[R] How to estate the correlation between two autocorrelated variables

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Wed Jan 9 23:16:10 CET 2013


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Zhiqiu Hu
> Sent: Wednesday, January 09, 2013 1:45 PM
> To: r-help at r-project.org
> Subject: [R] How to estate the correlation between two autocorrelated
> variables
> 
> Dear R users,
> 
> In my data, there are two variables t1 and t2. For each observation of
> t1
> and t2, two location indicators (x, y) were provided.
> 
> The data format is
> #    x   y   t1   t2
> 
> Since the both t1 and t2 are depended on x and y, t1 and t2 are
> autocorrelated variables. My question is how to calculate the
> correlation
> between t1 and t2 by taking into account the structure of residual
> variance
> caused by x and y. Seemly, the gls function in nlme/R package might can
> be
> used for the purpose. However, I failed to figure out how to use the
> function for my data. I appreciate your kind help providing an example
> code
> for the above data format. Please also let me know if there is any
> other
> more suitable R package for the analysis.
> 
> Best regards,
> 
> Zhiqiu
> 

If you want the partial correlation between t1 and t2 given x and y, then look at the pcor() function in the ppcor package.

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204



More information about the R-help mailing list