The “stan_betareg” Function in R

  • Package: rstanarm

  • Purpose: Fits a Bayesian beta regression model using Stan.

  • General class: Modeling

  • Required argument(s):

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

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

  • Notable optional arguments:

    • link: The link function to be used (e.g., “logit”, “probit”, “cloglog”).

    • prior: The prior distribution for the coefficients.

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

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

    • seed: An optional seed for reproducibility.

  • Example:

  • # Load the rstanarm library
    library(rstanarm)

    # Generate a sample dataset for beta regression
    set.seed(123)
    n <- 100
    x <- runif(n, 0, 10)
    y <- rbeta(n, shape1 = 2 + 0.5 * x, shape2 = 2)

    # Create a data frame
    data <- data.frame(y = y, x = x)

    # Fit a Bayesian beta regression model
    model <- stan_betareg(y ~ x, data = data, link = "logit")

    # Print model summary
    print(model)

  • This example demonstrates how to fit a Bayesian beta regression model using the stan_betareg function from the rstanarm package. The formula specifies the model structure, the data argument provides the dataset, and optional arguments like link, prior, chains, iter, and seed can be adjusted for customization.

Previous
Previous

The “kfold” Function in R

Next
Next

The “stan_polr” Function in R