R version 2.7.0 Under development (unstable) (2008-01-31 r44278) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(lme4) Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from package:stats : xtabs > sessionInfo() R version 2.7.0 Under development (unstable) (2008-01-31 r44278) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lme4_0.999375-2 Matrix_0.999375-5 lattice_0.17-4 loaded via a namespace (and not attached): [1] grid_2.7.0 > data(ships, package = "MASS") > ships$period <- factor(ships$period) > ships$year <- factor(ships$year) > str(ships) 'data.frame': 40 obs. of 5 variables: $ type : Factor w/ 5 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 2 2 ... $ year : Factor w/ 4 levels "60","65","70",..: 1 1 2 2 3 3 4 4 1 1 ... $ period : Factor w/ 2 levels "60","75": 1 2 1 2 1 2 1 2 1 2 ... $ service : int 127 63 1095 1095 1512 3353 0 2244 44882 17176 ... $ incidents: int 0 0 3 4 6 18 0 11 39 29 ... > summary(gm1 <- glm(incidents ~ type + period + year, poisson, ships, + offset = log(service), subset = service > 0)) Call: glm(formula = incidents ~ type + period + year, family = poisson, data = ships, subset = service > 0, offset = log(service)) Deviance Residuals: Min 1Q Median 3Q Max -1.6768 -0.8293 -0.4370 0.5058 2.7912 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -6.40590 0.21744 -29.460 < 2e-16 *** typeB -0.54334 0.17759 -3.060 0.00222 ** typeC -0.68740 0.32904 -2.089 0.03670 * typeD -0.07596 0.29058 -0.261 0.79377 typeE 0.32558 0.23588 1.380 0.16750 period75 0.38447 0.11827 3.251 0.00115 ** year65 0.69714 0.14964 4.659 3.18e-06 *** year70 0.81843 0.16977 4.821 1.43e-06 *** year75 0.45343 0.23317 1.945 0.05182 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for poisson family taken to be 1) Null deviance: 146.328 on 33 degrees of freedom Residual deviance: 38.695 on 25 degrees of freedom AIC: 154.56 Number of Fisher Scoring iterations: 5 > (fm1 <- lmer(incidents ~ type + period + (1|year), ships, poisson, + subset = service > 0, offset = log(service), + verbose = 1)) 0: 56.324851: 0.560112 -5.80233 -0.742961 -0.754492 -0.184515 0.388495 0.503035 1: 52.443218: 0.486594 -5.81197 -0.586829 -0.765313 -0.186328 0.306971 0.377171 2: 51.027620: 0.273061 -5.85529 -0.616571 -0.742885 -0.133739 0.287584 0.399082 3: 51.000404: 0.307239 -5.85955 -0.596402 -0.740351 -0.129823 0.294884 0.402664 4: 50.991950: 0.296412 -5.88658 -0.596912 -0.731550 -0.119153 0.312545 0.384511 5: 50.962732: 0.279763 -5.88712 -0.574804 -0.722006 -0.107773 0.323063 0.408667 6: 50.947186: 0.302802 -5.89532 -0.578942 -0.699239 -0.0852610 0.316915 0.406992 7: 50.934658: 0.290722 -5.89763 -0.575193 -0.700236 -0.0879166 0.320458 0.397380 8: 50.932280: 0.295799 -5.89644 -0.570728 -0.699260 -0.0919162 0.334647 0.400968 9: 50.930416: 0.291949 -5.90257 -0.571984 -0.698084 -0.0907263 0.333282 0.400983 10: 50.930233: 0.292603 -5.90112 -0.570161 -0.697808 -0.0899512 0.332447 0.402873 11: 50.929900: 0.292245 -5.90081 -0.571103 -0.696584 -0.0875279 0.332722 0.401375 12: 50.929854: 0.292816 -5.90169 -0.570542 -0.696453 -0.0875669 0.331954 0.401691 13: 50.929849: 0.292481 -5.90193 -0.570829 -0.696352 -0.0875021 0.332103 0.401527 14: 50.929838: 0.292540 -5.90198 -0.570581 -0.696005 -0.0873020 0.332288 0.401761 15: 50.929836: 0.292591 -5.90223 -0.570349 -0.695775 -0.0871275 0.332607 0.401635 16: 50.929836: 0.292542 -5.90225 -0.570317 -0.695717 -0.0870174 0.332581 0.401713 17: 50.929836: 0.292573 -5.90227 -0.570327 -0.695693 -0.0870332 0.332559 0.401708 18: 50.929836: 0.292561 -5.90226 -0.570316 -0.695688 -0.0870394 0.332550 0.401713 19: 50.929836: 0.292559 -5.90226 -0.570321 -0.695701 -0.0870231 0.332545 0.401709 20: 50.929836: 0.292561 -5.90226 -0.570330 -0.695685 -0.0870361 0.332543 0.401711 21: 50.929836: 0.292563 -5.90226 -0.570325 -0.695694 -0.0870395 0.332543 0.401715 22: 50.929836: 0.292563 -5.90226 -0.570325 -0.695694 -0.0870395 0.332543 0.401715 Generalized linear mixed model fit by the Laplace approximation Formula: incidents ~ type + period + (1 | year) Data: ships Subset: service > 0 AIC BIC logLik deviance 64.93 75.61 -25.46 50.93 Random effects: Groups Name Variance Std.Dev. year (Intercept) 0.085592 0.29256 Number of obs: 34, groups: year, 4 Fixed effects: Estimate Std. Error z value Pr(>|z|) (Intercept) -5.90226 0.23165 -25.479 < 2e-16 *** typeB -0.57032 0.17644 -3.232 0.001227 ** typeC -0.69569 0.32884 -2.116 0.034381 * typeD -0.08704 0.29013 -0.300 0.764173 typeE 0.33254 0.23580 1.410 0.158464 period75 0.40171 0.11681 3.439 0.000584 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) typeB typeC typeD typeE typeB -0.647 typeC -0.320 0.433 typeD -0.359 0.455 0.241 typeE -0.438 0.574 0.313 0.337 period75 -0.353 0.048 0.005 -0.012 0.031 > #lmer(formula = incidents ~ type + (1 | period/year) + (1 | year), > # data = ships[ships$service>0,], family = poisson, offset = service, > # verbose=TRUE) > > proc.time() user system elapsed 8.680 0.112 8.784