Rev 7620 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R version 3.5.2 Patched (2019-01-14 r75994) -- "Eggshell Igloo"Copyright (C) 2019 The R Foundation for Statistical ComputingPlatform: 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)>> options(digits = 6)# <==> less platform dependency in print() output> if(!dev.interactive(orNone=TRUE)) pdf("test_lme.pdf")>> fm1 <- lmList(Oxboys)> fm1Call:Model: height ~ age | SubjectData: OxboysCoefficients:(Intercept) age10 130.262 3.7229126 137.993 5.5887825 139.210 4.024089 138.137 6.009062 142.858 5.440186 146.791 3.963177 146.128 4.9900517 142.978 8.6117816 147.545 4.5452015 144.276 7.124268 148.293 6.4647120 151.471 4.374471 148.120 7.1781518 151.180 5.957795 151.429 6.2461323 151.065 7.1851211 150.047 8.5060821 150.521 7.497793 155.651 4.7746724 153.140 6.7647022 154.567 8.0875112 156.811 7.0154713 156.071 8.4938114 159.474 8.6708919 164.576 9.065624 165.072 9.36056Degrees of freedom: 234 total; 182 residualResidual standard error: 0.659888> fm2 <- lme(fm1)> fm2Linear mixed-effects model fit by REMLData: OxboysLog-restricted-likelihood: -362.045Fixed: height ~ age(Intercept) age149.37175 6.52547Random effects:Formula: ~age | SubjectStructure: General positive-definite, Log-Cholesky parametrizationStdDev Corr(Intercept) 8.081077 (Intr)age 1.680717 0.641Residual 0.659889Number of Observations: 234Number 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))+ )>> ## "typo" in 'random=' -- giving 27-dim. vector random effect:> ## PR#17524 B.Tyner: https://bugs.r-project.org/show_bug.cgi?id=17524> try(lme(distance ~ 1, data=Orthodont, random = ~ Subject))Error in lme.formula(distance ~ 1, data = Orthodont, random = ~Subject) :fewer observations than random effects in all level 1 groups> tools::assertError(lme(distance ~ age, data=Orthodont, random = ~ Subject))> ## seg.faults in nlme <= 3.1-137 (2018) because of integer overflow> ## The previous warning is now an *error* (unless new lmeControl(allow.n.lt.q=TRUE))>>> ## based on bug report on R-help> (p3.1 <- predict(fm3, Orthodont[1,]))M0125.3924attr(,"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 REMLData: OrthodontLog-restricted-likelihood: -221.318Fixed: distance ~ age(Intercept) age16.761111 0.660185Random effects:Formula: ~age | SubjectStructure: General positive-definite, Log-Cholesky parametrizationStdDev Corr(Intercept) 2.327034 (Intr)age 0.226428 -0.609Residual 1.310040Number of Observations: 108Number of Groups: 27> i4 <- intervals(fm4)> ## from dput(signif(i4$reStruct$Subject, 8))> ## R-devel 2016-01-11; 64-bit :> 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))> ## R-devel 2016-01-11; 32-bit :> ## reSS <- data.frame(lower = c(0.94962127,0.10262181, -0.93804767),> ## est. = c(2.3270339, 0.22642779, -0.60933284),> ## upper = c(5.7023648, 0.49959695, 0.29662651))> 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= 1e-7)+ ## (lower, upper) cannot be very accurate for these : ==> tol = *e-4+ ,## "interestingly" 32-bit values changed from 3.2.3 to R-devel(3.3.0):+ all.equal(i4$reStruct$Subject[,c(1,3)], reSS[,c(1,3)], tol = .005)+ ,+ all.equal(as.vector(i4$sigma),+ ## lower est. upper+ c(1.0849772, 1.3100397, 1.5817881), tol=8e-4)+ ,+ all.equal(as.vector(i4$fixed),+ as.vector(rbind(c(15.218322, 16.761111, 18.3039),+ c(0.51838667, 0.66018519, 0.8019837))),+ tol = 1e-6)+ )>>> ## wrong results from getData:> ss2 <- readRDS("ss2.rds")> 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)>>> ## Variogram() failing in the case of 1-observation groups (PR#17192):> BW <- subset(BodyWeight, ! (Rat=="1" & Time > 1))> if(interactive())+ print( xtabs(~ Rat + Time, data = BW) )# Rat '1' only at Time == 1> fm2 <- lme(fixed = weight ~ Time * Diet, random = ~ 1 | Rat, data = BW)> Vfm2 <- Variogram(fm2, form = ~ Time | Rat)> stopifnot(is.data.frame(Vfm2),+ identical(dim(Vfm2), c(19L, 3L)),+ all.equal(unlist(Vfm2[10,]), c(variog = 1.08575384191148,+ dist = 22, n.pairs = 15))+ )> ## failed in nlme from 3.1-122 till 3.1-128>> proc.time()user system elapsed1.376 0.138 1.653