1616# ' @seealso \code{\link{mira}}
1717# ' @method summary mira
1818# ' @export
19- summary.mira <- function (object ,
20- type = c(" tidy" , " glance" , " summary" ),
21- dfcom = NULL ,
22- ... ) {
19+ summary.mira <- function (
20+ object ,
21+ type = c(" tidy" , " glance" , " summary" ),
22+ dfcom = NULL ,
23+ ...
24+ ) {
2325 type <- match.arg(type )
2426 fitlist <- getfit(object )
2527 if (type == " tidy" ) {
2628 # Try standard tidy() first, with fallback for lmer objects
27- v <- tryCatch({
28- lapply(fitlist , tidy , effects = " fixed" , parametric = TRUE , ... ) %> % bind_rows()
29- }, error = function (e ) {
30- # Check if this is an lmerMod object without broom.mixed
31- if (inherits(fitlist [[1 ]], " lmerMod" ) &&
32- grepl(" No.*tidy.*method" , e $ message , ignore.case = TRUE )) {
33- # Manual extraction for lmer objects using built-in methods
34- lapply(fitlist , function (fit ) {
35- coefs <- lme4 :: fixef(fit )
36- se <- sqrt(diag(as.matrix(stats :: vcov(fit ))))
37- data.frame (
38- term = names(coefs ),
39- estimate = as.numeric(coefs ),
40- std.error = as.numeric(se ),
41- stringsAsFactors = FALSE
42- )
43- }) %> % bind_rows()
44- } else {
45- # Re-throw the error if it's not an lmer issue
46- stop(e )
29+ v <- tryCatch(
30+ {
31+ lapply(fitlist , tidy , effects = " fixed" , parametric = TRUE , ... ) %> %
32+ bind_rows()
33+ },
34+ error = function (e ) {
35+ # Check if this is an lmerMod object without broom.mixed
36+ if (
37+ inherits(fitlist [[1 ]], " lmerMod" ) &&
38+ grepl(" No.*tidy.*method" , e $ message , ignore.case = TRUE )
39+ ) {
40+ # Ensure lme4 is available (CRAN-compliant check)
41+ install.on.demand(" lme4" , ... )
42+ # Manual extraction for lmer objects using built-in methods
43+ lapply(fitlist , function (fit ) {
44+ coefs <- lme4 :: fixef(fit )
45+ se <- sqrt(diag(as.matrix(stats :: vcov(fit ))))
46+ data.frame (
47+ term = names(coefs ),
48+ estimate = as.numeric(coefs ),
49+ std.error = as.numeric(se ),
50+ stringsAsFactors = FALSE
51+ )
52+ }) %> %
53+ bind_rows()
54+ } else {
55+ # Re-throw the error if it's not an lmer issue
56+ stop(e )
57+ }
4758 }
48- } )
59+ )
4960 }
5061 if (type == " glance" ) {
5162 v <- lapply(fitlist , glance , ... ) %> % bind_rows()
@@ -54,8 +65,9 @@ summary.mira <- function(object,
5465 # not supplied by broom <= 0.5.6
5566 model <- getfit(object , 1L )
5667 if (! " nobs" %in% colnames(v )) {
57- v $ nobs <- tryCatch(length(stats :: residuals(model )),
58- error = function (e ) {NULL })
68+ v $ nobs <- tryCatch(length(stats :: residuals(model )), error = function (e ) {
69+ NULL
70+ })
5971 }
6072
6173 # get df.residuals
@@ -87,10 +99,12 @@ summary.mice.anova <- function(object, ...) {
8799
88100 # handle objects from D1, D2 and D3
89101 if (is.null(out )) {
90- out <- list (`1 ~~ 2` = list (
91- result = object $ result ,
92- dfcom = object $ dfcom
93- ))
102+ out <- list (
103+ `1 ~~ 2` = list (
104+ result = object $ result ,
105+ dfcom = object $ dfcom
106+ )
107+ )
94108 }
95109
96110 test <- names(out )
@@ -115,8 +129,11 @@ summary.mice.anova <- function(object, ...) {
115129
116130 structure(
117131 list (
118- models = ff , comparisons = rf ,
119- m = object $ m , method = object $ method , use = object $ use
132+ models = ff ,
133+ comparisons = rf ,
134+ m = object $ m ,
135+ method = object $ method ,
136+ use = object $ use
120137 ),
121138 class = c(" mice.anova.summary" , class(object ))
122139 )
0 commit comments