# \donttest{
# Simulate data with count-valued response y:
sim_dat = simulate_nb_friedman(n = 100, p = 10)
y = sim_dat$y; X = sim_dat$X
# BART-STAR with log-transformation:
fit_log = bart_star(y = y, X = X, transformation = 'log',
save_y_hat = TRUE, nburn=1000, nskip=0)
# Fitted values
plot_fitted(y = sim_dat$Ey,
post_y = fit_log$post.fitted.values,
main = 'Fitted Values: BART-STAR-log')
# WAIC for BART-STAR-log:
fit_log$WAIC
# MCMC diagnostics:
plot(as.ts(fit_log$post.fitted.values[,1:10]))
# Posterior predictive check:
hist(apply(fit_log$post.pred, 1,
function(x) mean(x==0)), main = 'Proportion of Zeros', xlab='');
abline(v = mean(y==0), lwd=4, col ='blue')
# BART-STAR with nonparametric transformation:
fit = bart_star(y = y, X = X,
transformation = 'np', save_y_hat = TRUE)
# Fitted values
plot_fitted(y = sim_dat$Ey,
post_y = fit$post.fitted.values,
main = 'Fitted Values: BART-STAR-np')
# WAIC for BART-STAR-np:
fit$WAIC
# MCMC diagnostics:
plot(as.ts(fit$post.fitted.values[,1:10]))
# Posterior predictive check:
hist(apply(fit$post.pred, 1,
function(x) mean(x==0)), main = 'Proportion of Zeros', xlab='');
abline(v = mean(y==0), lwd=4, col ='blue')
# }
Run the code above in your browser using DataLab