coef.hmclearn: Extract Model Coefficients

Description Usage Arguments Value Examples

View source: R/methods.R

Description

Method for hmclearn objects created by mh and hmc functions. Extracts the specified quantile of the posterior.

Usage

1
2
## S3 method for class 'hmclearn'
coef(object, burnin = NULL, prob = 0.5, ...)

Arguments

object

an object of class hmclearn, usually a result of a call to mh or hmc

burnin

optional numeric parameter for the number of initial MCMC samples to omit from the summary

prob

quantile to extract coefficients

...

additional arguments to pass to quantile

Value

Numeric vector of parameter point estimates based on the given prob, with a default of the median estimate.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Linear regression example
set.seed(521)
X <- cbind(1, matrix(rnorm(300), ncol=3))
betavals <- c(0.5, -1, 2, -3)
y <- X%*%betavals + rnorm(100, sd=.2)

f1 <- hmc(N = 500,
          theta.init = c(rep(0, 4), 1),
          epsilon = 0.01,
          L = 10,
          logPOSTERIOR = linear_posterior,
          glogPOSTERIOR = g_linear_posterior,
          varnames = c(paste0("beta", 0:3), "log_sigma_sq"),
          param=list(y=y, X=X), parallel=FALSE, chains=1)

summary(f1)
coef(f1)

hmclearn documentation built on Oct. 23, 2020, 8:04 p.m.