sjPlot icon indicating copy to clipboard operation
sjPlot copied to clipboard

tab_model() always displays conditional average from MuMIn object

Open tsievert opened this issue 4 years ago • 1 comments

Hey,

I noticed that when a MuMIn object is passed to tab_model(), the resulting table always displays the conditional averages. Am I missing an option to display the full average instead or does it not exist?

Cheers, Thorbjörn

library(lme4)
#> Lade nötiges Paket: Matrix
library(MuMIn)
library(sjPlot)


test.data <- structure(list(mother = c(86L, 76L, 252L, 2434L, 2003L, 2151L,285L, 116L, 36L, 62L), father = c("2087", "0300", "2438", "2123","0122", "2592", "2095", "0101", "2239", "2966"), pup_ID = c("mum","mum", "mum", "mum", "mum", "mum", "mum", "mum", "mum", "mum"), litter_size = c(5L, 6L, 2L, 5L, 4L, 4L, 5L, 5L, 4L, 4L), treatment = structure(c(2L,2L, 2L, 2L, 3L, 1L, 2L, 3L, 2L, 3L), .Label = c("C", "AP", "PO"), class = "factor"), timing = c("late", "late", "late", "late","late", "late", "early", "late", "early", "early"), day = c(0L,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(6L, 61L,131L, 158L, 218L, 268L, 318L, 1545L, 1597L, 1642L), class = "data.frame") 

test.1<-glm(litter_size ~ treatment*timing, family=poisson(link = "log"), data=test.data)
test.2<-glm(litter_size ~ treatment+timing, family=poisson(link = "log"), data=test.data)
test.3<-glm(litter_size ~ timing, family=poisson(link = "log"), data=test.data)
test.4<-glm(litter_size ~ treatment, family=poisson(link = "log"), data=test.data)

model.avg(test.4, test.3)
#> 
#> Call:
#> model.avg(object = test.4, test.3)
#> 
#> Component models: 
#> '1' '2'
#> 
#> Coefficients: 
#>        (Intercept) timinglate treatmentAP treatmentPO
#> full      1.457744 0.01940595  0.01264538 0.008593515
#> subset    1.457744 0.02173999  0.11778304 0.080042708

tab_model(model.avg(test.4, test.3), transform = NULL, show.df = F, show.stat = F, p.adjust = T)
#> 'r2()' does not support models of class 'averaging'.

 

litter_size

Predictors

Log-Mean

CI

p

(Intercept)

1.46

0.74 – 2.18

<0.001

timing [late]

0.02

-0.74 – 0.78

0.955

treatment [AP]

0.12

-1.15 – 1.38

0.855

treatment [PO]

0.08

-1.27 – 1.43

0.908

Observations

10

Created on 2020-10-07 by the reprex package (v0.3.0)

tsievert avatar Oct 07 '20 10:10 tsievert

You can do this with the parameters package, and select the required component via component, see example below. However, the functionality to print to HTML is currently only available after installing insight and parameters from GitHub, updates of those packages will hopefully appear on CRAN in 2-3 weeks.

I'll see if I can directly include this in tab_model().

library(lme4)
#> Loading required package: Matrix
library(MuMIn)
library(parameters)

test.data <- structure(list(mother = c(86L, 76L, 252L, 2434L, 2003L, 2151L,285L, 116L, 36L, 62L), father = c("2087", "0300", "2438", "2123","0122", "2592", "2095", "0101", "2239", "2966"), pup_ID = c("mum","mum", "mum", "mum", "mum", "mum", "mum", "mum", "mum", "mum"), litter_size = c(5L, 6L, 2L, 5L, 4L, 4L, 5L, 5L, 4L, 4L), treatment = structure(c(2L,2L, 2L, 2L, 3L, 1L, 2L, 3L, 2L, 3L), .Label = c("C", "AP", "PO"), class = "factor"), timing = c("late", "late", "late", "late","late", "late", "early", "late", "early", "early"), day = c(0L,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), row.names = c(6L, 61L,131L, 158L, 218L, 268L, 318L, 1545L, 1597L, 1642L), class = "data.frame") 

test.1<-glm(litter_size ~ treatment*timing, family=poisson(link = "log"), data=test.data)
test.2<-glm(litter_size ~ treatment+timing, family=poisson(link = "log"), data=test.data)
test.3<-glm(litter_size ~ timing, family=poisson(link = "log"), data=test.data)
test.4<-glm(litter_size ~ treatment, family=poisson(link = "log"), data=test.data)

model.avg(test.4, test.3)
#> 
#> Call:
#> model.avg(object = test.4, test.3)
#> 
#> Component models: 
#> '1' '2'
#> 
#> Coefficients: 
#>        (Intercept) timinglate treatmentAP treatmentPO
#> full      1.457744 0.01940595  0.01264538 0.008593515
#> subset    1.457744 0.02173999  0.11778304 0.080042708

model_parameters(model.avg(test.4, test.3), component = "conditional", digits = 3)
#> Parameter      | Log-Mean |    SE |        95% CI |     z |      p
#> ------------------------------------------------------------------
#> (Intercept)    |    1.458 | 0.367 | [ 0.74, 2.18] | 3.971 | < .001
#> timing [late]  |    0.022 | 0.389 | [-0.74, 0.78] | 0.056 | 0.955 
#> treatment [AP] |    0.118 | 0.646 | [-1.15, 1.38] | 0.182 | 0.855 
#> treatment [PO] |    0.080 | 0.690 | [-1.27, 1.43] | 0.116 | 0.908
model_parameters(model.avg(test.4, test.3), component = "full", digits = 3)
#> Parameter      | Log-Mean |    SE |        95% CI |     z |      p
#> ------------------------------------------------------------------
#> (Intercept)    |    1.458 | 0.367 | [ 0.74, 2.18] | 3.971 | < .001
#> timing [late]  |    0.019 | 0.367 | [-0.70, 0.74] | 0.053 | 0.958 
#> treatment [AP] |    0.013 | 0.215 | [-0.41, 0.43] | 0.059 | 0.953 
#> treatment [PO] |    0.009 | 0.227 | [-0.44, 0.45] | 0.038 | 0.970

mp <- model_parameters(model.avg(test.4, test.3), component = "conditional", digits = 3)

print_md(mp)
Parameter Log-Mean SE 95% CI z p
(Intercept) 1.458 0.367 (0.74, 2.18) 3.971 < .001
timing (late) 0.022 0.389 (-0.74, 0.78) 0.056 0.955
treatment (AP) 0.118 0.646 (-1.15, 1.38) 0.182 0.855
treatment (PO) 0.080 0.690 (-1.27, 1.43) 0.116 0.908

print_html(mp)

Regression Model

Parameter

Coefficient

SE

95% CI

z

p

(Intercept)

1.458

0.367

(0.74, 2.18)

3.971

< .001

timing (late)

0.022

0.389

(-0.74, 0.78)

0.056

0.955

treatment (AP)

0.118

0.646

(-1.15, 1.38)

0.182

0.855

treatment (PO)

0.080

0.690

(-1.27, 1.43)

0.116

0.908

Created on 2021-01-10 by the reprex package (v0.3.0)

strengejacke avatar Jan 10 '21 12:01 strengejacke