Note that there are some explanatory texts on larger screens.

plurals
  1. POR: running standard deviations
    primarykey
    data
    text
    <p>I need to compute the "running" standard deviations of a vector of means, computing them as if the sample size is increasing. In other words, I need to compute the sd of mean_y[1], of mean_y[1] and mean_y[2], of mean_y[1], mean_y[2], mean_y[3] and so on,</p> <p>where:</p> <pre><code>y &lt;- rnorm(10000, mean=5, sd=2) i &lt;- seq(1 : length(y)) mean_y &lt;- cumsum(y)/i </code></pre> <p>Trying to apply the same criterion (hence, not explicitly using a loop), I produced the following code for the standard deviations of the vector of running means:</p> <pre><code>se &lt;- sqrt(1/i^2*cumsum(y^2) - 1/i*mean_y^2) </code></pre> <p>This beacuse, var(mean(x)) = 1/n*var(x). To me, the code seems ok. But when I plot the runnning means with their confidence intervals against i (the increasing sample size), the 95% bands perfectly coincide with the means!</p> <p>The code is:</p> <pre><code>error &lt;- qnorm(0.975)*se/sqrt(i) lower &lt;- mean_y - error upper &lt;- mean_y + error # plotting means and ci's against sample size (= up to 10000) plot(x=i, y=mean_y, xlab="Number of iterations (sample size)", ylab="E[y] estimates and 95% CI's", cex=0.4, ylim=c(4.6, 5.4)) lines(lower, col="gold") lines(upper, col="gold") </code></pre> <p>The rationale is to produce a graph showing the convergence of the estimator "mean_y" as the sample size keeps increasing.</p> <p>Can anyone help me? Probably there is some kind of basic error, either in the <code>se</code> formula or in <code>lower</code> and <code>upper</code>. Thanks!! Stefano </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload