Update glmmTMB models in parallel.
updateParallel.Rd
This function updates glmmTMB models in parallel using multiple cores, allowing for faster computation. It updates the models with new reference labels if specified. It can also be used to fit a new formula or to change additional parameters of glmmTMB (param : "...").
Arguments
- formula
Formula for the GLMNB model.
- list_tmb
List of glmmTMB objects.
- reference_labels
Vector of reference labels. Default is c(), selecting the first alphanumeric label as reference.
- n.cores
Number of cores to use for parallel processing. If NULL, the function will use all available cores.
- cl_type
cluster type (default "PSOCK"). "FORK" is recommended for linux.
- log_file
File path for the log output (default: Rtmpdir/htrfit.log).
- ...
Additional arguments to be passed to the glmmTMB::glmmTMB function.
Examples
# -- Example usage: update formula
data(iris)
groups <- unique(iris$Species)
group_by <- "Species"
formula <- Sepal.Length ~ Sepal.Width + Petal.Length
fitted_models <- fitModelParallel(formula, iris, group_by, n.cores = 1)
#> Log file location: /tmp/RtmpS86cq0/htrfit.log
#> CPU(s) number : 1
#> Cluster type : PSOCK
new_formula <- Sepal.Length ~ Sepal.Width
results <- updateParallel(new_formula, fitted_models, n.cores = 1)
#> Log file location: /tmp/RtmpS86cq0/htrfit.log
#> CPU(s) number : 1
#> Cluster type : PSOCK
# Example usage: update reference
# -- Load the mtcars dataset
data("mtcars")
# -- Specify categorical variables
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
list_tmb <- updateParallel(formula = mpg ~ hp + vs + am, list_tmb,
reference_labels = c("straight", "manual"), n.cores = 1)
#> Log file location: /tmp/RtmpS86cq0/htrfit.log
#> CPU(s) number : 1
#> Cluster type : PSOCK