R Under development (unstable) (2024-06-05 r86695 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 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. > ## reported by simon bond to R-help 2007-03-16 > library(nlme) > x <- rnorm(10, 0.1, 1) > try(gls(x ~ 0)) # segfaulted in 3.1-79 Error in gls(x ~ 0) : no coefficients to fit > > > ## PR#10364 > # copied verbatim from Pinheiro & Bates 8.3.3 > fm1Dial.gnls <- + gnls(rate ~ SSasympOff(pressure, Asym, lrc, c0), + data = Dialyzer, params = list(Asym + lrc ~ QB, c0 ~ 1), + start = c(53.6, 8.6, 0.51, -0.26, 0.225)) > (p1 <- predict(fm1Dial.gnls)) 1 2 3 4 5 6 7 8 1.475873 20.375561 36.405294 41.994432 44.039430 44.645427 44.863648 1.475873 9 10 11 12 13 14 15 16 22.159761 36.405294 41.929400 43.997815 44.649074 44.873769 1.941160 19.016369 17 18 19 20 21 22 23 24 36.677652 42.120376 43.997815 44.659782 44.863648 2.856859 19.840635 36.405294 25 26 27 28 29 30 31 32 41.962091 43.987129 44.641741 44.878512 2.856859 20.899106 36.497058 42.120376 33 34 35 36 37 38 39 40 44.039430 44.641741 44.873769 3.307378 20.109536 36.854405 42.026428 43.976327 41 42 43 44 45 46 47 48 44.634249 44.870076 7.151318 20.375561 36.124008 42.120376 44.008387 44.652682 49 50 51 52 53 54 55 56 44.868818 7.151318 20.375561 36.405294 42.089396 43.976327 44.634249 44.871320 57 58 59 60 61 62 63 64 2.401470 19.840635 36.497058 42.089396 43.920540 44.638015 44.866261 1.005557 65 66 67 68 69 70 71 72 20.375561 36.854405 41.929400 43.931939 44.634249 44.871320 2.395338 18.570454 73 74 75 76 77 78 79 80 38.683313 50.010624 56.009187 58.937674 60.429927 4.288996 18.850364 39.281339 81 82 83 84 85 86 87 88 50.010624 55.888046 58.916451 60.520040 9.617892 17.432637 40.007554 50.166772 89 90 91 92 93 94 95 96 55.805977 58.895090 60.486789 0.835945 17.432637 39.574631 50.010624 55.805977 97 98 99 100 101 102 103 104 58.808262 60.486789 2.778958 19.404810 38.378480 50.244095 55.805977 58.895090 105 106 107 108 109 110 111 112 60.464264 0.835945 17.719841 40.007554 50.397258 55.805977 58.937674 60.520040 113 114 115 116 117 118 119 120 4.660474 19.679370 39.428456 50.166772 55.764544 58.851956 60.464264 5.396300 121 122 123 124 125 126 127 128 19.404810 39.574631 49.852455 55.888046 58.808262 60.486789 5.029570 18.288739 129 130 131 132 133 134 135 136 39.719868 50.473104 56.049051 58.895090 60.418333 12.576983 16.852655 39.574631 137 138 139 140 50.397258 55.722845 58.937674 60.475563 attr(,"label") [1] "Fitted values (ml/hr)" > (p2 <- predict(fm1Dial.gnls, newdata = Dialyzer)) 1 2 3 4 5 6 7 8 1.475873 20.375561 36.405294 41.994432 44.039430 44.645427 44.863648 1.475873 9 10 11 12 13 14 15 16 22.159761 36.405294 41.929400 43.997815 44.649074 44.873769 1.941160 19.016369 17 18 19 20 21 22 23 24 36.677652 42.120376 43.997815 44.659782 44.863648 2.856859 19.840635 36.405294 25 26 27 28 29 30 31 32 41.962091 43.987129 44.641741 44.878512 2.856859 20.899106 36.497058 42.120376 33 34 35 36 37 38 39 40 44.039430 44.641741 44.873769 3.307378 20.109536 36.854405 42.026428 43.976327 41 42 43 44 45 46 47 48 44.634249 44.870076 7.151318 20.375561 36.124008 42.120376 44.008387 44.652682 49 50 51 52 53 54 55 56 44.868818 7.151318 20.375561 36.405294 42.089396 43.976327 44.634249 44.871320 57 58 59 60 61 62 63 64 2.401470 19.840635 36.497058 42.089396 43.920540 44.638015 44.866261 1.005557 65 66 67 68 69 70 71 72 20.375561 36.854405 41.929400 43.931939 44.634249 44.871320 2.395338 18.570454 73 74 75 76 77 78 79 80 38.683313 50.010624 56.009187 58.937674 60.429927 4.288996 18.850364 39.281339 81 82 83 84 85 86 87 88 50.010624 55.888046 58.916451 60.520040 9.617892 17.432637 40.007554 50.166772 89 90 91 92 93 94 95 96 55.805977 58.895090 60.486789 0.835945 17.432637 39.574631 50.010624 55.805977 97 98 99 100 101 102 103 104 58.808262 60.486789 2.778958 19.404810 38.378480 50.244095 55.805977 58.895090 105 106 107 108 109 110 111 112 60.464264 0.835945 17.719841 40.007554 50.397258 55.805977 58.937674 60.520040 113 114 115 116 117 118 119 120 4.660474 19.679370 39.428456 50.166772 55.764544 58.851956 60.464264 5.396300 121 122 123 124 125 126 127 128 19.404810 39.574631 49.852455 55.888046 58.808262 60.486789 5.029570 18.288739 129 130 131 132 133 134 135 136 39.719868 50.473104 56.049051 58.895090 60.418333 12.576983 16.852655 39.574631 137 138 139 140 50.397258 55.722845 58.937674 60.475563 attr(,"label") [1] "Predicted values (ml/hr)" > # failed, factor levels complaint > # also, missed row names as names > stopifnot(all.equal(as.vector(p1), as.vector(p2)), # 'label' differs + identical(names(p1), names(p2))) > > > ## PR#13418 > fm1 <- gls(weight ~ Time * Diet, BodyWeight) > (V10 <- Variogram(fm1, form = ~ Time | Rat)[1:10,]) variog dist n.pairs 1 0.007239522 1 16 2 0.014584634 6 16 3 0.014207936 7 144 4 0.018442267 8 16 5 0.011128505 13 16 6 0.019910082 14 128 7 0.027072311 15 16 8 0.034140379 20 16 9 0.028320657 21 112 10 0.037525507 22 16 > ## failed in 3.1-89 > stopifnot(all.equal(V10$variog, + c(0.0072395216, 0.014584634, 0.014207936, 0.018442267, + 0.011128505, 0.019910082, 0.027072311, 0.034140379, + 0.028320657, 0.037525507)), + V10$dist == c(1, 6, 7, 8, 13, 14, 15, 20, 21, 22), + V10$n.pairs == 16*c(1, 1, 9, 1, 1, 8, 1, 1, 7, 1)) > > intervals(fm1) Approximate 95% confidence intervals Coefficients: lower est. upper (Intercept) 237.31347269 251.6516516 265.9898304 Time -0.01011197 0.3596391 0.7293902 Diet2 175.83103217 200.6654865 225.4999407 Diet3 227.23722348 252.0716778 276.9061321 Time:Diet2 -0.03458851 0.6058392 1.2462668 Time:Diet3 -0.34209014 0.2983375 0.9387652 Residual standard error: lower est. upper 30.90225 34.18162 38.24575 > > ## predict from model with factor and no intercept > fm1b <- gls(weight ~ Diet - 1, BodyWeight) > stopifnot(all.equal(predict(fm1b, BodyWeight[1,]), coef(fm1b)[1], + check.attributes = FALSE)) > ## in nlme <= 3.1-155, failed with > ## Error in X[, names(cf), drop = FALSE] : subscript out of bounds > > ## predict.gls(): handling newdata for factor variables > stopifnot(all.equal( + predict(fm1, newdata = data.frame(Time = 1, Diet = "1", stringsAsFactor = FALSE)), + fitted(fm1)[1], check.attributes = FALSE)) > ## in nlme <= 3.1-155, predict() failed with > ## Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : > ## contrasts can be applied only to factors with 2 or more levels > stopifnot(all.equal( + predict(fm1, data.frame(Time = 71, Diet = c("2", "3"), stringsAsFactor = FALSE)), + predict(fm1, data.frame(Time = 71, Diet = c("2", "3"), stringsAsFactor = TRUE)))) > ## in nlme <= 3.1-155, using character input failed with > ## Error in X[, names(cf), drop = FALSE] : subscript out of bounds > tools::assertError(predict(fm1, data.frame(Time = 71, Diet = 2)), verbose = TRUE) Asserted error: contrasts apply only to factors > ## more helpful error + warning now > > ## PR#17226: same for predict.gnls(), also without intercept > fm2 <- gnls(weight ~ f, data = BodyWeight, params = list(f ~ Diet - 1), + start = rep(coef(fm1)[1], 3)) > stopifnot(all.equal(predict(fm2, head(BodyWeight)), head(fitted(fm2)), + check.attributes = FALSE)) > ## in nlme <= 3.1-155, failed with > ## Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : > ## contrasts can be applied only to factors with 2 or more levels > stopifnot(all.equal( + predict(fm2, data.frame(Time = 71, Diet = c("2", "3"), stringsAsFactor = FALSE)), + predict(fm2, data.frame(Time = 71, Diet = c("2", "3"), stringsAsFactor = TRUE)))) > ## in nlme <= 3.1-155, failed with > ## Error in p %*% beta[pmap[[nm]]] : non-conformable arguments > > > ## PR#17880: offset() terms are (currently) not supported in package nlme > y <- 10:20; off <- rep(10, length(y)) > tools::assertError(gls(y ~ 1 + offset(off)), verbose = TRUE) Asserted error: offset() terms are not supported > ## the following was TRUE in nlme <= 3.1-155, unfortunately: > ## all.equal(coef(gls(y ~ 1 + offset(off))), coef(gls(y ~ 1))) > > > ## PR#18283: gls() did not keep terms so predict() lacked "predvars" > fm_poly <- gls(distance ~ poly(age, 1), data = Orthodont) > fm_nopoly <- gls(distance ~ age, data = Orthodont) > stopifnot(all.equal(predict(fm_poly, data.frame(age = 10)), + predict(fm_nopoly, data.frame(age = 10)))) > ## in nlme <= 3.1-155, prediction from fm_poly failed with > ## Error in poly(age, 1) : > ## 'degree' must be less than number of unique points > stopifnot(all.equal(predict(fm_poly, head(Orthodont)), + head(fitted(fm_poly)), check.attributes = FALSE)) > ## predictions were wrong due to data-dependent bases > > > ## R-help, From: Aaron Crowley; Jul 21, 2022 "Error generated by nlme::gnls" > df <- Soybean > n <- nrow(df) > set.seed(548) > for(j in 1:12) + df[sprintf("x%02d", j)] <- sample(0:1, size=n, replace=TRUE) > > gm12 <- gnls(weight ~ x, data = df, + params = (x ~ -1 + x01 + x02 + x03 + x04 + x05 + x06 + x07 + x08 + + x09 + x10 + x11 + x12), + start = rep(0, 12)) > ## gave error Error in if (deparse(params[[nm]][[3]]) != "1") { : > ## the condition has length > 1 > stopifnot(all.equal( + c(0.652122, 0.454468, 1.01271, 1.20772, 1.35816, -0.207982, + 1.19959, 0.349636, 2.39818, 1.36285, 0.75055, 1.18374), + unname(coef(gm12)), tol = 1e-5)) # Lnx x68_64: 1.18e-6 > > > ## PR#17988: corARMA() with default p=0=q fails, now with a clear error message > tools::assertError( + gls(follicles ~ 1, Ovary, correlation = corARMA(form = ~ 1 | Mare)) + , verbose = TRUE) Asserted error: at least one of 'p' and 'q' must be > 0 > ## in nlme <= 3.1-164, corARMA() returned dysfunctional corIdent() which gave > ## Error in getGroupsFormula.default(correlation) : > ## 'form' argument must be a formula > > proc.time() user system elapsed 0.26 0.04 0.29