# fit the fineroot data with Bayesian models
# first use the latent variable approach
set.seed(10)
fit1 <- bcpglm(RLD~ factor(Zone)*factor(Stock), data=fineroot,
n.iter=11000, n.burnin=1000,
n.thin=10, n.report=5000, method="latent")
gelman.diag(fit1$sims.list)
# diagnostic plots
acfplot(fit1$sims.list,lag.max=20)
xyplot(fit1$sims.list)
densityplot(fit1$sims.list)
# summary results
summary(fit1)
# now try direct density evaluation (This is much slower)
set.seed(10)
fit2 <- bcpglm(RLD~ factor(Zone)*factor(Stock), data=fineroot,
n.iter=11000, n.burnin=1000,
n.thin=10, n.report=5000)
gelman.diag(fit2$sims.list)
summary(fit2)
# now fit the Bayesian model to an insurance loss triangle
# (see Peters et al. 2009)
# MLE estimate
fit3 <- cpglm(increLoss~ factor(year)+factor(lag), data=insLoss)
fit4 <- mcmcsamp(fit3, tune.iter=5000, n.tune = 10,
n.iter=11000, n.burnin=1000,
n.thin=10, n.report=5000, bound.p=c(1.1,1.95))
gelman.diag(fit4$sims.list)
summary(fit4)
# mixed models
set.seed(10)
fit5 <- bcpglmm(RLD~Zone*Stock+(1|Plant), data = fineroot,
n.chains=3, n.iter=25000, n.burnin=5000,
n.sims=2000, n.report=5000)
gelman.diag(fit5$sims.list)
summary(fit5)
# now change the prior distribution for the random component
fit6 <- bcpglmm(RLD~Zone*Stock+(1|Plant), data = fineroot,
n.chains=3, n.iter=25000, n.burnin=5000,
n.sims=2000, n.report=5000, tune.iter=6000, n.tune=20,
prior.Sigma = list(igamma(scale=0.01,shape=0.01)))
summary(fit6)
# now use latent variables and mcmcsamp
fit7 <- cpglmm(RLD~Zone*Stock+(1|Plant), data = fineroot)
fit8 <- mcmcsamp(fit7, n.chains=3, n.iter=25000, n.burnin=5000,
n.sims=2000, n.report=5000, tune.iter=6000, n.tune=20,
prior.Sigma = list(igamma(scale=0.01,shape=0.01)),
method = "latent")
summary(fit8)
Run the code above in your browser using DataLab