## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# 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) ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required