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 G

R CODE FOR MULTIVARIATE ADAPTIVE TESTS

Note: The functions cdfhat must also be included. This is in Appendix A and on the file adapt.r.

adaptmult <- function(y,complete,reduced,r=2000,seed=1492) {
lambdau<- teststat(y,complete,reduced)
e <- 0
redu <- lm(as.formula(reduced))
yhat <- predict(redu)
yresidual <- residuals(redu)
set.seed(seed)
n <- length(yhat[,1])
nvars <- length(yhat[1,])
y <- matrix(0,n,nvars)
observations <- c(1:n)
 for (k in 1:r) {
  place <- sample(observations)
  for (i in 1:n) {
row <- place[i] y[i,] <- yhat[i,] + yresidual[row,] } lambdap <- teststat(y,complete,reduced) 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(“ Dependent variables: ”, yvars,“\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(“ p-value = ”,round(p,4),“\n”,“\n”,“\n”) cat(“\n”,“*************************************”,“\n” “\n”) return(p) } teststat <- function(y,complete,reduced) { red <- lm(as.formula(reduced)) resid <- residuals(red) n <- length(resid[,1 ] ) nvars <- length(resid[1,]) # standardize residuals temp <- matrix(0,n,1) for (j in 1:nvars) { temp <- resid[,j] q25 <- quantile(temp,0.25,type=6) ...

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