Learn R Programming

valueprhr (version 0.1.0)

fit_bayesian_hierarchical: Fit Bayesian Hierarchical Panel Model

Description

Fits a Bayesian mixed effects model with random slopes by sector.

Usage

fit_bayesian_hierarchical(
  panel_data,
  include_time = TRUE,
  chains = 4L,
  iter = 4000L,
  seed = 12345L
)

Value

A list containing:

model

The fitted rstanarm model object

r2_bayes

Bayesian R-squared (mean)

summary

Model summary for fixed effects

metrics

In-sample evaluation metrics

Arguments

panel_data

Data frame in panel format.

include_time

Logical. Include time trend. Default TRUE.

chains

Number of MCMC chains. Default 4.

iter

Number of iterations. Default 4000.

seed

Random seed. Default 12345.

Examples

Run this code
if (FALSE) {
if (requireNamespace("rstanarm", quietly = TRUE)) {
  set.seed(123)
  panel <- data.frame(
    year = rep(2000:2009, 5),
    sector = rep(LETTERS[1:5], each = 10),
    time = rep(1:10, 5),
    log_direct = rnorm(50, 5, 0.5),
    log_production = rnorm(50, 5, 0.5)
  )
  panel$log_production <- panel$log_direct * 0.95 + rnorm(50, 0, 0.1)

  result <- fit_bayesian_hierarchical(panel, chains = 2, iter = 1000)
  print(result$r2_bayes)
}
}

Run the code above in your browser using DataLab