[R] Simple simulation in R
Liaw, Andy
andy_liaw at merck.com
Tue Aug 26 18:47:39 CEST 2003
I believe simple math stat calculations should be sufficient for this.
For simplicity, assume X1 through X4 are iid with mean m and variance v.
Note that
var1 = (3*var2 + x4) / 4
so
cov(var1, var2) = cov(var2, (3*var2 + x4)/4)
and since var2 and x4 are independent, this covariance can be simplified.
Carry this through and substituting in m and v in the appropriate places
should give you the covariance (and hence correlation) in terms of m and
v.
Andy
> -----Original Message-----
> From: Peter Flom [mailto:flom at ndri.org]
> Sent: Tuesday, August 26, 2003 10:31 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Simple simulation in R
>
>
> Hello all
>
> I have a feeling this is very simple......but I am not sure
> how to do it
>
> My boss has two variables, one is an average of 4 numbers,
> the other is an average of 3 of those numbers i.e
>
> var1 = (X1 + X2 + X3 + X4)/4
> var2 = (X1 + X2 + X3)/3
>
> all of the X variables are supposed to be measuring similar constructs
>
> not surprisingly, these are highly correlated (r = .98), the
> question is how much of this correlation is due to the fact
> that the X's are related, and how much to the fact that the
> two VARs are similarly constructed
>
> What I want to do is simulate this with normally distributed
> data for the X's. That is, generate (say) 1000 sets of X1
> through X4, use those to caluculate 1000 var1 and var2, and
> then 1000 correlations between var1 and var2, and then plot
> those results.
>
> Any help appreciated
>
> Peter Flom
>
> Peter L. Flom, PhD
> Assistant Director, Statistics and Data Analysis Core
> Center for Drug Use and HIV Research
> National Development and Research Institutes
> 71 W. 23rd St
> www.peterflom.com
> New York, NY 10010
> (212) 845-4485 (voice)
> (917) 438-0894 (fax)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments,...{{dropped}}
More information about the R-help
mailing list