dy.d_ {NNS} | R Documentation |
Partial Derivative dy/d_[wrt]
Description
Returns the numerical partial derivative of y
with respect to [wrt] any regressor for a point of interest. Finite difference method is used with NNS.reg estimates as f(x + h)
and f(x - h)
values.
Usage
dy.d_(x, y, wrt, eval.points = "obs", mixed = FALSE, messages = TRUE)
Arguments
x |
a numeric matrix or data frame. |
y |
a numeric vector with compatible dimensions to |
wrt |
integer; Selects the regressor to differentiate with respect to (vectorized). |
eval.points |
numeric or options: ("obs", "apd", "mean", "median", "last"); Regressor points to be evaluated.
|
mixed |
logical; |
messages |
logical; |
Value
Returns column-wise matrix of wrt regressors:
dy.d_(...)[, wrt]$First
the 1st derivativedy.d_(...)[, wrt]$Second
the 2nd derivativedy.d_(...)[, wrt]$Mixed
the mixed derivative (for two independent variables only).
Note
For binary regressors, it is suggested to use eval.points = seq(0, 1, .05)
for a better resolution around the midpoint.
Author(s)
Fred Viole, OVVO Financial Systems
References
Viole, F. and Nawrocki, D. (2013) "Nonlinear Nonparametric Statistics: Using Partial Moments" https://www.amazon.com/dp/1490523995/ref=cm_sw_su_dp
Vinod, H. and Viole, F. (2020) "Comparing Old and New Partial Derivative Estimates from Nonlinear Nonparametric Regressions" https://www.ssrn.com/abstract=3681104
Examples
## Not run:
set.seed(123) ; x_1 <- runif(1000) ; x_2 <- runif(1000) ; y <- x_1 ^ 2 * x_2 ^ 2
B <- cbind(x_1, x_2)
## To find derivatives of y wrt 1st regressor for specific points of both regressors
dy.d_(B, y, wrt = 1, eval.points = t(c(.5, 1)))
## To find average partial derivative of y wrt 1st regressor,
only supply 1 value in [eval.points], or a vector of [eval.points]:
dy.d_(B, y, wrt = 1, eval.points = .5)
dy.d_(B, y, wrt = 1, eval.points = fivenum(B[,1]))
## To find average partial derivative of y wrt 1st regressor,
for every observation of 1st regressor:
apd <- dy.d_(B, y, wrt = 1, eval.points = "apd")
plot(B[,1], apd[,1]$First)
## 95% Confidence Interval to test if 0 is within
### Lower CI
LPM.VaR(.025, 0, apd[,1]$First)
### Upper CI
UPM.VaR(.025, 0, apd[,1]$First)
## End(Not run)