Re: Anova() in car not works after loading piecewiseSEM package
varin sacha via R-help <[email protected]> Sun, 19 Jul 2026 08:38:29 +0200
| Newsgroups | gmane.comp.lang.r.general |
|---|---|
| Message-ID | <[email protected]> |
Ok ! According to what I see, the error is occurring inside car:::Anova.lme(), s= pecifically during the construction of the model matrix. It therefore appears to be a genuine compatibility problem between the curr= ent CRAN versions of car (3.1-5), piecewiseSEM (2.3.1), and/or nlme (3.1-17= 0). The fact that you reproduced the same behavior on both Windows and FreeBSD = also suggests that the issue is not platform-specific. I think this would be worth reporting to the package maintainers (perhaps s= tarting with car, since the traceback shows that the failure occurs inside = Anova.lme(), while mentioning that the problem only arises after loading pi= ecewiseSEM). The reproducible example you=E2=80=99ve provided should make i= t straightforward for them to investigate. > Le 19 juil. 2026 =C3=A0 08:22, Jinsong Zhao <[email protected]> a =C3=A9cri= t : > = > =EF=BB=BFThank for the instruction. Here is the whole outputs: > = > > library(piecewiseSEM) > Registered S3 method overwritten by 'lme4': > method from > na.action.merMod car > = > This is piecewiseSEM version 2.3.0.2. > = > = > Questions or bugs can be addressed to <[email protected]>. > > library(nlme) > > library(car) > Loading required package: carData > > fm2 <- lme(distance ~ age + Sex, data =3D Orthodont, random =3D ~ 1) > > Anova(fm2) > Error in if (random) { : the condition has length > 1 > > car::Anova(fm2) > Error in if (random) { : the condition has length > 1 > > car:::Anova.lme(fm2) > Error in if (random) { : the condition has length > 1 > > traceback() > 8: model.frame.lme(object, data, xlev =3D xlev) > 7: model.frame(object, data, xlev =3D xlev) > 6: model.matrix.default(mod, data =3D structure(list(distance =3D c(26, > 25, 29, 31, 21.5, 22.5, 23, 26.5, 23, 22.5, 24, 27.5, 25.5, 27.5, > 26.5, 27, 20, 23.5, 22.5, 26, 24.5, 25.5, 27, 28.5, 22, 22, 24.5, > 26.5, 24, 21.5, 24.5, 25.5, 23, 20.5, 31, 26, 27.5, 28, 31, 31.5, > 23, 23, 23.5, 25, 21.5, 23.5, 24, 28, 17, 24.5, 26, 29.5, 22.5, > 25.5, 25.5, 26, 23, 24.5, 26, 30, 22, 21.5, 23.5, 25, 21, 20, > 21.5, 23, 21, 21.5, 24, 25.5, 20.5, 24, 24.5, 26, 23.5, 24.5, > 25, 26.5, 21.5, 23, 22.5, 23.5, 20, 21, 21, 22.5, 21.5, 22.5, > 23, 25, 23, 23, 23.5, 24, 20, 21, 22, 21.5, 16.5, 19, 19, 19.5, > 24.5, 25, 28, 28), age =3D c(8, 10, 12, 14, 8, 10, 12, 14, 8, 10, > 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, > 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, > 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, > 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, > 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, > 14, 8, 10, 12, 14, 8, 10, 12, 14, 8, 10, 12, 14), Subject =3D structur= e(c(15L, > 15L, 15L, 15L, 3L, 3L, 3L, 3L, 7L, 7L, 7L, 7L, 14L, 14L, 14L, > 14L, 2L, 2L, 2L, 2L, 13L, 13L, 13L, 13L, 5L, 5L, 5L, 5L, 6L, > 6L, 6L, 6L, 11L, 11L, 11L, 11L, 16L, 16L, 16L, 16L, 4L, 4L, 4L, > 4L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 12L, > 12L, 12L, 12L, 1L, 1L, 1L, 1L, 20L, 20L, 20L, 20L, 23L, 23L, > 23L, 23L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 21L, 21L, 21L, > 21L, 19L, 19L, 19L, 19L, 22L, 22L, 22L, 22L, 24L, 24L, 24L, 24L, > 18L, 18L, 18L, 18L, 17L, 17L, 17L, 17L, 27L, 27L, 27L, 27L), levels = =3D c("M16", > "M05", "M02", "M11", "M07", "M08", "M03", "M12", "M13", "M14", > "M09", "M15", "M06", "M04", "M01", "M10", "F10", "F09", "F06", > "F01", "F05", "F07", "F02", "F08", "F03", "F04", "F11"), class =3D c("= ordered", > "factor")), Sex =3D structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, > 2L, 2L, 2L, 2L), levels =3D c("Male", "Female"), class =3D "factor")),= row.names =3D c("1", > "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", > "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", > "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", > "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", > "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", > "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", > "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", > "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", > "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", > "101", "102", "103", "104", "105", "106", "107", "108"), outer =3D ~Se= x, class =3D c("nfnGroupedData", > "nfGroupedData", "groupedData", "data.frame"), formula =3D distance ~ > age | Subject, labels =3D list(x =3D "Age", y =3D "Distance from p= ituitary to pterygomaxillary fissure"), units =3D list( > x =3D "(yr)", y =3D "(mm)"), FUN =3D structure(function (x) > max(x, na.rm =3D TRUE), source =3D "function (x) max(x, na.rm =3D TRUE= )"), order.groups =3D TRUE), > contrasts.arg =3D list(Sex =3D structure(c(0, 1), dim =3D 2:1, dim= names =3D list( > c("Male", "Female"), "Female")))) > 5: NextMethod(formula(object), data =3D data, contrasts.arg =3D object$co= ntrasts) > 4: model.matrix.lme(mod) > 3: model.matrix(mod) > 2: Anova_II_lme(mod, vcov., singular.ok =3D singular.ok) > 1: car:::Anova.lme(fm2) > > sessionInfo() > R version 4.6.1 (2026-06-24 ucrt) > Platform: x86_64-w64-mingw32/x64 > Running under: Windows 10 x64 (build 19045) > = > Matrix products: default > LAPACK version 3.12.1 > = > locale: > [1] LC_COLLATE=3DChinese (Simplified)_China.utf8 > [2] LC_CTYPE=3DChinese (Simplified)_China.utf8 > [3] LC_MONETARY=3DChinese (Simplified)_China.utf8 > [4] LC_NUMERIC=3DC > [5] LC_TIME=3DChinese (Simplified)_China.utf8 > = > time zone: Asia/Shanghai > tzcode source: internal > = > attached base packages: > [1] stats graphics grDevices utils datasets methods base > = > other attached packages: > [1] car_3.1-5 carData_3.0-6 nlme_3.1-170 piecewiseSEM_2.3.1 > = > loaded via a namespace (and not attached): > [1] Matrix_1.7-5 jsonlite_2.0.0 compiler_4.6.1 Rcpp_1.1.2 > [5] DiagrammeR_1.0.12 splines_4.6.1 boot_1.3-32 fastmap_1.2.0 > [9] lattice_0.22-9 TH.data_1.1-5 Formula_1.2-5 MuMIn_1.48.19 > [13] rbibutils_2.4.1 htmlwidgets_1.6.4 MASS_7.3-66 visNetwork_2.1.4 > [17] nloptr_2.2.1 insight_1.5.2 minqa_1.2.8 RColorBrewer_1.1-3 > [21] rlang_1.3.0 multcomp_1.4-31 performance_0.17.1 estimabilit= y_2.0.0 > [25] cli_3.6.6 magrittr_2.0.5 Rdpack_2.6.6 emmeans_2.0.4 > [29] digest_0.6.39 grid_4.6.1 mvtnorm_1.4-2 sandwich_3.1-2 > [33] lme4_2.0-6 reformulas_0.4.4 glue_1.8.1 codetools_0.2-20 > [37] zoo_1.8-15 survival_3.8-9 abind_1.4-8 stats4_4.6.1 > [41] tools_4.6.1 htmltools_0.5.9 > > packageVersion("car") > [1] =E2=80=983.1.5=E2=80=99 > > packageVersion("piecewiseSEM") > [1] =E2=80=982.3.1=E2=80=99 > > packageVersion("nlme") > [1] =E2=80=983.1.170=E2=80=99 > = > All the packages are installed from CRAN, and updated to the latest versi= on. I also run the codes on FreeBSD 15.1, the same output. > = > Best, > = > Jinsong > = >> On 7/19/2026 2:02 PM, varin sacha wrote: >> Hi, >> = >> Could this be a package compatibility bug? >> = >> Since Anova(fm2), car::Anova(fm2), and even car:::Anova.lme(fm2) all pro= duce the same error, it doesn=E2=80=99t appear to be a simple namespace mas= king issue. >> = >> Could you post the output of: >> = >> traceback() >> sessionInfo() >> packageVersion("car") >> packageVersion("piecewiseSEM") >> packageVersion("nlme") >> = >> That should help identify the exact call that=E2=80=99s failing and whet= her the problem lies in car, piecewiseSEM, or an incompatibility between th= e two packages. >> = >> = >> = >>>> Le 19 juil. 2026 =C3=A0 04:58, Jinsong Zhao <[email protected]> a =C3=A9= crit : >>> = >>> I have tried each solution in a new R session, and neither works. >>> = >>>> library(piecewiseSEM) >>> Registered S3 method overwritten by 'lme4': >>> method from >>> na.action.merMod car >>> = >>> This is piecewiseSEM version 2.3.0.2. >>> = >>> = >>> Questions or bugs can be addressed to <[email protected]>. >>>> library(nlme) >>>> library(car) >>> Loading required package: carData >>>> fm2 <- lme(distance ~ age + Sex, data =3D Orthodont, random =3D ~ 1) >>>> Anova(fm2) >>> Error in if (random) { : the condition has length > 1 >>>> car::Anova(fm2) >>> Error in if (random) { : the condition has length > 1 >>>> car:::Anova.lme(fm2) >>> Error in if (random) { : the condition has length > 1 > =