APPENDIX H

R CODE FOR CONFIDENCE INTERVALS AND ESTIMATES

Note: The functions rootcdf and cdfhat must also be included. These are in Appendix A and on the file adapt.r.

adaptest  <− function(dataset, complete, reduced, varname,
                      plower, initial, maxsteps, seed) {
testdata <− read.table(dataset)
cat(“Data Set”, “\n”, “\n”)
print(testdata)
attach(testdata)
yvector <− y
xa <− as.vector(as.matrix(subset(testdata,select=varname)))
set.seed(seed)
olsmodel <− lm(as.formula(complete))
olsse <− summary(olsmodel)$coefficients[varname,2]
dfc <− df.residual(olsmodel)
tcrit <− abs(qt(0.975,dfc))
k <− 17.4 6*tcrit*olsse
estimate <− initial estimatesum <− 0 cat(“\n”, “\n”, “\n”, “*****************************”, “\n”, “\n”) cat(“ Input:”, “\n”, “\n”) cat(“ Data set :”, dataset, “\n”, “\n”) cat(“ Complete model: ”, complete, “\n”, “\n”) cat(“ Reduced model : ”, reduced, “\n”, “\n”) cat(“ Variable estimated : ”, varname, “\n”, “\n”) cat(“ Maximum number of steps = ”, maxsteps, “\n”, “\n”) cat(“ Random seed = ”, seed, “\n”, “\n”) cat(“ Initial estimate = ”, initial, “\n”, “\n”) cat(“ Proportion to left = ”, plower,“\n”, “\n”) cat (“ Steplength constant = ”, k, “\n”, “\n”) cat(“\n”, “\n”, “Estimates:”, “\n”, “\n”) for (1 in 1:maxsteps) { yadj <− yvector − estimate*xa tunperm <− teststat(yadj,complete, reduced, varname) yadj <− permres(yadj,complete,reduced) tperm <− teststat(yadj,complete,reduced, varname) if( (tperm < tunperm) | ( (tperm==tunperm) & (plower > .5))) estimate <− estimate + k*plower/(1+22) ...

Get Adaptive Tests of Significance Using Permutations of Residuals with R and SAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.