sample_params_lm: Sample the parameters for a linear regression

View source: R/source_MCMC.R

sample_params_lmR Documentation

Sample the parameters for a linear regression

Description

Sample the parameters for a linear regression model assuming a ridge prior for the (non-intercept) coefficients. The number of predictors p may exceed the number of observations n.

Usage

sample_params_lm(y, X, params, A = 10^4, XtX = NULL)

Arguments

y

n x 1 vector of data

X

n x p matrix of predictors

params

the named list of parameters containing

  1. mu: vector of conditional means (fitted values)

  2. sigma: the conditional standard deviation

  3. coefficients: a named list of parameters that determine mu

A

the prior scale for sigma_beta, which we assume follows a Uniform(0, A) prior.

XtX

the p x p matrix of crossprod(X) (one-time cost); if NULL, compute within the function

Value

The updated named list params with draws from the full conditional distributions of sigma and coefficients (and updated mu).

Note

The parameters in coefficients are:

  • beta: the p x 1 vector of regression coefficients

  • sigma_beta: the prior standard deviation for the (non-intercept) components of beta

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_params_lm(y = y, X = X)

# Sample:
params = sample_params_lm(y = y, X = X, params = params)
names(params)
names(params$coefficients)


drkowal/rSTAR documentation built on July 5, 2023, 2:18 p.m.