Learn R Programming

rstpm2 (version 1.2.2)

predictnl.default: Default implementation of the predictnl generic function.

Description

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.

Usage

predictnl.default(object, fun, newdata = NULL, ...)

Arguments

object
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).
fun
Function that has a signature function(object, ...)
newdata
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.

Value

  • Returns a data-frame with components Estimate for the point estimate and SE for the standard errors.

Details

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.

Examples

Run this code
##---- 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