Skip to contents

gradients is a generic function which extracts gradients from objects.

Usage

gradients(x, ...)

# S3 method for class 'condensity'
gradients(x, se = FALSE, gradient.order = NULL, ...)

# S3 method for class 'condistribution'
gradients(x, se = FALSE, gradient.order = NULL, ...)

# S3 method for class 'lsqregression'
gradients(x, se = FALSE, gradient.order = NULL, ...)

# S3 method for class 'npregression'
gradients(x, se = FALSE, gradient.order = NULL, ...)

# S3 method for class 'qregression'
gradients(x, se = FALSE, ...)

# S3 method for class 'conmode'
gradients(x, level = NULL, se = FALSE, ...)

# S3 method for class 'singleindex'
gradients(x, se = FALSE, ...)

Arguments

Object And Output Controls

Object to interrogate and whether gradient standard errors are requested.

x

an object for which the extraction of gradients is meaningful.

se

a logical value specifying whether or not standard errors of gradients are desired. Defaults to FALSE.

level

for conmode objects, an optional dependent-variable class level identifying the stored class-probability gradients to extract. If supplied, it must match the level requested when the object was fitted.

Derivative Order Controls

Optional local-polynomial derivative order controls.

gradient.order

for npregression, condensity, condistribution, and lsqregression objects fitted with regtype="lp", optional derivative order request (scalar or one entry per continuous predictor). For npregression, condensity, and condistribution, unavailable components whose order exceeds the fitted polynomial degree are returned as NA when another requested continuous component or categorical first-difference effect remains available. Although the formal derivative of the fitted truncated polynomial is zero above its degree, that zero is not an estimate of the corresponding derivative of the unknown target; NA records that the derivative was not estimated. For lsqregression, a supplied order must exactly identify the stored order; unavailable stored components remain NA, while any different requested order is rejected. If another derivative order is desired, compute the fit, prediction, or evaluation with gradients=TRUE and that gradient.order; gradients() does not recompute derivatives after fitting. Gradient standard errors additionally require the object to have been created with se=TRUE.

Additional Arguments

Further method-specific arguments.

...

other arguments.

Value

Gradients extracted from the model object x.

Details

This function provides a generic interface for extraction of gradients from objects. For npregression, condensity, condistribution, and lsqregression objects fitted with regtype="lp", gradient.order identifies the stored continuous-predictor derivative order to extract; it is not a post-fit recomputation control. For lsqregression, the requested order must exactly match the stored order. For qregression objects, se=TRUE returns asymptotic standard errors for the quantile gradients when the object was fitted with gradients=TRUE.

See also

fitted, residuals, coef, and se, for related methods; np for supported objects.

References

See the references for the method being interrogated via gradients in the appropriate help file. For example, for the particulars of the gradients for nonparametric regression see the references in npreg

Author

Tristen Hayfield tristen.hayfield@gmail.com, Jeffrey S. Racine racinej@mcmaster.ca

Note

This method currently only supports objects from the np library.

Examples

x <- runif(10)
y <- x + rnorm(10, sd = 0.1)
gradients(npreg(y~x, gradients=TRUE))
#>             [,1]
#>  [1,] 0.08335970
#>  [2,] 0.05645006
#>  [3,] 0.08940909
#>  [4,] 0.38686901
#>  [5,] 0.17183005
#>  [6,] 0.02558592
#>  [7,] 0.13164093
#>  [8,] 0.37459957
#>  [9,] 0.55905602
#> [10,] 0.49043644