From j@n@@nn@ert @ending from u@ntwerpen@be  Fri Oct  5 10:28:05 2018
From: j@n@@nn@ert @ending from u@ntwerpen@be (Annaert Jan)
Date: Fri, 5 Oct 2018 08:28:05 +0000
Subject: [Rd] 
 [R] Bug : Autocorrelation in sample drawn from stats::rnorm (hmh)
In-Reply-To: <aa15aaef-d56c-e44a-e618-61c69e9b36a7@gmx.fr>
References: <1607055752.4873464.1538697126419.ref@mail.yahoo.com>
 <1607055752.4873464.1538697126419@mail.yahoo.com>
 <f5169c3a-cd6b-1ba4-9701-4119f4123db3@gmx.fr>
 <61E0376C-8813-4678-B4AF-12D57017624C@ua.ac.be>
 <aa15aaef-d56c-e44a-e618-61c69e9b36a7@gmx.fr>
Message-ID: <ABD057D3-5E10-44B4-B4DD-0FB04D475B52@ua.ac.be>



> 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-devel/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-devel/attachments/20181005/1c25e7f4/attachment-0001.png>


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