*Laura Lee* laura.lee at ncdenr.gov <mailto:r-help%40r-project.org?Subject=Re%3A%20%5BR%5D%20Predicted%20values%20for%20zero-inflated%20Poisson&In-Reply-To=%3C1341937636301-4636016.post%40n4.nabble.com%3E> /Tue Jul 10 18:27:16 CEST 2012/
------------------------------------------------------------------------ I want to predict the number of turtles for different levels of effort and combinations of covariates. So, for my dataset from which I built the model, would I compare sum(predict(ZIP,type="response")) to the observed bycatch to compare numbers? In order to predict for the new data (called effort), would I use sum(predict(ZIP,newdata=effort,type="response"))? I want to be certain I am understanding the coding--this is my first time using the predict function. Thanks, Laura Laura Why do you use the sum? If you use: PredY <- predict(ZIP, type = "response") then you have predicted values for each of the rows in your effort data frame. Job done. You have an offset in your model, isn't it? You will need to choose values for this in the data frame effort as well. Also double check that the offset is only in the count part....at least that is what I would do. Note that using an offset means that you assume that if sampling effort is doubled, your fish (?) numbers double. If you fully want to understand what predict is doing, try to do it manually. Below is R code from Chapter 7 (Zero Inflation and GLMM with R) M3 <- zeroinfl(ParrotFish ~ Depth + Slope + SQDistRck + DistSed + Swell + Chla + SST, dist = "poisson", link = "logit", data = PF2) Betas.logistic <- coef(M3, model = "zero") X.logistic <- model.matrix(M3, model = "zero") eta.logistic <- X.logistic %*% Betas.logistic p <- exp(eta.logistic) / (1 + exp(eta.logistic)) Betas.log <- coef(M3, model = "count") X.log <- model.matrix(M3, model = "count") eta.log <- X.log %*% Betas.log mu <- exp(eta.log) ExpY <- mu * (1 - p) VarY <- (1 - p) * (mu + p * mu^2) Instead of using model.matrix(M3), you could specify your own data frame with covariates. Your effort. Something like: M4 <- zeroinfl(ParrotFish ~ Depth + Slope | SST, dist = "poisson", link = "logit", data = PF2) betapois <- coef(M4, model = "count") betaBin <- coef(M4, model = "zero") MyDataPois <- data.frame(Depth = blah blah, Slope = Blah blah) MyDataBin <- data.frame(SST = blah) Xpois <- model.matrix(~ blah blah, data = MyDataPois) Xbin <- model.matrix(~ blah blah, data = MyDataBin) eta.Pois <- Xpois %*% betapois eta.Bin <- blah blah mu = blah blah pi = blah blah ExpY = ... Doing it like this means you fully understand it..:-) Alain -- Dr. Alain F. Zuur First author of: 1. Analysing Ecological Data (2007). Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p. URL: www.springer.com/0-387-45967-7 2. Mixed effects models and extensions in ecology with R. (2009). Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer. http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9 3. A Beginner's Guide to R (2009). Zuur, AF, Ieno, EN, Meesters, EHWG. Springer http://www.springer.com/statistics/computational/book/978-0-387-93836-3 4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno. http://www.highstat.com/book4.htm Other books: http://www.highstat.com/books.htm Statistical consultancy, courses, data analysis and software Highland Statistics Ltd. 6 Laverock road UK - AB41 6FN Newburgh Tel: 0044 1358 788177 Email: highs...@highstat.com URL: www.highstat.com URL: www.brodgar.com [[alternative HTML version deleted]] ______________________________________________ R-help@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.