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] ...

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.