Learn R Programming

valueprhr (version 0.1.0)

fit_bayesian_glm_sectors: Fit Bayesian GLM for Each Sector

Description

Fits separate Bayesian generalized linear models for each sector, regressing production prices on direct prices.

Usage

fit_bayesian_glm_sectors(
  direct_prices,
  production_prices,
  chains = 4L,
  iter = 4000L,
  seed = 12345L,
  verbose = TRUE
)

Value

A list with two elements:

results

List of results for each sector

summary_table

Data frame with summary statistics for all sectors

Arguments

direct_prices

Data frame with direct prices. First column must be 'Year', remaining columns are sector values.

production_prices

Data frame with prices of production. Must have same structure as direct_prices.

chains

Number of MCMC chains. Default 4.

iter

Number of iterations per chain. Default 4000.

seed

Random seed for reproducibility. Default 12345.

verbose

Logical. Print progress messages. Default TRUE.

Details

This function requires the 'rstanarm' and 'loo' packages to be installed. Each sector model uses a Gaussian family with identity link and weakly informative priors.

Examples

Run this code
# \donttest{
if (requireNamespace("rstanarm", quietly = TRUE)) {
  set.seed(123)
  years <- 2000:2010

  direct <- data.frame(
    Year = years,
    Agriculture = 100 + cumsum(rnorm(11, 2, 1)),
    Manufacturing = 120 + cumsum(rnorm(11, 2, 1))
  )

  production <- data.frame(
    Year = years,
    Agriculture = 102 + cumsum(rnorm(11, 2, 1)),
    Manufacturing = 118 + cumsum(rnorm(11, 2, 1))
  )

  results <- fit_bayesian_glm_sectors(
    direct, production,
    chains = 2, iter = 1000
  )
  print(results$summary_table)
}
# }

Run the code above in your browser using DataLab