Wednesday, March 5, 2014

Simulated correlated data points with specific R-squared value, R



set.seed(2014)
N=500
x = rnorm(N)
error = rnorm(N)
Rsquared= 0
rho = sqrt(Rsquared)
y= rho*x + sqrt(1-rho^2)*error
summary(lm(y ~ x ))
model = lm(y ~ x )
plot( y ~ x, col='blue')
abline( model, lwd=3 )
title( paste("R2 = ", Rsquared))

No comments:

Post a Comment