# \donttest{
##Data Generation
set.seed(123)
library(MASS)
m=30
x=runif(m,0,1)
b0=b1=0.5
u=rnorm(m,0,1)
Mu=exp(b0+b1*x+u)
theta=1
y=rnegbin(m,Mu,theta)
vardir=Mu+Mu^2/theta
dataNegativeBinomial=as.data.frame(cbind(y,x,vardir))
dataNegativeBinomialNs=dataNegativeBinomial
dataNegativeBinomialNs$y[c(3,14,22,29,30)] <- NA
dataNegativeBinomialNs$vardir[c(3,14,22,29,30)] <- NA
## Compute Fitted Model
## y ~ x
## For data without any nonsampled area
formula = y ~ x
v= c(1,1)
c= c(0,0)
dat = dataNegativeBinomial
## Using parameter coef and var.coef
saeHBNegbin <- NegativeBinomial(formula,coef=c,var.coef=v,iter.update=10,data =dat)
saeHBNegbin$Est #Small Area mean Estimates
saeHBNegbin$refVar #Random effect variance
saeHBNegbin$coefficient #coefficient
#Load Library 'coda' to execute the plot
#autocorr.plot(saeHBNegbin$plot[[3]]) is used to generate ACF Plot
#plot(saeHBNegbin$plot[[3]]) is used to generate Density and trace plot
## Do not using parameter coef and var.coef
saeHBNegbin <- NegativeBinomial(formula,data =dat)
## For data with nonsampled area use dataNegativeBinomialNs
# }
Run the code above in your browser using DataLab