## Not run:
# require(MASS)
# data(UScereal)
# UScereal$shelf = factor(UScereal$shelf, ordered=TRUE)
# UScereal$vitamins = factor(UScereal$vitamins, ordered=TRUE,
# levels=c("none", "enriched", "100%"))
# obj = bfa_copula(~., data=UScereal[,-1], num.factor=2, nsim=10000, nburn=1000, thin=4,
# rest=list(c("sugars", 2, "0")), loading.prior="gdp", keep.scores=T,
# print.status=2500)
# biplot(obj, cex=c(0.8, 0.8))
# plot(get_coda(obj))
# plot(get_coda(obj, loadings=F, scores=T))
# hpd.int = HPDinterval(obj, scores=T)
#
# #sample from posterior predictive
# ps = predict(obj)
#
# m=ggplot(UScereal, aes(x=calories, y=sugars))+geom_point(position='jitter', alpha=0.5)
# m=m+stat_density2d(data=ps, aes(x=calories, y=sugars, color = ..level..), geom='contour')
# print(m)
#
# m=ggplot(UScereal, aes(x=calories))+geom_histogram()
# m=m+stat_density(data=ps, aes(x=calories, y=..count..), color='red',fill=NA, adjust=1.3)
# m=m+facet_grid(shelf~.)
# print(m)
#
# #we can compute conditional dist'n estimates directly as well by supplying cond.vars
# cond.vars=list(shelf=1)
# out = predict(obj, resp.var="calories", cond.vars=cond.vars)
# plot(sort(unique(UScereal$calories)), apply(out, 2,mean), type='s')
# lines(sort(unique(UScereal$calories)), apply(out, 2, quantile, 0.05), type='s', lty=2)
# lines(sort(unique(UScereal$calories)), apply(out, 2,quantile, 0.95), type='s', lt=2)
# lines(ecdf(UScereal$calories[UScereal$shelf==1]), col='blue')
# text(400, 0.1, paste("n =", sum(UScereal$shelf==1)))
#
# out2 = predict(obj, resp.var="calories", cond.vars=list(shelf=2))
# out3 = predict(obj, resp.var="calories", cond.vars=list(shelf=3))
# plot(sort(unique(UScereal$calories)), apply(out, 2,mean), type='s')
# lines(sort(unique(UScereal$calories)), apply(out2, 2,mean), type='s', lty=2)
# lines(sort(unique(UScereal$calories)), apply(out3, 2,mean), type='s', lty=3)
# ## End(Not run)
Run the code above in your browser using DataLab