# \donttest{
# Simulate data from a transformed (sparse) linear model:
dat = simulate_tlm(n = 100, p = 5, g_type = 'beta')
y = dat$y; X = dat$X
hist(y, breaks = 25) # marginal distribution
# Package for conveniently computing all subsets:
library(plyr)
# Fit the semiparametric Bayesian linear model with model selection:
fit = sblm_modelsel(y = y, X = X)
names(fit) # what is returned
# Summarize the probabilities of each model (by size):
plot(rowSums(fit$all_models), fit$post_probs,
xlab = 'Model sizes', ylab = 'p(model | data)',
main = 'Posterior model probabilities', pch = 2, ylim = c(0,1))
# Highest probability model:
hpm = which.max(fit$post_probs)
fit$post_probs[hpm] # probability
which(fit$all_models[hpm,]) # which variables
which(dat$beta_true != 0) # ground truth
# }
Run the code above in your browser using DataLab