
Last chance! 50% off unlimited learning
Sale ends in
MCMC sampling for Bayesian linear regression with a (known or unknown) Box-Cox transformation. A g-prior is assumed for the regression coefficients.
blm_bc(
y,
X,
X_test = X,
psi = length(y),
lambda = NULL,
sample_lambda = TRUE,
nsave = 1000,
nburn = 1000,
nskip = 0,
verbose = TRUE
)
a list with the following elements:
coefficients
the posterior mean of the regression coefficients
fitted.values
the posterior predictive mean at the test points X_test
post_theta
: nsave x p
samples from the posterior distribution
of the regression coefficients
post_ypred
: nsave x n_test
samples
from the posterior predictive distribution at test points X_test
post_g
: nsave
posterior samples of the transformation
evaluated at the unique y
values
post_lambda
nsave
posterior samples of lambda
post_sigma
nsave
posterior samples of sigma
model
: the model fit (here, blm_bc
)
as well as the arguments passed in.
n x 1
vector of observed counts
n x p
matrix of predictors
n_test x p
matrix of predictors for test data;
default is the observed covariates X
prior variance (g-prior)
Box-Cox transformation; if NULL, estimate this parameter
logical; if TRUE, sample lambda, otherwise use the fixed value of lambda above or the MLE (if lambda unspecified)
number of MCMC iterations to save
number of MCMC iterations to discard
number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw
logical; if TRUE, print time remaining
This function provides fully Bayesian inference for a
transformed linear model via MCMC sampling. The transformation is
parametric from the Box-Cox family, which has one parameter lambda
.
That parameter may be fixed in advanced or learned from the data.
# Simulate some data:
dat = simulate_tlm(n = 100, p = 5, g_type = 'step')
y = dat$y; X = dat$X # training data
y_test = dat$y_test; X_test = dat$X_test # testing data
hist(y, breaks = 25) # marginal distribution
# Fit the Bayesian linear model with a Box-Cox transformation:
fit = blm_bc(y = y, X = X, X_test = X_test)
names(fit) # what is returned
round(quantile(fit$post_lambda), 3) # summary of unknown Box-Cox parameter
Run the code above in your browser using DataLab