knitr::opts_chunk$set(echo = TRUE, collapse = TRUE) library(ipriorBVS) library(rjags) load.module("lecuyer") runjags::runjags.options( silent.runjags = TRUE, silent.jags = FALSE, summary.warning = FALSE, rng.warning = FALSE )
Bayesian variable selection for linear models using I-priors in R. This work is part of the PhD project entitled Regression Modelling with Priors using Fisher Information Covariance Kernels (I-priors). Visit http://phd.haziqj.ml for details.
A toy data set designed by Tibshirani (1996), often used to compare variable selection methods.
n = 50
data points are generated from a linear model with parameters beta = c(3, 1.5, 0, 0, 2, 0, 0, 0)
and sigma = 3
.
The X
are generated from a normal distribution with mean zero, and the correlation between the i
th and j
th variable is 0.5 ^ abs(i - j)
.
This is implemented in the gen_benchmark()
function included in the package.
(dat <- gen_benchmark(n = 50, sd = 3, seed = 123))
The model fitted either using formula or non-formula syntax. We are then able to obtain posterior inclusion probabilities (PIPs) for the each variable, and also posterior model probabilities (PMPs). For comparison, Bayes factors and deviances are reported as well.
runjags::runjags.options(silent.jags = TRUE, silent.runjags = TRUE) (mod <- ipriorBVS(y ~ ., dat))
The model coefficients are averaged across all probable sub-models, which yields a kind of "model-averaged" coefficients.
coef(mod)
Copyright (C) 2017 Haziq Jamil.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.