par8 <- '104' par7 <- '97' par6 <- '0' par5 <- 'Y' par4 <- '8' par3 <- '1.34' par2 <- '100.18' par1 <- '18' library(MASS) library(msm) par1 <- sub(',','.',par1) par2 <- sub(',','.',par2) par3 <- sub(',','.',par3) par4 <- sub(',','.',par4) par1 <- as.numeric(par1) if (par1 > 10000) par1=10000 #impose restriction on number of random values par2 <- as.numeric(par2) par3 <- as.numeric(par3) par4 <- as.numeric(par4) if (par6 == '0') par6 = 'Sturges' else { par6 <- as.numeric(par6) if (par6 > 50) par6 = 50 #impose restriction on the number of bins } if (par7 == '') par7 <- -Inf else par7 <- as.numeric(par7) if (par8 == '') par8 <- Inf else par8 <- as.numeric(par8) x <- rtnorm(par1,par2,par3,par7,par8) x <- as.ts(x) #otherwise the fitdistr function does not work properly if ((par7 == -Inf) & (par8 == Inf)) (r <- fitdistr(x,'normal')) bitmap(file='test1.png') myhist<-hist(x,col=par4,breaks=par6,main=main,ylab=ylab,xlab=xlab,freq=F) if ((par7 == -Inf) & (par8 == Inf)) { curve(1/(r$estimate[2]*sqrt(2*pi))*exp(-1/2*((x-r$estimate[1])/r$estimate[2])^2),min(x),max(x),add=T) } dev.off() load(file='createtable') if (par5 == 'Y') { a<-table.start() a<-table.row.start(a) a<-table.element(a,'Index',1,TRUE) a<-table.element(a,'Value',1,TRUE) a<-table.row.end(a) for (i in 1:par1) { a<-table.row.start(a) a<-table.element(a,i,header=TRUE) a<-table.element(a,x[i]) a<-table.row.end(a) } a<-table.end(a) table.save(a,file='mytable1.tab') } if ((par7 == -Inf) & (par8 == Inf)) { a<-table.start() a<-table.row.start(a) a<-table.element(a,'Parameter',1,TRUE) a<-table.element(a,'Value',1,TRUE) a<-table.element(a,'Standard Deviation',1,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'# simulated values',header=TRUE) a<-table.element(a,par1) a<-table.element(a,'-') a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'true mean',header=TRUE) a<-table.element(a,par2) a<-table.element(a,'-') a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'true standard deviation',header=TRUE) a<-table.element(a,par3) a<-table.element(a,'-') a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'mean',header=TRUE) a<-table.element(a,r$estimate[1]) a<-table.element(a,r$sd[1]) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'standard deviation',header=TRUE) a<-table.element(a,r$estimate[2]) a<-table.element(a,r$sd[2]) a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable.tab') } a<-table.start() a<-table.row.start(a) a<-table.element(a,'Frequency Table (Histogram)',6,TRUE) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,'Bins',header=TRUE) a<-table.element(a,'Midpoint',header=TRUE) a<-table.element(a,'Abs. Frequency',header=TRUE) a<-table.element(a,'Rel. Frequency',header=TRUE) a<-table.element(a,'Cumul. Rel. Freq.',header=TRUE) a<-table.element(a,'Density',header=TRUE) a<-table.row.end(a) crf <- 0 mynumrows <- (length(myhist$breaks)-1) for (i in 1:mynumrows) { a<-table.row.start(a) dum <- paste('[',myhist$breaks[i],sep='') dum <- paste(dum,myhist$breaks[i+1],sep=',') if (i==mynumrows) dum <- paste(dum,']',sep='') else dum <- paste(dum,'[',sep='') a<-table.element(a,dum,header=TRUE) a<-table.element(a,myhist$mids[i]) a<-table.element(a,myhist$counts[i]) rf <- myhist$counts[i]/par1 crf <- crf + rf a<-table.element(a,round(rf,6)) a<-table.element(a,round(crf,6)) a<-table.element(a,round(myhist$density[i],6)) a<-table.row.end(a) } a<-table.end(a) table.save(a,file='mytable3.tab')
|