The answers differ by a factor of 19/20, ie, (n-1)/n, so it is presumably the choice of denominator for the variance that differs.

        -thomas

On Tue, 2 Jun 2009, Liviu Andronic wrote:

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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to