Linearity assumption for Pearson correlation 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.
 A: 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.
A: 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.

