It's known that values must have a linear relationship to count Pearson correlation between them.
I'm wondering if there are any formal tests (preferably) or at least graphical way to check for the data linearity? As R user i'd glad to see R code example as well.
- 439
2 Answers
Actually the Pearson correlation can be computed for any data, not just linear data. However its distribution theory relies on linearity (which you need if you want to test the null hypothesis $\rho=0$ or compute a confidence interval) and interpretation may be a bit more tricky if the relationship is not linear.
The best check for linearity is to do a scatterplot of the data, where you can see whether there are obvious issues with it. There are formal tests, but I'm not very keen on them for model assumption checking - they test linearity against specific alternatives, but a non-rejection doesn't mean that linearity is actually fulfilled. The idea that if you have a formal test, the result will tell you reliably whether you can or can't use this-or-that method is a myth.
- 23,655
A linear relationship has nothing to do with data linearity, it just means that when one variable increases or decreases, the other variable increases or decreases too.
For example,
> x <- 1:10
> y <- x^2
> cor(x,y)
[1] 0.9745586
Here $y$ is not linear, but is linearly correlated with $x$ because it increases when $x$ increases.
> x <- -10:10
> y <- x^2
> cor(x,y)
[1] 0
Here $y$ is not linearly correlated with $x$ because:
- if $x<0$, then $y$ decreases when $x$ increases;
- if $x>0$, then $y$ increases when $x$ increases.
- 5,951
linear relationship. I'm wondering, what is thedata linearity? So, the assumption forPearson correlationislinear relationshipordata linearityeventually? – Denis Aug 18 '20 at 13:35linearityconcept and how i may check my own data for that inR? I realized now that it's not related toPearson correlation, but i saw this term many times in the papers as important assumption for other statistic tests. – Denis Aug 19 '20 at 17:07R. Please check my post:https://stats.stackexchange.com/questions/424202/check-if-dependency-between-two-variables-is-linear – Denis Aug 23 '20 at 15:22