From: Sarah J Thomas <sarah.thomas_at_rice.edu>

Date: Mon, 18 Feb 2008 00:50:21 -0600

Y <- rep(0, 100)

Date: Mon, 18 Feb 2008 00:50:21 -0600

I construct a zero-inflated series of counts, called Y, like so:

b= as.vector(c(1.5, -2))

g= as.vector(c(-3, 1))

x <- runif(100) # x is the covariate

X <- cbind(1,x)

p <- exp(X%*%g)/(1+exp(X%*%g))

m <- exp(X%*%b) # log-link for the mean process

# of the Poisson

Y <- rep(0, 100)

u <- runif(100)

for(i in 1:100) {

if( u[i] < p[i] ) { Y[i] = 0 }

else { Y[i] <- rpois(1, m[i]) }

}

# now let's compare the fitted.values from zeroinfl()

# and from glm()

z1 <- glm(Y ~ x, family=poisson)

z2 <- zeroinfl(Y ~ x|x) #poisson is the default

z1$fitted.values[1:20]

#1.3254209 0.7458029 2.0300505 1.1292954 1.4512862 #0.6513798 1.8980126

0.6558228 1.5302057

#0.6993626 2.6875736 0.7586985 2.0622238 2.1009979 #1.4254607 1.8130159

3.6603137 2.1330030

#2.9409379 3.3203350

z2$fitted.values[1:20]

#1.3587457 0.7254296 2.0730982 1.1497492 1.4902778 #0.6178648 1.9429778

0.6229478 1.5717923

#0.6726527 2.7010395 0.7400369 2.1045779 2.1424025 #1.4634459 1.8583877

3.5830697 2.1735319

#2.9354839 3.2800839

many thanks,

Sarah Thomas

-- Sarah J. Thomas Research Assistant, Department of Statistics Rice University, Houston, TX ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.Received on Mon 18 Feb 2008 - 06:55:54 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Mon 18 Feb 2008 - 14:00:15 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*