# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- gen_auto_correlated_data = function(){ y1 = rnorm(51) y = y1[-1] + y1[-51] # y1[-1] drops the first point; y1[-51] drops the last point i.e. y[n] = y1[n-1] + y1[n] } n_sims = 25 av = numeric(n_sims) v = numeric(n_sims) for( n in 1:n_sims ){ X = gen_auto_correlated_data() av[n] = mean( X ) v[n] = var( X ) } print( var(av) ) print( mean(v) ) print( var(v) )