predict-methods {twopartm} | R Documentation |
Method for Function predict
for Two-part Model Fits in Package twopartm
Description
Obtains predictions and optionally estimates standard errors of those predictions from a fitted two-part model object of class twopartm
.
Usage
## S4 method for signature 'twopartm'
predict(object,newdata = NULL, se.fit = FALSE,
dispersion_part1 = NULL,dispersion_part2 = NULL,na.action = na.pass)
Arguments
object |
a fitted two-part model object of class |
newdata |
optionally, a data frame in which to look for variables with which to predict. If omitted, the original observations are used. |
se.fit |
logical switch indicating if standard errors are required. |
dispersion_part1 |
the dispersion of the GLM fit to be assumed in computing the standard errors for the first-part model. If omitted, that returned by |
dispersion_part2 |
the dispersion of the GLM fit to be assumed in computing the standard errors for the second-part model. If omitted, that returned by |
na.action |
function determining what should be done with missing values in |
Details
The predictive values and corresponding standard errors are on the scales of the response variable not considering the link functions. The predictive responses are calculated by multiplying the predicted probabilities of non-zero responses and the fitted means of non-zero values. The prediction standard errors are calculated using delta method combining prediction standard errors from the models of both parts. If newdata
is omitted the predictions are based on the data used for the fit. In that case how cases with missing values in the original fit is determined by the na.action
argument of that fit.
Value
If se.fit = FALSE
, a vector or matrix of predictions.
If se.fit = TRUE
, a list with components
fit |
Predictions, as for |
se.fit |
Estimated standard errors. |
residual.scale_part1 |
A scalar giving the square root of the dispersion used in computing the standard errors for the first-part model. |
residual.scale_part2 |
A scalar giving the square root of the dispersion used in computing the standard errors for the second-part model. |
Author(s)
Yajie Duan, Birol Emir, Griffith Bell and Javier Cabrera
References
Belotti, F., Deb, P., Manning, W.G. and Norton, E.C. (2015). twopm: Two-part models. The Stata Journal, 15(1), pp.3-20.
Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.
See Also
twopartm-class
, tpm
, AME
, margin
, glm
, predict.glm
Examples
##data about health expenditures, i.e., non-negative continuous response
data(meps,package = "twopartm")
##fit two-part model with the same regressors in both parts, with logistic
##regression model for the first part, and glm with Gamma family with log
##link for the second-part model
tpmodel = tpm(exp_tot~female+age, data = meps,link_part1 = "logit",
family_part2 = Gamma(link = "log"))
tpmodel
##get prediction results with standard errors for the
##first 500 observations in the dataset
predict(tpmodel,newdata = meps[1:500,],se.fit = TRUE)
##data for count response
data("bioChemists")
##fit two-part model with the same regressors in both parts, with logistic
##regression model for the first part, and poisson regression model with
##default log link for the second-part model
tpmodel = tpm(art ~ .,data = bioChemists,link_part1 = "logit",
family_part2 = poisson)
tpmodel
##get predictive counts
predict(tpmodel)