predict.opsr {OPSR} | R Documentation |
Predict Method for OPSR Model Fits
Description
Obtains predictions for the selection process (probabilities), the outcome process, or returns the inverse mills ratio. Handles also log-transformed outcomes.
Usage
## S3 method for class 'opsr'
predict(
object,
newdata,
group,
counterfact = NULL,
type = c("response", "unlog-response", "prob", "mills", "correction", "Xb"),
delta = 1,
...
)
Arguments
object |
an object of class |
newdata |
an optional data frame in which to look for variables used in
|
group |
predict outcome of this group (regime). |
counterfact |
counterfactual group. |
type |
type of prediction. Can be abbreviated. See 'Details' section for more information. |
delta |
constant that was added during the continuity correction
( |
... |
further arguments passed to or from other methods. |
Details
Elements are NA_real_
if the group
does not correspond to the observed
regime (selection outcome). This ensures consistent output length.
If the type
argument is "response"
then the continuous outcome is predicted.
Use "unlog-response"
if the outcome response was log-transformed (i.e., either
in the formula
specification or during data pre-processing).
"prob"
returns the probability vector of belonging to group
, "mills"
returns the inverse mills ratio, "correction"
the heckman correction (i.e.,
\rho_j * \sigma_j * \text{mills}
) and "Xb"
returns X \beta
.
Value
a vector of length nrow(newdata)
(or data used during estimation).
See Also
Examples
set.seed(123)
sim_dat <- opsr_simulate()
dat <- sim_dat$data
model <- ys | yo ~ xs1 + xs2 | xo1 + xo2
fit <- opsr(model, dat)
p <- predict(fit, group = 1, type = "response")
fit_log <- update(fit, . | log(yo) ~ .)
p_unlog <- predict(fit, group = 1, type = "unlog-response")
## newdata
newdat <- dat[1:4, ]
unique(newdat$ys) # available selection outcomes
predict(fit, newdata = newdat, group = 2)