The “stan_glmer” Function in R

  • Package: rstanarm

  • Purpose: Fits a Bayesian generalized linear mixed-effects model using Stan.

  • General class: Modeling

  • Required argument(s):

    • formula: The model formula specifying the response variable and predictors.

    • data: The data frame containing the variables in the formula.

  • Notable optional arguments:

    • family: The family of the response variable distribution (e.g., gaussian, binomial, poisson).

    • chains: The number of Markov chains to run (default is 4).

    • iter: The number of iterations for each chain (default is 2,000).

    • cores: The number of CPU cores to use for parallel computing.

  • Example:

  • # Load the rstanarm library
    library(rstanarm)

    # Fit a Bayesian generalized linear mixed-effects model
    model <- stan_glmer(Sepal.Length ~ Sepal.Width + (1 | Species), data = iris, family = gaussian(link = "identity"))

    # Print model summary
    summary(model)

  • This example demonstrates how to fit a Bayesian generalized linear mixed-effects model using the stan_glmer function from the rstanarm package. The formula specifies the model structure, the data argument provides the dataset, and optional arguments like family, chains, iter, and cores can be adjusted for customization.

Previous
Previous

The “stan_polr” Function in R

Next
Next

The “stan_lmer” Function in R