Conditional Correlation?

0

Given: I have columns something like

| Location  | Year | A | B   |
|-----------|------|---|-----|
| Delhi     | 1980 | 4 | 3.4 |
| Mumbai    | 1986 | 3 | 3.9 |
| Delhi     | 1990 | 5 | 4.4 |
| Bangalore | 1997 | 2 | 2.6 |
| Delhi     | 1998 | 4 | 3.8 |
| Delhi     | 1991 | 4 | 4.5 |
| Bangalore | 1987 | 4 | 3.8 |
| Mumbai    | 1998 | 5 | 4.8 |

And I want to perform correlation between column A and B under Delhi Location category.

I want to perform correlation with only Delhi as Location

| Location | A | B   |
|----------|---|-----|
| Delhi    | 4 | 3.4 |
| Delhi    | 5 | 4.4 |
| Delhi    | 4 | 3.8 |
| Delhi    | 4 | 4.5 |

I tried CORREL() function but this will give correlation A and B for all location. I just want specific Location to correlated.

Thank you for your time and consideration.

Maqsud Inamdar

Posted 2019-11-25T11:25:58.247

Reputation: 71

Answers

1

The solution is some basic array formula filtering. By making each correlation range dependent on whether A2:A9 is Delphi, you create a conditional correlation.

=CORREL(IF(A2:A9="Delhi", C2:C9), IF(A2:A9="Delhi", D2:D9))

This is an array style formula. As such, you need to uses Ctrl+Shift+Enter to finalize the formula; not just Enter. If you do this correctly, Excel will wrap the formula in maths braces; e.g. { and }.

Using this method the answer to your sample data is 0.481869424652427.

Jeeped

Posted 2019-11-25T11:25:58.247

Reputation: 2 435

I am getting #VALUE!. which says A value used in the formula is of the wrong data types. I am calculating this correlation in another sheet. Does it effect my calculation. Or there is something else. – Maqsud Inamdar – 2019-11-25T14:17:15.163

It shouldn't matter if the table is on another worksheet. It shouldn't matter if there are numbers in the Location column and if there was text in any of the number columns, you would get a #DIV/0! error. I'm a little dumbfounded as to what the problem is. – Jeeped – 2019-11-25T20:47:58.200

1Ctrl + Shift + Enter works. Thanks @Jeeped. – Maqsud Inamdar – 2019-11-26T05:55:57.273