[R] Bug : Autocorrelation in sample drawn from stats::rnorm (hmh)

Annaert Jan j@n@@nn@ert @ending from u@ntwerpen@be
Fri Oct 5 10:28:05 CEST 2018



> Nope.

> This IS a bug:
> The negative auto-correlation mostly disappear when I randomize small samples using the R function 'sample'.

> Please check thoroughly the code of the 1st mail I sent, there should be no difference between the two R functions I wrote to illustrate the bug.
> The two functions that should produce the same output if there would be no bug are 'DistributionAutocorrelation_Unexpected' and  'DistributionAutocorrelation_Expected'.
>Please take the time to compare there output!!
>The finite-sample bias in the sample autocorrelation coefficient you mention should affect them in the same manner. This bias is not the only phenomenon at work, there is ALSO as BUG !

I disagree. Take a look at your code:
Cor[repetition] = cor(sample(X[-1]),sample(X[-length(X)]))

By sampling the two series in the correlation function, you discard any time series structure; you are no longer estimating a serial correlation coefficient, but just a correlation (which in this case is unbiased).
Try out the following:

Xs <- sample(X)
Cor[repetition] = cor(Xs[-1]),(Xs[-length(Xs)]))

The bias should reappear.

Jan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: cclhgmpcmhoinmca.png
Type: image/png
Size: 76147 bytes
Desc: cclhgmpcmhoinmca.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181005/1c25e7f4/attachment.png>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: adeokhkijhbomjkp.png
Type: image/png
Size: 75264 bytes
Desc: adeokhkijhbomjkp.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181005/1c25e7f4/attachment-0001.png>


More information about the R-help mailing list