Reputation: 53
I have an example data frame as follows.
data.df = data.frame(Y=c(0,0,0,0,0,0,0,0,0,0,1,2,3),X1=c(3,5,3,2,5,6,3,5,1,3,1,7,8),X2=c(6,2,1,6,7,1,1,4,2,6,7,2,3))
To create and update the Poisson model I would do the following
model.poi = glm(Y~X1+X2,data=data.df,family="poisson")
summary(model.poi)
model.poi.2 = update(model.poi,~. -X2)
summary(model.poi.2)
I can create a Zero Inflated Poisson model by doing the following
require(pscl)
model.zip = zeroinfl(Y~X1+X2|X1+X2,data=data.df,dist="poisson")
summary(model.zip)
How would I go about updating the zero inflated model in the same manner as the Poisson glm?
Upvotes: 5
Views: 1263
Reputation: 270195
There is no update
method for the "zeroinfl"
class but we can define one:
library(Formula)
update.zeroinfl <- function(object, new, ...) {
call <- object$call
call$formula <- update(as.Formula(formula(object)), new)
eval.parent(call)
}
Now we test it out:
> update(model.zip, . ~ . - X2 | . - X2)
Call:
zeroinfl(formula = Y ~ X1 | X1, data = data.df, dist = "poisson")
Count model coefficients (poisson with log link):
(Intercept) X1
-4.0538 0.6139
Zero-inflation model coefficients (binomial with logit link):
(Intercept) X1
-6.50595 -0.06057
Upvotes: 4