O'Reilly logo

Adaptive Tests of Significance Using Permutations of Residuals with R and SAS by Thomas W. O'Gorman

Stay ahead with the world's most comprehensive technology and business learning platform.

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

Start Free Trial

No credit card required

APPENDIX D

R CODE FOR ADAPTIVE TESTS WITH BLOCKING FACTORS

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

adaptblock <- function(dataset,complete,reduced,r,seed,
                       nblocks) {
tradpvalue <- trad.ftest(dataset,complete,reduced)
testdata <- read.table(dataset)
print(testdata)
attach(testdata)
statsu <- teststats(y,complete, reduced)
lambdau <- statsu[l]
e <- 0
countperm <- 0
redu <- lm(as.formula(reduced))
yhat <- predict(redu)
yresidual <- residuals(redu)
set.seed(seed)
n <- length(yresidual) for (k in 1:r) { for (b in 1:nblocks[1]) { permres <- yresidual[block==b] lengthperm <- length(permres) if ( (lengthperm>1) )permres <- sample(permres) countperm[1] <- 0 for (i in 1:n) { if( (block[i]==b) ) { countperm[1] <- countperm[1] + 1 yresidual[i] <- permres[countperm[1]] } } } ynew <- yhat + yresidual statsp <- teststats(ynew,complete,reduced) lambdap <- statsp[1] if( (lambdap <= lambdau) ) e <- e + 1 } p <- (e+l)/(r+l) detach(testdata) cat(“\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(“ Number of permutations = ”,r,“\n”,“\n”) cat(“ Random seed = ”, seed, “\n”,“\n”,“\n”, “\n”) cat(“ Output:”,“\n”,“\n”) cat(“ Unpermuted lambda = ”, round (lambdau, 4), “\n”,“\n”) cat(“ Adaptive p-value = ”, round (p, 4), “\n”,“\n”) cat(“ Traditional ...

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

Start Free Trial

No credit card required