Predict from a two-part model
Arguments
- object
a
"twopart"fit- newdata
optional data frame; defaults to the (complete-case) data used for fitting. For
cre = TRUEfits, the individual means are recomputed withinnewdataunless itsmean_*columns are supplied.- type
"response"forE[y] = P(y > 0) E[y | y > 0],"prob"forP(y > 0), or"positive"forE[y | y > 0](retransformed for the lognormal part)- ...
unused
See also
Other twopart methods:
confint.twopart(),
plot.twopart()
Examples
data(copd)
set.seed(1)
copd$cost <- ifelse(copd$exacerbations > 0,
exp(6 + 0.1 * copd$crp + rnorm(nrow(copd), 0, 0.5)), 0)
tp <- twopart(cost ~ treatment + crp, data = copd, index = c("id", "visit"))
head(predict(tp)) # E[y]
#> [1] 657.3327 376.3459 552.9015 608.6868 511.9711 558.2423
head(predict(tp, type = "prob")) # P(y > 0)
#> [1] 0.7720320 0.7609261 0.7686167 0.7705176 0.7670897 0.7688072
head(predict(tp, type = "positive")) # E[y | y > 0]
#> [1] 851.4320 494.5893 719.3462 789.9713 667.4202 726.1148