R version 3.2.3 beta (2015-11-29 r69717) -- "Wooden Christmas-Tree" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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. 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(nlme) > fm1 <- lmList(Oxboys) > fm1 Call: Model: height ~ age | Subject Data: Oxboys Coefficients: (Intercept) age 10 130.2616 3.722915 26 137.9927 5.588783 25 139.2105 4.024081 9 138.1369 6.009057 2 142.8584 5.440176 6 146.7908 3.963171 7 146.1279 4.990050 17 142.9777 8.611780 16 147.5447 4.545196 15 144.2759 7.124260 8 148.2929 6.464712 20 151.4707 4.374466 1 148.1203 7.178151 18 151.1804 5.957793 5 151.4293 6.246128 23 151.0645 7.185123 11 150.0467 8.506082 21 150.5210 7.497794 3 155.6508 4.774669 24 153.1404 6.764705 22 154.5670 8.087514 12 156.8106 7.015468 13 156.0714 8.493806 14 159.4738 8.670886 19 164.5761 9.065620 4 165.0724 9.360561 Degrees of freedom: 234 total; 182 residual Residual standard error: 0.6598878 > fm2 <- lme(fm1) > fm2 Linear mixed-effects model fit by REML Data: Oxboys Log-restricted-likelihood: -362.0455 Fixed: height ~ age (Intercept) age 149.371753 6.525469 Random effects: Formula: ~age | Subject Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 8.081077 (Intr) age 1.680717 0.641 Residual 0.659889 Number of Observations: 234 Number of Groups: 26 > vc2 <- VarCorr(fm2) > stopifnot( + all.equal(fixef(fm2), c("(Intercept)" = 149.371753, + age = 6.52546866), tol=1e-8), + all.equal(as.numeric(vc2[,"StdDev"]), + c(8.081077, 1.680717, 0.659889), tol=4e-7)) > > # bug report from Arne.Mueller@sanofi-aventis.com > mod <- distance ~ age + Sex > fm3 <- lme(mod, Orthodont, random = ~ 1) > pm3 <- predict(fm3, Orthodont) > stopifnot(all.equal(mean(pm3), 24.023148148), + all.equal( sd(pm3), 2.4802195115), + all.equal(quantile(pm3), c("0%" = 17.0817792, "25%" = 22.3481813, + "50%" = 23.9271016, "75%" = 25.5740014, + "100%"= 30.8662241))) > > > ## bug report and fix from Dimitris Rizopoulos and Spencer Graves: > ## when 'returnObject = TRUE', do not stop() but give warning() on non-convergence: > tools::assertWarning( + fm1 <- lme(distance ~ age, data = Orthodont, + control = lmeControl(msMaxIter = 1, returnObject = TRUE)) + ) > > ## based on bug report on R-help > (p3.1 <- predict(fm3, Orthodont[1,])) M01 25.39237 attr(,"label") [1] "Predicted values (mm)" > # failed in 3.1-88 > stopifnot(all.equal(pm3[1], p3.1, + check.attributes=FALSE, tolerance = 1e-14)) > > ## Intervals failed in a patch proposal (Nov.2015): > (fm4 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)) Linear mixed-effects model fit by REML Data: Orthodont Log-restricted-likelihood: -221.3183 Fixed: distance ~ age (Intercept) age 16.7611111 0.6601852 Random effects: Formula: ~age | Subject Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr (Intercept) 2.3270341 (Intr) age 0.2264278 -0.609 Residual 1.3100397 Number of Observations: 108 Number of Groups: 27 > (i4 <- intervals(fm4)) Approximate 95% confidence intervals Fixed effects: lower est. upper (Intercept) 15.2183224 16.7611111 18.3038999 age 0.5183867 0.6601852 0.8019837 attr(,"label") [1] "Fixed effects:" Random Effects: Level: Subject lower est. upper sd((Intercept)) 0.9485605 2.3270341 5.7087424 sd(age) 0.1025090 0.2264278 0.5001467 cor((Intercept),age) -0.9382505 -0.6093329 0.2981686 Within-group standard error: lower est. upper 1.084977 1.310040 1.581788 > reSS <- data.frame(lower = c(0.9485605, 0.10250901, -0.93825047), + est. = c(2.3270341, 0.22642779, -0.60933286), + upper = c(5.7087424, 0.50014674, 0.29816857)) > rownames(reSS) <- rownames(i4$reStruct$Subject) > sm4 <- summary(fm4) > stopifnot( + all.equal(fixef(fm4), + c("(Intercept)" = 16.761111, age = 0.66018519)), + identical(fixef(fm4), sm4$tTable[,"Value"]), + all.equal(sm4$tTable[,"Std.Error"], + c("(Intercept)" = 0.77524603, age = 0.071253264), tol=6e-8), + all.equal(i4$reStruct$Subject[,"est."], reSS[,"est."], tol= 8e-8) + ## (lower, upper) cannot be very accurate for these : ==> tol = *e-4 + , + all.equal(i4$reStruct$Subject[,c(1,3)], reSS[,c(1,3)], tol= 8e-4) + , + all.equal(as.vector(i4$sigma), + ## lower est. upper + c(1.0849772, 1.3100397, 1.5817881), tol=8e-4) + ) > > > ## wrong results from getData: > load("ss2.rda") > m1 <- lme(PV1MATH ~ ESCS + Age +time , + random = ~ time|SCHOOLID, + data = ss2, + weights = varIdent(form=~1|time), + corr = corCompSymm(form=~1|SCHOOLID/StIDStd), + na.action = na.omit) > plot(m1, resid(.) ~ WEALTH) > > m2 <- lme(PV1MATH ~ ESCS + Age +time , + random = ~ time|SCHOOLID, + data = ss2, + weights = varIdent(form=~1|time), + corr = corCompSymm(form=~1|SCHOOLID/StIDStd), + na.action = na.omit) > plot(m2, resid(.) ~ WEALTH) > > proc.time() user system elapsed 1.97 0.08 2.13