Skip to content
Snippets Groups Projects
updateParallel.Rd 2.38 KiB
Newer Older
Arnaud Duvermy's avatar
Arnaud Duvermy committed
% Generated by roxygen2: do not edit by hand
Arnaud Duvermy's avatar
Arnaud Duvermy committed
% Please edit documentation in R/update_fittedmodel.R
Arnaud Duvermy's avatar
Arnaud Duvermy committed
\name{updateParallel}
\alias{updateParallel}
Arnaud Duvermy's avatar
Arnaud Duvermy committed
\title{Update glmmTMB models in parallel.}
Arnaud Duvermy's avatar
Arnaud Duvermy committed
\usage{
updateParallel(
  formula,
  list_tmb,
Arnaud Duvermy's avatar
Arnaud Duvermy committed
  reference_labels = c(),
  n.cores = NULL,
  log_file = paste(tempdir(check = FALSE), "htrfit.log", sep = "/"),
  ...
)
Arnaud Duvermy's avatar
Arnaud Duvermy committed
}
\arguments{
\item{formula}{Formula for the GLMNB model.}

Arnaud Duvermy's avatar
Arnaud Duvermy committed
\item{list_tmb}{List of glmmTMB objects.}
Arnaud Duvermy's avatar
Arnaud Duvermy committed

Arnaud Duvermy's avatar
Arnaud Duvermy committed
\item{reference_labels}{Vector of reference labels. Default is c(), selecting the first alphanumeric label as reference.}

Arnaud Duvermy's avatar
Arnaud Duvermy committed
\item{n.cores}{Number of cores to use for parallel processing. If NULL, the function will use all available cores.}

Arnaud Duvermy's avatar
Arnaud Duvermy committed
\item{cl_type}{cluster type (default "PSOCK"). "FORK" is recommended for linux.}
\item{log_file}{File path for the log output (default: Rtmpdir/htrfit.log).}
Arnaud Duvermy's avatar
Arnaud Duvermy committed

\item{...}{Additional arguments to be passed to the glmmTMB::glmmTMB function.}
}
\value{
A list of updated GLMNB models.
}
\description{
Arnaud Duvermy's avatar
Arnaud Duvermy committed
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 : "...").
Arnaud Duvermy's avatar
Arnaud Duvermy committed
}
\examples{
Arnaud Duvermy's avatar
Arnaud Duvermy committed
# -- Example usage: update formula
Arnaud Duvermy's avatar
Arnaud Duvermy committed
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)
new_formula <- Sepal.Length ~ Sepal.Width 
results <- updateParallel(new_formula, fitted_models, n.cores = 1)
Arnaud Duvermy's avatar
Arnaud Duvermy committed
# 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)
# -- Relevel transmission and engine shape variables
list_tmb <- updateParallel(formula = mpg ~ hp + vs + am, list_tmb,
                  reference_labels = c("straight", "manual"), n.cores = 1)
Arnaud Duvermy's avatar
Arnaud Duvermy committed
}