APPENDIX A

R CODE FOR UNIVARIATE ADAPTIVE TESTS

adapt <− function(dataset, complete, reduced, r=2000, seed=1492){

tradpvalue <− trad.ftest(dataset, complete, reduced)
testdata <− read.table(dataset)
print(testdata)
attach(testdata)
statsu<− teststats(y, complete, reduced)
lambdau <− statsu[l]
fu <− statsu[2]
e <− 0
redu <− lm(as.formula(reduced))
yhat <− predict(redu)
yresidual <− residuals(redu)
set.seed(seed)
for (k in l:r) {
 ynew <− yhat+sample(yresidual)
statsp <− teststats(ynew, complete, reduced) lambdap <− statsp[1] if( (lambdap <= lambdau) ) e <− e + 1 } p <− (e+1)/(r+1) 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 from Adaptive Test:”, “\n”, “\n”) cat (“ Unpermuted lambda = ”, round(lambdau, 4), “\n”, “\n”) cat (“ Unpermuted F = ”, round(fu, 4), “\n”, “\n”) cat (“ p-value = ”, round(p, 4), “\n”, “\n”, “\n”) cat (“ Trad. F test p-value = ”, round(tradpvalue, 4), “\n”) cat (“\n”, “ *************************************** ”, “\n”, “\n”) return(p) } teststats <− function(y, complete, reduced) { red <− 1m(as.formula(reduced)) resid <− residuals(red) # compute traditional quantiles q25 <− quantile(resid, 0.25, type=6) q75 <− quantile(resid, 0.75, type=6) ...

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.