library(zoib)
data("GasolineYield", package = "zoib")
#################################################
# fixed effects zoib with
# batch as a 10-level qualitative variable
################################################
eg.fixed <- zoib(yield ~ temp + as.factor(batch)| 1, data=GasolineYield,
joint = FALSE, random = 0, EUID = 1:nrow(d),
zero.inflation = FALSE, one.inflation = FALSE,
n.iter = 1100, n.thin = 5, n.burn=100)
# yieds 400 posterior draws (200 per chain) on the parameters of interest
# posterior draws of the regression coefficients
coeff <- mcmc(eg.fixed$coef)
traceplot(coeff)
autocorr.plot(coeff, lag.max=5)
check.psrf(coeff)
summ1 <- summary(coeff)
# Design Matrix: Xb, Xd, Xb0, Xb1
eg.fixed$Xb; eg.fixed$Xd; eg.fixed$Xb0; eg.fixed$Xb1
# Posterior predictive values of Y
ypred = rbind(eg.fixed$ypred[[1]],eg.fixed$ypred[[2]])
post.mean= apply(ypred,2,mean);
plot(GasolineYield$yield, post.mean, col='blue',pch=2);
abline(0,1,col='red')
######################################################
# mixed effects zoib with batch as a random variable
#####################################################
eg.random <- zoib(yield ~ temp | 1 | 1, data=GasolineYield,
joint = FALSE, random=1, EUID=GasolineYield$batch,
zero.inflation = FALSE, one.inflation = FALSE,
n.iter=3200, n.thin=15, n.burn=200)
# check convergence on the regression coefficients
sample2 <- eg.random$coeff
traceplot(sample2)
autocorr.plot(sample2)
check.psrf(coeff)
summary(mcmc(sample2))
# predicted y
ypred = rbind(eg.random$ypred[[1]],eg.random$ypred[[2]])
post.mean= apply(ypred,2,mean);
plot(GasolineYield$yield, post.mean, col='blue',pch=2);
abline(0,1,col='red')Run the code above in your browser using DataLab