R version 2.8.0 (2008-10-20) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > par2 = '0.5' > par1 = '1000' > n <- as.numeric(par1) > p <- as.numeric(par2) > heads=rbinom(n-1,1,p) > a=2*(heads)-1 > b=diffinv(a,xi=0) > c=1:n > pheads=(diffinv(heads,xi=.5))/c > postscript(file="/var/www/html/freestat/rcomp/tmp/1top41228761676.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op=par(mfrow=c(2,1)) > plot(c,b,type='n',main='Law of Averages',xlab='Toss Number',ylab='Excess of Heads',lwd=2,cex.lab=1.5,cex.main=2) > lines(c,b,col='red') > lines(c,rep(0,n),col='black') > plot(c,pheads,type='n',xlab='Toss Number',ylab='Proportion of Heads',lwd=2,cex.lab=1.5) > lines(c,pheads,col='blue') > lines(c,rep(.5,n),col='black') > par(op) > dev.off() null device 1 > b [1] 0 1 0 1 2 3 4 5 6 7 8 9 8 7 6 7 6 7 [19] 8 7 6 5 4 5 6 5 4 3 2 1 2 1 0 -1 0 1 [37] 2 3 4 3 4 3 4 5 4 5 4 3 2 3 4 3 2 1 [55] 2 3 2 1 0 -1 -2 -1 -2 -1 0 1 2 1 2 1 2 3 [73] 2 3 4 5 4 3 4 5 6 7 6 5 6 7 6 7 8 7 [91] 6 7 8 9 10 9 8 7 8 9 8 7 6 7 8 7 8 9 [109] 8 7 8 9 8 7 6 7 8 7 8 7 6 7 8 7 6 7 [127] 6 7 6 7 6 5 4 5 4 3 2 1 0 -1 0 1 0 1 [145] 2 3 4 5 6 5 6 5 4 5 4 3 2 1 2 1 2 3 [163] 4 5 4 3 2 3 4 5 6 7 6 7 8 7 8 7 8 9 [181] 10 11 10 11 10 11 12 13 12 11 12 13 14 13 12 13 12 11 [199] 10 11 12 13 14 15 14 13 12 13 12 13 14 13 14 13 14 13 [217] 14 15 14 15 16 17 18 19 18 19 18 19 18 19 20 19 18 19 [235] 18 17 18 17 16 15 16 17 18 17 16 17 18 19 20 21 20 21 [253] 22 21 22 23 22 21 22 23 24 25 24 23 22 23 24 23 22 23 [271] 22 21 22 23 24 23 24 25 24 25 26 27 28 27 26 25 24 23 [289] 24 23 22 21 20 21 20 21 22 21 20 19 18 19 18 19 18 19 [307] 20 21 22 21 20 21 20 21 22 21 20 19 20 19 18 19 18 17 [325] 16 17 16 15 16 17 18 19 20 21 22 21 20 19 20 21 22 21 [343] 20 19 20 19 18 19 18 17 16 15 14 13 12 11 12 11 12 11 [361] 12 11 12 13 14 13 12 11 12 13 14 13 12 11 10 11 10 9 [379] 10 11 12 13 14 13 12 11 10 9 8 9 10 11 10 11 10 9 [397] 8 7 8 7 6 7 6 5 4 5 4 3 2 1 2 1 0 1 [415] 0 1 2 1 0 -1 0 -1 0 -1 0 1 0 -1 0 1 2 1 [433] 0 1 0 1 2 3 4 5 4 3 2 1 2 3 4 3 2 3 [451] 4 3 2 3 2 1 2 3 2 1 0 1 2 3 2 3 4 5 [469] 6 5 4 5 6 5 6 5 6 5 6 7 6 5 4 5 4 3 [487] 2 1 2 1 0 1 0 -1 -2 -3 -4 -3 -4 -5 -4 -5 -6 -5 [505] -4 -5 -4 -3 -2 -3 -4 -5 -6 -5 -6 -7 -6 -7 -6 -5 -4 -5 [523] -6 -5 -6 -7 -6 -5 -6 -5 -4 -3 -2 -3 -2 -1 0 -1 -2 -1 [541] 0 -1 0 -1 0 -1 0 -1 0 1 0 -1 0 -1 0 -1 -2 -1 [559] -2 -1 -2 -3 -2 -3 -2 -3 -2 -1 -2 -1 -2 -3 -4 -5 -6 -5 [577] -6 -7 -8 -7 -6 -7 -6 -5 -4 -5 -6 -5 -4 -3 -2 -3 -2 -1 [595] 0 1 0 1 2 1 2 3 2 3 2 1 0 -1 0 1 2 3 [613] 4 5 4 3 2 1 0 -1 -2 -3 -4 -3 -4 -3 -4 -5 -4 -3 [631] -4 -5 -6 -7 -8 -9 -8 -9 -10 -9 -8 -9 -8 -9 -10 -9 -8 -7 [649] -6 -5 -6 -7 -8 -9 -10 -9 -8 -7 -6 -7 -8 -9 -8 -9 -8 -9 [667] -10 -11 -12 -13 -12 -11 -12 -11 -10 -11 -12 -11 -12 -13 -14 -13 -14 -13 [685] -14 -15 -16 -17 -18 -19 -20 -21 -20 -21 -22 -23 -24 -23 -22 -21 -22 -23 [703] -24 -25 -26 -27 -26 -27 -26 -27 -28 -27 -26 -27 -26 -25 -24 -23 -24 -23 [721] -24 -25 -26 -27 -26 -25 -24 -23 -24 -25 -24 -23 -24 -23 -24 -25 -26 -25 [739] -24 -25 -26 -25 -24 -23 -24 -25 -26 -25 -24 -23 -22 -21 -22 -21 -20 -19 [757] -20 -19 -18 -19 -18 -17 -18 -19 -20 -21 -22 -23 -22 -21 -22 -21 -22 -21 [775] -22 -23 -24 -25 -26 -27 -26 -27 -26 -27 -26 -25 -26 -27 -26 -25 -26 -25 [793] -26 -27 -28 -29 -30 -31 -32 -33 -32 -33 -34 -35 -36 -35 -36 -37 -36 -35 [811] -34 -33 -34 -33 -34 -35 -36 -37 -38 -37 -36 -35 -36 -35 -34 -33 -34 -35 [829] -34 -33 -32 -33 -32 -33 -34 -33 -34 -35 -34 -35 -36 -37 -36 -37 -36 -37 [847] -38 -39 -40 -39 -38 -39 -40 -41 -40 -41 -40 -39 -38 -39 -38 -39 -38 -39 [865] -40 -41 -40 -41 -42 -41 -42 -43 -42 -43 -44 -45 -46 -45 -44 -43 -42 -41 [883] -40 -39 -40 -41 -40 -39 -40 -41 -42 -41 -42 -41 -42 -41 -42 -43 -42 -41 [901] -40 -41 -40 -41 -42 -41 -42 -43 -42 -41 -40 -41 -42 -43 -42 -43 -42 -43 [919] -44 -43 -44 -45 -46 -45 -44 -43 -42 -41 -40 -41 -42 -43 -42 -41 -40 -39 [937] -38 -39 -38 -37 -38 -39 -40 -39 -40 -41 -40 -41 -42 -41 -40 -39 -38 -37 [955] -38 -39 -38 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -45 -44 -43 -44 -43 [973] -42 -43 -42 -43 -44 -45 -44 -45 -44 -45 -46 -47 -46 -47 -48 -47 -48 -49 [991] -48 -49 -48 -49 -48 -47 -46 -45 -44 -45 > postscript(file="/var/www/html/freestat/rcomp/tmp/28xn11228761676.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > racf <- acf(b,n/10,main='Autocorrelation',xlab='lags',ylab='ACF') > dev.off() null device 1 > racf Autocorrelations of series 'b', by lag 0 1 2 3 4 5 6 7 8 9 10 11 12 1.000 0.997 0.994 0.991 0.988 0.985 0.981 0.978 0.974 0.971 0.968 0.964 0.961 13 14 15 16 17 18 19 20 21 22 23 24 25 0.957 0.954 0.950 0.947 0.944 0.941 0.938 0.935 0.931 0.928 0.925 0.922 0.919 26 27 28 29 30 31 32 33 34 35 36 37 38 0.917 0.914 0.911 0.908 0.905 0.902 0.899 0.896 0.893 0.890 0.886 0.883 0.880 39 40 41 42 43 44 45 46 47 48 49 50 51 0.878 0.875 0.873 0.870 0.868 0.865 0.863 0.861 0.858 0.856 0.854 0.851 0.849 52 53 54 55 56 57 58 59 60 61 62 63 64 0.846 0.844 0.842 0.839 0.837 0.834 0.832 0.829 0.827 0.824 0.822 0.819 0.817 65 66 67 68 69 70 71 72 73 74 75 76 77 0.814 0.811 0.809 0.806 0.803 0.800 0.797 0.794 0.791 0.788 0.785 0.781 0.777 78 79 80 81 82 83 84 85 86 87 88 89 90 0.774 0.770 0.767 0.763 0.759 0.756 0.752 0.749 0.745 0.742 0.738 0.735 0.732 91 92 93 94 95 96 97 98 99 100 0.728 0.725 0.721 0.718 0.714 0.711 0.708 0.705 0.701 0.698 > > system("convert tmp/1top41228761676.ps tmp/1top41228761676.png") > system("convert tmp/28xn11228761676.ps tmp/28xn11228761676.png") > > > proc.time() user system elapsed 0.991 0.656 1.410