GLM+Randomization

Generalized Linear Model (GLM) Randomization

Applications:  GLM –  Regression models that allow us to generalize the linear regression approach to accommodate many types of response variables including count, binary, proportions and positive valued continuous distributions (Nelder and Wedderburn, 1972; Hilbe, 1994; Hoffman, 2004). Randomization – Randomization (or permutation) tests involve reordering observed data values (see Crowley [1992], Edgington [1995], and Manly [2007] for detailed coverage of random resampling methods). Permutation tests provide for the fewest assumptions to be met by a dataset when explanatory variables are fixed.

Assumptions: GLM – Homogeneity, Normality, and Independence of Residuals; Variance equal to Mean Randomization – effectively removes assumptions above (Crowley 1992, Manly 2007).

Program: R (2.8) Package: stats  Calls: glm + fitted, resid, plot, lag.plot, qqnorm, qqline, abline, coef, deviance, df.residual Package: car (1.2-9) Calls: Anova Generic Implementation: //# DATA MUST BE IN TAB DELIMITED TEXT FILE TO FOLLOW THIS ROUTINE.// //# IMPORT DATA TO R:// // data.name // <-read.delim(" // filename // .txt") //# CHECK THAT COLUMN HEADERS ARE CORRECT://  names( // data.name // ) ## [1] "// var.1 //" "// var.2 //" "// ... //" //# CONSTRUCT THE MODEL:// //# INDEPENDENCE – 1. COLINEARTY OF EXPLANATORY VARIABLES, REMOVE DATA REPLICATION, RE-RUN//  pairs(with( // data.name // ,cbind( // var.1 //, // var.2 // , // var.3 // , // var.4 // , // ... // ))) // model.name // <-with( // data.name // ,glm( // response.variable // ~ // var.1 // + // var.2 // + // var.3 // + // var.4 // + // ... // ,family= // family // )) //# family CAN BE gaussian, poisson, Gamma(link="identity"), binomial,// //quasi, quasipossion, OR quasibinomial.// //# ALL COLUMNS OF DATA IN NUMBER FORMAT ARE ASSUMED TO BE RATIO DATA IN R.// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# TO COERCE TO CATEGORICAL USE factor( var.name ) AS THE VARIABLE.// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# INTERACTION TERMS MAY BE ENTERED AS var.name*var.name TO INCLUDE INTERACTION AND MAIN TERMS, OR AS var.name:var.name FOR ONLY THE INTERACTION TERM.// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# CHECK ASSUMPTIONS WITH PLOTS (KEEP PLOT WINDOW OPEN, R WILL AUTOMATICALLY REPLACE EACH TIME)// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# STRAIGHT LINE (IF YOU HAVE A REGRESSION) & HOMOGENEITY// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> plot(fitted( // model.name // ),resid( // model.name // )) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# INDEPENDENCE – 2. LAGGED RESIDUALS// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> lag.plot(resid( // model.name // )) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# NORMALITY// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> qqnorm(resid( // model.name // )) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> qqline(resid( // model.name // )) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# LINEAR MODEL FIT (LINK FUNCTION CHECK)// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> plot(fitted( // model.name // ), with( // data.name //, // response.variable // )) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# FIT REGRESSION LINE TO THE PLOT// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> abline(lm(with( // data.name //, // response.variable // )~fitted( // model.name // ))) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# EXTRACT REGRESSION COEFFICIENTS// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> coef(lm(with( // data.name //, // response.variable // )~fitted( // model.name // ))) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## (Intercept) fitted(// model.name //) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## // #.######## // // #.######## <-this value is slope of importance // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# DISPERSION// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> deviance( // model.name // ) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> df.residual( // model.name // ) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> deviance( // model.name // )/df.residual( // model.name // ) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# PRINT ANODEV TABLE:// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> Anova( // model.name // ,type="III") <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Anova Table (Type III tests) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Response: // response.variable // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## LR Chisq Df Pr(>Chisq) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## // var.1 #.#### # #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## // var.2 #.#### # #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## // ... #.#### # #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## --- <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## ASSIGN EXPERIMENTAL LR Chisq TO A VECTOR: <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">// exp.chi // <-data.frame(data.frame(Anova( // model.name // ,type="III"))[,1]) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# CHECK THAT ASSIGNMENT WAS CORRECT:// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">// exp.chi // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## data.frame.Anova.model2..type....III......1. <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## 1 // #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## 2 // #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## ... // #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# CHECK THAT INDIVIDUAL VALUE WITHIN VECTOR IS CORRECT:// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">// exp.chi // [1,] <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## [1] // #.###### // <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"># ASSIGN RANDOMIZED LR Chisq VALUES TO A MATRIX: <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">// rand.chi // <-data.frame(rbind(replicate( // #### // ,c(data.frame(with( // data.name //, Anova(glm(sample( // response.variable // , // ## // ,FALSE)~ // var.1 // + // var.2 // + // var.3 // + // var.4 // + // ... // ,family= // family // ),type="III")))[,1])))) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# #### IS NUMBER OF RANDOMIZATIONS.// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# ## MUST EQUAL NUMBER OF OBSERVATIONS OF response.variable .// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# CALCULATE RANDOMIZED P-VALUE FOR EACH TERM OF INTEREST:// <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> summary(c( // rand.chi // [1,])> // exp.chi // [1,]) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Mode FALSE TRUE NA's <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## logical // ### // //###// 0 <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> summary(c( // rand.chi // [2,])> // exp.chi // [2,]) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Mode FALSE TRUE NA's <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## logical // ### // //###// 0 <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;"> summary(c( // rand.chi // [...,])> // exp.chi // [...,]) <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## Mode FALSE TRUE NA's <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">## logical // ### // //###// 0 <span style="margin-bottom: 0in; margin-left: 63.8pt; margin-right: 0in; margin-top: 0in; text-indent: -21.25pt;">//# ### TRUE DIVIDED BY #### RANDOMIZATIONS IS THE P-VALUE FOR EACH TERM.//

