stat196, week3, Poisson outcome factorial design HIE Syndney > ?read.csv starting httpd help server ... done > ?read.table > forest = read.table("https://www.westernsydney.edu.au/__data/assets/text_file/0011/917237/eucfaceGC.csv", header = TRUE, sep = ",") > str(forest) 'data.frame': 192 obs. of 8 variables: $ Date : Factor w/ 2 levels "11/06/13","3/09/13": 1 1 1 1 1 1 1 1 1 1 ... $ Ring : int 1 1 1 1 1 1 1 1 1 1 ... $ Plot : int 1 1 1 1 2 2 2 2 3 3 ... $ Sub : int 1 2 3 4 1 2 3 4 1 2 ... $ Forbes: int 0 2 0 0 2 5 4 0 1 3 ... $ Grass : int 16 14 16 16 15 16 16 16 16 13 ... $ Litter: int 5 6 2 2 3 3 4 3 0 4 ... $ Trt : Factor w/ 2 levels "ctrl","elev": 2 2 2 2 2 2 2 2 2 2 ... > dim(forest) [1] 192 8 > stem(forest$Forbes) The decimal point is at the | 0 | 00000000000000000000000000000000000000000000000000000000000000000000+14 1 | 000000000000000000000000000 2 | 0000000000000000 3 | 000000000000000000 4 | 000000 5 | 00000000000 6 | 000000 7 | 000000 8 | 000 9 | 00 10 | 00 11 | 0 > table(forest$Forbes) 0 1 2 3 4 5 6 7 8 9 10 11 94 27 16 18 6 11 6 6 3 2 2 1 > fivenum(forest$Forbes) [1] 0 0 1 3 11 > forb.pois <- glmer(Forbes~Date*Trt+(1|as.factor(Ring)),family=poisson, data=forest) Error: couldn't evaluate grouping factor as.factor(Ring) within model frame: try adding grouping factor to data frame explicitly if possible > forest$Ring <- as.factor(paste(forest$Ring, forest$Trt, sep='-')) > forb.pois <- glmer(Forbes~Date*Trt+(1|Ring),family=poisson, data=forest) > summary(forb.pois) Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] Family: poisson ( log ) Formula: Forbes ~ Date * Trt + (1 | Ring) Data: forest AIC BIC logLik deviance df.resid 659.5 675.8 -324.7 649.5 187 Scaled residuals: Min 1Q Median 3Q Max -2.2892 -0.8289 -0.6934 0.7290 5.6446 Random effects: Groups Name Variance Std.Dev. Ring (Intercept) 0.7981 0.8934 Number of obs: 192, groups: Ring, 6 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) 0.36114 0.53258 0.678 0.498 Date3/09/13 -1.05605 0.20412 -5.174 2.3e-07 *** Trtelev 0.03945 0.75050 0.053 0.958 Date3/09/13:Trtelev 1.02866 0.24458 4.206 2.6e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) Dt3/09/13 Trtelv Date3/09/13 -0.099 Trtelev -0.709 0.070 Dt3/09/13:T 0.083 -0.835 -0.107 > exp(fixef(forb.pois)) (Intercept) Date3/09/13 Trtelev Date3/09/13:Trtelev 1.4349572 0.3478259 1.0402348 2.7973069 > exp(confint(forb.pois)) Computing profile confidence intervals ... 2.5 % 97.5 % .sig01 1.7010845 6.2396119 (Intercept) 0.4091106 4.8319798 Date3/09/13 0.2292726 0.5140375 Trtelev 0.1838199 5.9957720 Date3/09/13:Trtelev 1.7420442 4.5743513 # The HIE guide does a more complex (within Ring) replication. > forest$Plot <- as.factor(forest$Plot) > forest$Sub <- as.factor(forest$Sub) > forb.pois.nest <- glmer(Forbes~Date*Trt+(1|Ring/Plot/Sub),family=poisson, data=forest) > summary(forb.pois.nest) Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] Family: poisson ( log ) Formula: Forbes ~ Date * Trt + (1 | Ring/Plot/Sub) Data: forest AIC BIC logLik deviance df.resid 614.7 637.5 -300.3 600.7 185 Scaled residuals: Min 1Q Median 3Q Max -1.9409 -0.6627 -0.4394 0.4823 3.6061 Random effects: Groups Name Variance Std.Dev. Sub:(Plot:Ring) (Intercept) 0.1437 0.3790 Plot:Ring (Intercept) 0.5900 0.7681 Ring (Intercept) 0.8504 0.9222 Number of obs: 192, groups: Sub:(Plot:Ring), 96; Plot:Ring, 24; Ring, 6 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) 0.08894 0.59923 0.148 0.882 Date3/09/13 -1.05606 0.19836 -5.324 1.02e-07 *** Trtelev 0.03243 0.84154 0.039 0.969 Date3/09/13:Trtelev 1.02866 0.23830 4.317 1.58e-05 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) Dt3/09/13 Trtelv Date3/09/13 -0.085 Trtelev -0.705 0.061 Dt3/09/13:T 0.071 -0.832 -0.094 > exp(fixef(forb.pois.nest)) (Intercept) Date3/09/13 Trtelev Date3/09/13:Trtelev 1.0930189 0.3478244 1.0329578 2.7973041 > exp(confint(forb.pois.nest)) Computing profile confidence intervals ... 2.5 % 97.5 % .sig01 1.1187957 1.8936468 .sig02 1.5465222 3.6756420 .sig03 1.5221009 7.5639339 (Intercept) 0.2624446 4.2286415 Date3/09/13 0.2292838 0.5140144 Trtelev 0.1461481 7.4206146 Date3/09/13:Trtelev 1.7420895 4.5742068 > # about same result