Learn R Programming

SDGLM (version 0.4.0)

compute_metrics: Posterior-Predictive Metrics for Sca-MCMC Fit

Description

Computes R2, RMSE, AIC and BIC after discarding the first 50 as burn-in. Predictive expectations are obtained by plugging the posterior mean coefficients into the appropriate inverse-link function.

Usage

compute_metrics(fit, y, X)

Value

A data.frame with columns: R2, RMSE, AIC, BIC.

Arguments

fit

Object returned by `sca_mcmc` (must contain `beta_chain` and `family`).

y

Observed response vector (length n).

X

n x p design matrix used for the fit.

Examples

Run this code
set.seed(123)
X <- matrix(rnorm(100 * 3), 100, 3)
beta <- c(0.5, -0.2, 0.1)
y <- rgamma(100, shape = 2, rate = exp(X %*% beta))
fit <- sca_mcmc(y, X, family = "gamma", method = "ScaII", iter = 1000)
vals <- compute_metrics(fit, y, X)
print(vals)

Run the code above in your browser using DataLab