[R] variance does not equal serial covariance of lag zero?

Liviu Andronic landronimirc at gmail.com
Tue Jun 2 15:23:46 CEST 2009


Dear all,
Does this make any sense:
var() = cov() != acf(lag.max=0, type="covariance")?

I have daily data of IBM for May 2005, and I'm using the logarithmic return:
> ibm200505$LRAdj.Close
 [1]         NA  0.0203152  0.0005508 -0.0148397 -0.0025182  0.0092025
-0.0013889
 [8]  0.0098196 -0.0103757 -0.0274917  0.0005716 -0.0159842 -0.0074306
 0.0091710
[15]  0.0002898  0.0226306  0.0036754  0.0005643  0.0206567 -0.0079052
 0.0005568
> with(ibm200505, {var(RAdj.Close, na.rm=TRUE)})
[1] 0.0001627
> with(ibm200505, {cov(RAdj.Close, RAdj.Close, use="pairwise.complete.obs")})
[1] 0.0001627
> with(ibm200505, {acf(RAdj.Close, lag.max=0, type="covariance", na.action=na.pass, plot=F)})$acf[1]
[1] 0.0001546

For the correlation, the function yields expected results:
> with(ibm200505, {cor(RAdj.Close, RAdj.Close, use="pairwise.complete.obs")})
[1] 1
> with(ibm200505, {acf(RAdj.Close, lag.max=0, type="correlation", na.action=na.pass, plot=F)})$acf[1]
[1] 1

Is this a bug, or am I doing anything stupid?
Thank you
Liviu




-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail




More information about the R-help mailing list