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 E

R CODE FOR ADAPTIVE TEST WITH PAIRED DATA

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

adaptpaired <− function(dataset, r=2000, seed=1492) {
testdata <− read.table(dataset)
print(testdata)
attach(testdata)
pairs <− length(differences)
dneg <− −1.0*differences
n <− 2*pairs
resid <− matrix(0,n,1)
resid <− (rbind(differences,dneg))/2
#                     compute traditional quantiles
q25 <− quantile(resid, 0.25, type=6)
q75 <− quantile(resid, 0.75, type=6)
sigmat <− (q75−q25)/I.349
#                     compute bandwidth (h)
h <− 1.587*sigmat*n^(−0.33333333333) range <− max(resid) − min(resid) lower <− min(resid) − range upper <− max(resid) + range tol <− 0.000001*sigmat cdf25 <− rootcdf(resid, h, 0.25, lower, upper, tol) cdf50 <− rootcdf(resid, h, 0.50, lower, upper, tol) cdf75 <− rootcdf(resid, h, 0.75, lower, upper, tol) sigma <− (cdf75−cdf25)/I.349 # compute adaptive weights s <− (resid−cdf50)/sigma tolerance <− 100*tol w <− matrix(0, n, 1) weights2 <− matrix(0, pairs, 1) for (i in l:n) { fhat <− cdfhat(resid, h, resid[i]) z <− qnorm(fhat) if ( (abs(s[i]) >= tolerance) ) w[i] <− z/s[i] else w[i] <− 1 } for (i in l:pairs){ j = 2 *i−l weights2[i] <− w[j]^2 } print(weights2) dwbar <− (t(weights2)%*%differences)/sum(weights2) sseu <− (t(weights2)%*%((differences−dwbar)^2))/2 e <− 0 set.seed(seed) diffsignch <− matrix(0, pairs, 1) for (k in l:r) { unifnum <− runif(pairs) for (j in 1:pairs){ if( (unifnum[j] <= 0.5) ) diffsignch[j] <− differences[j] ...

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