I generated an error in r
u1<-rnorm(n, mean=0, sd=1);
And I want to generate a random normal variable x ~ i.i.d.N(n, 0, 4) but this is not correlated with u1 i.e. corr(x, u1)
is zero.
How can I, define this in R?
Generation of two uncorrelated variables:
n <- 1e3
u1 <- rnorm(n, mean = 0, sd = 1)
x <- rnorm(n, mean = 0, sd = 4)
Please note that estimated correlation coefficient will not be exactly 0, but it will be close to 0.
> cor(x, u1)
[1] -0.01885482
Any two random Gaussian variables will have a theoretical correlation of 0, as long as n is large enough.
set.seed(1)
n=1000000
u1<-rnorm(n, mean=0, sd=1)
x<-rnorm(n, mean=0, sd=4)
cor(x, u1)
Output:
0.0007637239