Skip to content
Prev 6422 / 7420 Next

Predict on zero-inflated model using design matrix and parameter coefficients

Laura,

Depending on how you implement the ZIP model, the approach might be
slightly different. Using the pscl package you can do this:

r$> library(pscl)

r$> m <- zeroinfl(art ~ . | 1, data = bioChemists)

r$> cf0 <- coef(m, "zero")

r$> cf0
(Intercept)
  -1.681349

r$> cf1 <- coef(m, "count")

r$> cf1
 (Intercept)     femWomen   marMarried         kid5          phd
ment
 0.553995385 -0.231609021  0.131971507 -0.170473908  0.002525835
 0.021542720

r$> X0 <- model.matrix(m, "zero")

r$> head(X0)
  (Intercept)
1           1
2           1
3           1
4           1
5           1
6           1

r$> X1 <- model.matrix(m, "count")

r$> head(X1)
  (Intercept) femWomen marMarried kid5  phd ment
1           1        0          1    0 2.52    7
2           1        1          0    0 2.05    6
3           1        1          0    0 3.75    6
4           1        0          1    1 1.18    3
5           1        1          0    0 3.75   26
6           1        1          1    2 3.59    2

r$> pr <- drop((1 - plogis(X0 %*% cf0)) * exp(X1 %*% cf1))

r$> summary(pr - predict(m))
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      0       0       0       0       0       0

If you are predicting for a new data set, use model.matrix(~1, newdata) to
get X and make sure your inverse link functions are correct when using
probit or cloglog.

Cheers,

P?ter S?lymos
On Tue, May 3, 2022 at 8:11 AM Lee, Laura <laura.lee at ncdenr.gov> wrote:

            

  
  
Message-ID: <CA+cT0FgheZZFuy1_P820C+HK3N+_-HHjGp-N+h-YG3bJTSb9xA@mail.gmail.com>
In-Reply-To: <DM8PR09MB6232E559033EA969205A5B5293C09@DM8PR09MB6232.namprd09.prod.outlook.com>