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 = '500' > 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/1ep981228163815.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 1 0 1 2 3 4 3 4 3 2 3 2 3 [19] 2 1 2 1 0 -1 0 -1 0 1 2 3 2 1 2 1 0 -1 [37] -2 -1 0 -1 0 -1 0 -1 -2 -3 -2 -1 0 -1 -2 -1 -2 -3 [55] -2 -3 -4 -5 -4 -5 -4 -5 -6 -7 -6 -5 -4 -5 -4 -3 -2 -3 [73] -2 -3 -4 -3 -4 -5 -4 -5 -6 -5 -4 -3 -2 -3 -4 -5 -6 -5 [91] -6 -7 -6 -5 -4 -5 -4 -5 -6 -7 -6 -7 -8 -9 -10 -11 -12 -13 [109] -14 -13 -12 -13 -12 -11 -10 -11 -10 -11 -12 -11 -12 -11 -12 -13 -12 -13 [127] -12 -13 -12 -11 -10 -9 -10 -9 -10 -11 -10 -9 -10 -9 -10 -9 -8 -7 [145] -8 -7 -6 -7 -8 -7 -6 -7 -8 -7 -8 -7 -8 -7 -8 -9 -10 -11 [163] -10 -9 -8 -7 -8 -9 -8 -7 -8 -9 -8 -9 -8 -9 -10 -9 -10 -11 [181] -10 -9 -10 -9 -10 -11 -10 -11 -12 -13 -14 -15 -14 -15 -14 -15 -14 -13 [199] -14 -13 -14 -15 -16 -17 -16 -17 -16 -15 -14 -15 -16 -15 -14 -13 -14 -15 [217] -14 -13 -12 -13 -12 -11 -12 -13 -14 -15 -14 -15 -16 -17 -18 -19 -18 -17 [235] -18 -17 -16 -17 -18 -19 -20 -19 -20 -19 -20 -21 -22 -23 -22 -23 -24 -23 [253] -22 -23 -24 -23 -24 -25 -24 -25 -24 -25 -24 -23 -22 -21 -22 -23 -24 -23 [271] -24 -25 -24 -25 -24 -23 -22 -21 -22 -23 -24 -25 -24 -23 -22 -23 -22 -23 [289] -22 -23 -22 -21 -22 -21 -22 -23 -22 -23 -22 -23 -22 -23 -22 -21 -22 -23 [307] -22 -21 -22 -21 -22 -23 -24 -23 -22 -21 -20 -19 -20 -21 -20 -21 -20 -19 [325] -20 -21 -20 -21 -20 -21 -22 -23 -22 -21 -20 -21 -22 -23 -22 -23 -22 -23 [343] -24 -25 -26 -27 -28 -29 -30 -31 -32 -31 -32 -31 -32 -33 -34 -35 -36 -37 [361] -36 -35 -36 -37 -38 -37 -38 -37 -36 -35 -34 -33 -32 -33 -34 -35 -34 -35 [379] -36 -35 -34 -33 -32 -33 -32 -31 -32 -31 -32 -33 -34 -35 -36 -35 -34 -33 [397] -34 -33 -34 -35 -34 -33 -32 -31 -30 -29 -30 -29 -28 -27 -26 -25 -24 -23 [415] -22 -21 -20 -21 -20 -21 -20 -21 -22 -21 -20 -21 -22 -21 -22 -23 -22 -21 [433] -20 -21 -20 -19 -20 -19 -18 -19 -20 -21 -22 -23 -22 -21 -22 -21 -20 -19 [451] -20 -21 -22 -23 -24 -25 -24 -25 -26 -27 -26 -25 -24 -25 -26 -25 -24 -25 [469] -24 -23 -24 -25 -26 -25 -26 -25 -26 -27 -28 -27 -26 -25 -24 -25 -26 -25 [487] -24 -23 -24 -25 -26 -27 -26 -27 -28 -29 -28 -29 -28 -27 > par1 <- as.numeric(12) > x <- as.array(b) > n <- length(x) > sx <- sort(x) > > #Note: the /var/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Variance Reduction Matrix',6,TRUE) > a<-table.row.end(a) > for (bigd in 0:2) { + for (smalld in 0:3) { + mylabel <- 'V(Y[t],d=' + mylabel <- paste(mylabel,as.character(smalld),sep='') + mylabel <- paste(mylabel,',D=',sep='') + mylabel <- paste(mylabel,as.character(bigd),sep='') + mylabel <- paste(mylabel,')',sep='') + a<-table.row.start(a) + a<-table.element(a,mylabel,header=TRUE) + myx <- x + if (smalld > 0) myx <- diff(x,lag=1,differences=smalld) + if (bigd > 0) myx <- diff(myx,lag=par1,differences=bigd) + a<-table.element(a,var(myx)) + a<-table.element(a,'Range',header=TRUE) + a<-table.element(a,max(myx)-min(myx)) + a<-table.element(a,'Trim Var.',header=TRUE) + smyx <- sort(myx) + sn <- length(smyx) + a<-table.element(a,var(smyx[smyx>quantile(smyx,0.05) & smyx a<-table.end(a) > table.save(a,file="/var/www/html/freestat/rcomp/tmp/2fvf41228163815.tab") > > system("convert tmp/1ep981228163815.ps tmp/1ep981228163815.png") > > > proc.time() user system elapsed 0.661 0.297 0.744