Sample the linear regression parameters assuming a g-prior
Source:R/STAR_Bayesian.R
sample_lm_gprior.RdSample the parameters for a linear regression model assuming a g-prior for the coefficients.
Arguments
- y
n x 1vector of data- X
n x pmatrix of predictors- params
the named list of parameters containing
mu: vector of conditional means (fitted values)sigma: the conditional standard deviationcoefficients: a named list of parameters that determinemu
- psi
the prior variance for the g-prior
- XtX
the
p x pmatrix ofcrossprod(X)(one-time cost); if NULL, compute within the function- X_test
matrix of predictors at test points (default is NULL)
Value
The updated named list params with draws from the full conditional distributions
of sigma and coefficients (along with updated mu and mu_test if applicable).
Note
The parameters in coefficients are:
beta: thep x 1vector of regression coefficients components ofbeta
Examples
# Simulate data for illustration:
sim_dat = simulate_nb_lm(n = 100, p = 5)
y = sim_dat$y; X = sim_dat$X
# Initialize:
params = init_lm_gprior(y = y, X = X)
# Sample:
params = sample_lm_gprior(y = y, X = X, params = params)
names(params)
#> [1] "mu" "sigma" "coefficients"
names(params$coefficients)
#> [1] "beta"