Last chance! 50% off unlimited learning
Sale ends in
predictnl
generic function.Given a regression object
and a function fun
that
predicts values from the object, return the predicted values and the
standard errors using the numeric delta method.
predictnl.default(object, fun, newdata = NULL, ...)
Regression object, that includes methods for coef
and
vcov
and either (i) a coefficients
component, (ii) a
coef
component or (iii) a coef<-
method (checked in that order).
Function that has a signature function(object, ...)
A list or data-frame that is passed to fun
. If
newdata
is NULL
and object
has a non-NULL
data
component, then newdata <- object$data
.
Other arguments to fun
.
Returns a data-frame with components Estimate
for the point
estimate and SE
for the standard errors.
The work is done by rstpm:::numDeltaMethod
.
One potential issue for some regression objects is that predictions on
the fitted data may use values from the regression object, so that the
calculated standard errors are zero. The default work-around
provided here is define newdata
from object$data
; other
work-arounds include (i) always passing the original data to
newdata
and (ii) define a prediction function fun
that
always uses the original data.
# NOT RUN {
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (object, fun, newdata = NULL, ...)
{
if (is.null(newdata) && !is.null(object$data))
newdata <- object$data
localf <- function(coef, ...) {
if ("coefficients" %in% names(object)) {
object$coefficients <- coef
} else if ("coef" %in% names(object)) {
object$coef <- coef
} else coef(object) <- coef
fun(object, ...)
}
numDeltaMethod(object, localf, newdata = newdata, ...)
}
# }
Run the code above in your browser using DataLab