1 ## PsN R script for plotting results of bootstrap
8 ## autogenerated code begins
9 ## we can set other things, like colours, line types, layout, etc here if we wish
11 ## This script assumes "ofv" is the last column before we get into the parameter estimates
13 min.failed <- FALSE # do we want to omit minimization failed runs?
14 cov.failed <- FALSE # do we want to omit covariance failed runs?
15 cov.warnings <- TRUE # do we want to omit covariance failed runs?
16 boundary <- TRUE # do we want to omit boundary runs?
17 showoriginal <- TRUE # show line for original estimate
18 showmean <- TRUE # show line for mean
19 showmedian <- FALSE # show line for median
20 show95CI <- TRUE # show line for 95 % confidence interval (percentile)
21 showquart <- FALSE # show line for quartiles
23 ## autogenerated code ends
26 bootstrap.data <- read.csv("raw_results1.csv", header=T)
28 ## replace underscores
29 for (i in 1:length(names(bootstrap.data))) {
30 names(bootstrap.data)[i] <- gsub("\_", "\.", names(bootstrap.data)[i])
33 ## find ofv column index
37 for (i in names(bootstrap.data)) {
46 ## get number of parameters
47 n <- length(colnames(bootstrap.data)) - index
48 nparams <- length(colnames(bootstrap.data))
52 ## separate out original model fit
53 p1 <- subset(bootstrap.data, bootstrap.data$model != 0)
54 o1 <- subset(bootstrap.data, bootstrap.data$model == 0)
56 #names(p1)[2] <- "minimization.successful"
57 #names(p1)[3] <- "covariance.step.successful"
58 #names(p1)[4] <- "covariance.step.warnings"
59 #names(p1)[5] <- "estimate.near.boundary"
63 p1 <- subset(p1, minimization.successful == 1)
66 p1 <- subset(p1, covariance.step.successful == 1)
69 p1 <- subset(p1, covariance.step.warnings == 0)
72 p1 <- subset(p1, estimate.near.boundary == 0)
75 ## stats and plots for each- single
77 for (i in index:nparams) {
78 if (mode(p1[[i]]) == "numeric" &&
79 sum(p1[[i]],na.rm=T)) {
80 sp <- summary(p1[[i]])
81 # IQR <- diff(summary(p1[[i]])[c(5,2)])
82 dp <- density(p1[[i]], na.rm=T)
83 parmlabel <- names(p1)[i]
85 postscript(file=paste("bootstrap.", parmlabel, ".ps", sep=""), paper="a4",
86 title=paste("Bootstrap results - ", parmlabel, sep=""),
89 qu <- quantile(p1[[i]], c(0.025, 0.975), na.rm=T)
91 legend=paste("n = ", nrow(p1), sep="")
93 legend=paste(legend, "; Mean = ", sp[4], sep="")
96 legend=paste(legend, "; Median = ", sp[3], sep="")
99 legend=paste(legend, "; Orig = ", o1[[i]], sep="")
103 main = paste("Bootstrap results - ", parmlabel, sep=""),
105 # ylim = c(0, max(dp$y)),
107 xlim = c(min(dp$x), max(dp$x)),
109 # xlim = c(min(p1[[i]]) - min(p1[[i]])*0.15,max(p1[[i]]) + max(p1[[i]])*0.15),
112 # sub=paste(paste(paste("n = ", nrow(p1), sep=""), "; Median = ", sp[4], sep=""), "; Orig = ", o1[[i]], sep="") )
114 #h <- hist(p1[[i]], prob=T, plot=F)
116 lines(dp, lwd=2, lty=3, col="red")
119 abline(v=sp[2], lwd= 1, lty=3, col="red") ## 1st quartile
120 abline(v=sp[5], lwd= 1, lty=3, col="red") ## 3rd quartile
123 abline(v=sp[4], lty=2, lwd=1, col="red") ## mean
126 abline(v=sp[3], lty=1, lwd=2, col="red") ## median
129 abline(v=o1[[i]], lty=2, lwd=1, col="red") ## original
132 abline(v=qu[1], lty=4, lwd=1, col="red") ## 2.5% CL
133 abline(v=qu[2], lty=4, lwd=1, col="red") ## 97.5% CL
134 text(qu[1], max(dp$y), labels=signif(qu[1], digits = 3), cex = .8, adj = c(0,0), pos='2')
135 text(qu[2], max(dp$y), labels=signif(qu[2], digits = 3), cex = .8, adj = c(0,0), pos='4')
137 # abline(v=sp[4], lty=1, lwd=2, col="red") ## median
138 # abline(v=o1[[i]], lty=2, lwd=1, col="red") ## original
139 # abline(v=qu[1], lty=4, lwd=1, col="red") ## 2.5% CL
140 # abline(v=qu[2], lty=4, lwd=1, col="red") ## 97.5% CL
142 # text(qu[1], max(dp$y), labels=signif(qu[1], digits = 3), cex = .8, adj = c(0,0), pos='2')
143 # text(qu[2], max(dp$y), labels=signif(qu[2], digits = 3), cex = .8, adj = c(0,0), pos='4')
144 #text(sp[4], max(h$density), labels=paste("Med: ", signif(sp[4], digits = 3), sep=""), adj = c(-1,0), cex = .8, pos='2')
148 ## stats and plots for each - 6 per sheet
153 for (i in index:nparams) {
154 if (mode(p1[[i]]) == "numeric" &&
155 sum(p1[[i]],na.rm=T)) {
156 sp <- summary(p1[[i]])
157 # IQR <- diff(summary(p1[[i]])[c(5,2)])
158 dp <- density(p1[[i]], na.rm=T)
159 parmlabel <- names(p1)[i]
163 postscript(file=paste("bootstrap.page", bspage, ".ps", sep=""), paper="a4",
164 title="Bootstrap results",
170 qu <- quantile(p1[[i]], c(0.025, 0.975), na.rm=T)
172 legend=paste("n = ", nrow(p1), sep="")
174 legend=paste(legend, "; Mean = ", sp[3], sep="")
177 legend=paste(legend, "; Median = ", sp[4], sep="")
180 legend=paste(legend, "; Orig = ", o1[[i]], sep="")
184 main = paste("Bootstrap results - ", parmlabel, sep=""),
186 # ylim = c(0, max(dp$y)),
188 xlim = c(min(dp$x), max(dp$x)),
190 # xlim = c(min(p1[[i]]) - min(p1[[i]])*0.15,max(p1[[i]]) + max(p1[[i]])*0.15),
193 #=paste(paste(paste("n = ", nrow(p1), sep=""), "; Median = ", sp[4], sep=""), "; Orig = ", o1[[i]], sep="") )
195 #h <- hist(p1[[i]], prob=T, plot=F)
197 lines(dp, lwd=2, lty=3, col="red")
200 abline(v=sp[2], lwd= 1, lty=3, col="red") ## 1st quartile
201 abline(v=sp[5], lwd= 1, lty=3, col="red") ## 3rd quartile
204 abline(v=sp[3], lty=2, lwd=1, col="red") ## mean
207 abline(v=sp[4], lty=1, lwd=2, col="red") ## median
210 abline(v=o1[[i]], lty=2, lwd=1, col="red") ## original
213 abline(v=qu[1], lty=4, lwd=1, col="red") ## 2.5% CL
214 abline(v=qu[2], lty=4, lwd=1, col="red") ## 97.5% CL
215 text(qu[1], max(dp$y), labels=signif(qu[1], digits = 3), cex = .8, adj = c(0,0), pos='2')
216 text(qu[2], max(dp$y), labels=signif(qu[2], digits = 3), cex = .8, adj = c(0,0), pos='4')
219 # abline(v=sp[4], lty=1, lwd=2, col="red") ## median
220 # abline(v=o1[[i]], lty=2, lwd=1, col="red") ## original
221 # abline(v=qu[1], lty=4, lwd=1, col="red") ## 2.5% CL
222 # abline(v=qu[2], lty=4, lwd=1, col="red") ## 97.5% CL
224 # text(qu[1], max(dp$y), labels=signif(qu[1], digits = 3), cex = .8, adj = c(0,0), pos='2')
225 # text(qu[2], max(dp$y), labels=signif(qu[2], digits = 3), cex = .8, adj = c(0,0), pos='4')
226 #text(sp[4], max(h$density), labels=paste("Med: ", signif(sp[4], digits = 3), sep=""), adj = c(-1,0), cex = .8, pos='2')