Weblinks: N/A

References:

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Agresti, A. 2007. An introduction to categorical data analysis. Wiley-Interscience: Hoboken, NJ, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Breslow, N. 1996. Generalized linear models: checking assumptions and strengthening conclusions. Statistica applicata. 8: 23-41. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Carroll, R. and C. Spiegelman. 1992. Diagnostics for nonlinearity and heteroscedasticity in errors-in-variables regression. Technometrics. 34: 186-196. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Crowley <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">, P. 1992. Resampling methods for computation-intensive data analysis in ecology and evolution. Annual Review of Ecology and Systematics. 23:405–447. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Dobson, A. 2002. An introduction to generalized linear models. Chapman & Hall/CRC: Boca Raton, FL, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Edgington, E. 1995. Randomization tests. Third edition. M. Dekker, New York, NY, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Fox, J. 2007. car: Companion to Applied Regression R Foundation for Statistical Computing: Vienna, Austria. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Gill, J. 2001. Generalized linear models: a unified approach. Sage University Paper: London, UK. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Guisan, A., T. Edwards, C. Hastie. 2002. Generalized linear and generalized additive models in studies of species distributions: setting the scene. Ecological Modeling. 157, 89-100. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Hilbe, J. 1994. Generalized linear models. American Statistical Association. 48: 255-265. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Hoffmann, J. P. 2004. Generalized linear models: an applied approach. Pearson: Boston, MA, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Lindsey, J. 1997. Applying generalized linear models. Springer: New York, NY, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Manly, B. 2007. Randomization, bootstrap and Monte Carlo methods in biology. Third edition. Chapman & Hall/CRC: Boca Raton, FL, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">McCullogh, P. and J. Nelder. 1989. Generalized linear models. Second edition. Chapman and Hall: New York, NY, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Nelder, J. and R. Wedderburn. 1972. Generalized linear models. J. R. Statist. Soc. A. 135: 370-384. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Petraitis, P.S., S.J. Beaupre, and A.E. Dunham. 2001. ANCOVA: Nonparamentric and randomization approaches. pp. 116-133 in S.M. Scheiner and J. Guervitch, eds. Design and analysis of ecological experiments. Second edition. Oxford University Press: New York, NY, USA. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">Potvin, C. and D. Roff. 1993. Distribution-free and robust statistical method: viable alternatives to parametric statistics? Ecology. 74: 1617–1628. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;">R Core Development Team. 2008. R: a language and environmental for <span style="font-family: Arial,Helvetica,sans-serif; font-size: 90%;"> statistical computing. Version 2.8.0. Vol. R Foundation for Statistical Computing: Vienna, Austria.