Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_varcomp() #2

Open
3 tasks
SchmidtPaul opened this issue Feb 3, 2023 · 1 comment
Open
3 tasks

Add get_varcomp() #2

SchmidtPaul opened this issue Feb 3, 2023 · 1 comment
Assignees

Comments

@SchmidtPaul
Copy link
Owner

SchmidtPaul commented Feb 3, 2023

Base on this:

get_vc <- function(model) {
  model %>%
    VarCorr() %>%
    as_tibble() %>%
    setNames(c('group', 'effect', 'eff_2', 'var', 'sd')) %>%
    mutate(
      var_prop = var / sum(var),
      var_p = case_when(
        var_prop < 0.000001 ~ "   0%",
        TRUE ~ percent(var_prop, accuracy = 0.1, trim = FALSE)
      ),
      effect   = gsub(effect, pattern = '[\\(,\\)]', replacement = ''),
      effect   = ifelse(is.na(effect), '', effect)
    ) %>%
    select(group, var, var_p, sd, effect, everything())
}
  • which model classes are supported?
  • optional German?
  • optional print-ready version?
@SchmidtPaul SchmidtPaul self-assigned this Feb 3, 2023
@SchmidtPaul SchmidtPaul reopened this Mar 15, 2023
@SchmidtPaul
Copy link
Owner Author

library(BioMathR)
library(glmmTMB)
library(lme4)
library(lmerTest)

m1 <- lmer(mpg ~ cyl + am + (1 | carb) + (1 | gear:carb), data = mtcars)

VarCorr(m1)
#>  Groups    Name        Std.Dev.
#>  gear:carb (Intercept) 0.90804 
#>  carb      (Intercept) 0.93346 
#>  Residual              2.82878
get_varcomp(m1)
#> # A tibble: 3 × 7
#>   group     effect      var var_p   var_prop    sd effect_2
#>   <chr>     <chr>     <dbl> <chr>      <dbl> <dbl> <chr>   
#> 1 gear:carb Intercept 0.825 " 8.5%"    0.085 0.908 <NA>    
#> 2 carb      Intercept 0.871 " 9.0%"    0.09  0.933 <NA>    
#> 3 Residual  <NA>      8.00  "82.5%"    0.825 2.83  <NA>


m2 <- glmmTMB(mpg ~ cyl + am + (1 | carb) + (1 | gear:carb), REML = TRUE, data = mtcars)
#> Warning in .local(x, logarithm, ...): the default value of argument 'sqrt' of
#> method 'determinant(<CHMfactor>, <logical>)' may change from TRUE to FALSE as
#> soon as the next release of Matrix; set 'sqrt' when programming

VarCorr(m2)
#> 
#> Conditional model:
#>  Groups    Name        Std.Dev.
#>  carb      (Intercept) 0.93344 
#>  gear:carb (Intercept) 0.90806 
#>  Residual              2.82878
get_varcomp(m2)
# ?!

Created on 2023-07-21 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant