Re-levels categorical variables in a the frame of a list of glmmTMB objects.
relevel_list_tmb_frame.Rd
This function re-levels categorical variables in a list of glmmTMB objects using the specified reference labels.
Arguments
- list_tmb
List of glmmTMB objects.
- categorical_vars
Names of the categorical variables to be re-leveled.
- ref_labels
Vector of reference labels corresponding to the categorical variables.
Examples
# Example usage:
# -- Load the mtcars dataset
data("mtcars")
## -- specify categorical var
mtcars$vs <- factor(mtcars$vs) ## Engine (0 = V-shaped, 1 = straight)
levels(mtcars$vs) <- c("V-shaped", "straight")
mtcars$am <- factor(mtcars$am) ## Transmission (0 = automatic, 1 = manual)
levels(mtcars$am) <- c("automatic", "manual")
# -- For each group of number of cylinders,
# -- Explain fuel consumption with engine shape, Gross horsepower, and transmission type
list_tmb <- fitModelParallel(formula = mpg ~ hp + vs + am,
data = mtcars, group_by = "cyl", n.cores = 1)
#> Log file location: /tmp/RtmpS86cq0/htrfit.log
#> CPU(s) number : 1
#> Cluster type : PSOCK
# -- Relevel transmission and engine shape variables
relevel_list_tmb_frame(list_tmb, c("am", "vs"), c("manual", "straight"))
#> $`6`
#> Formula: mpg ~ hp + vs + am
#> Data: data
#> AIC BIC logLik df.resid
#> 28.46985 28.25349 -10.23492 3
#>
#> Number of obs: 7
#>
#> Dispersion estimate for gaussian family (sigma^2): 1.09
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) hp vsstraight ammanual
#> 23.46038 -0.02198 -1.80247 NA
#>
#> $`4`
#> Formula: mpg ~ hp + vs + am
#> Data: data
#> AIC BIC logLik df.resid
#> 64.87146 66.86093 -27.43573 6
#>
#> Number of obs: 11
#>
#> Dispersion estimate for gaussian family (sigma^2): 8.59
#>
#> Fixed Effects:
#>
#> Conditional model:
#> (Intercept) hp vsstraight ammanual
#> 30.3509 -0.1033 1.2943 5.0484
#>
#> $`8`
#> NULL
#>