Printversion of this page
PDF-Version of this page

 

#Correlation, significance and Monte carlo experiments

 

 

#Correlation = normed regression

 

a<-1:1000

noise<-rnorm(1000)*500

b<-a + noise

 

 

 

plot(a,b)

cor(a,b) #correlate a,b

cor.test(a,b) #correlation + significance test

 

 

 

N<-30

 

a<-rnorm(N)

b<-rnorm(N)

 

cor(a,b)

 

 

#Now the same as a Monte Carlo experiment (some hundred times)

 

rsave<-vector() #vector for saving

for (i in 1:5000)

{

a<-rnorm(N)

a<-1:N

b<-a+2*rnorm(N)

rsave[i]<-cor(a,b)

 

}

 

hist(rsave)

 

#abs is used to get the p-values for a two-sided test

quantile(abs(rsave),probs=0.95)


 
Printversion of this page
PDF-Version of this page