July 28, 2015

Constructing the dara

This example illustrates influence of linear dependency in data on correlation coefficients. Lets construct two well correlated vectors with random noise:

b <- 1:100+10*rnorm(100)
a <- 1:100+10*rnorm(100)
summary(a)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -10.19   25.86   48.44   49.67   70.71  110.80
summary(b)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  -12.36   25.23   51.47   51.05   77.44  123.00

Plotting daat as scatterplot

Calculating correlation coefficient

cor(a,b)
## [1] 0.900432

Transforming data with linear function y = a*x + b

aa <- 0.2*a + 3
bb <- 20*b - 30

Plotting both original and transformed data

Calculating Pearson's correaltion coefficients for both data set

cor(aa,bb)
## [1] 0.900432
cor(a,b)
## [1] 0.900432