[R] are these the same?

Ben Bolker bolker at ufl.edu
Tue Sep 16 19:05:03 CEST 2008


Kitty Lee <lee.kitty <at> yahoo.com> writes:

> 
> Dear members,
> 
> I was trying to simulate W which is iid and depends on X and Y. 
> 
> Here are 2 methods:
> 
> Method 1:
> x<-rnorm(100)
> y<-rnorm(100)
> w<-rnorm(100, 2x+y,1)
> 
> Method 2:
> x<-rnorm(100)
> 
> y<-rnorm(100)
> 
> w<-2x+y+rnorm(100,0,1)
> 
> Are these methods comparable? 
> 
> Since x and y are vectors, the term 2x+y would return a vector. It seems that,
given Method 1, each element of W
> would come from a different population with means depending on the value of x
and y. Is that true? Or is
> Method 1 equally acceptable as Method 2 in creating W?
> 
> I'd really appreciate clues to this puzzle! Thanks!

  They're identical.  Here's an experimental "proof":

> set.seed(1001); w1 <- rnorm(100,2*x+y)
> set.seed(1001); w2 <- 2*x+y+rnorm(100)
> var(cbind(x,y,w1))
            x          y       w1
x  0.91376508 0.06466817 1.796888
y  0.06466817 1.09054157 1.159634
w1 1.79688802 1.15963375 5.812402
> var(cbind(x,y,w2))
            x          y       w2
x  0.91376508 0.06466817 1.796888
y  0.06466817 1.09054157 1.159634
w2 1.79688802 1.15963375 5.812402

  Ben Bolker



More information about the R-help mailing list