Description Usage Arguments Details Value Author(s) References Examples
Estimate derivative of a function at a point d_0 based on a local quadratic regression procedure of Fan and Gijbels (1996) that utilizes an automatic bandwidth selection formula.
1 | estimateDeriv(explanatory, response, d_0, sigmaSq)
|
explanatory |
Explanatory sample points |
response |
Observed responses at the explanatory sample points |
d_0 |
d_0 is the point of interest where the derivative is estimated |
sigmaSq |
estimate of variance at d_0 |
This is an internal function not meant to be called directly.
Returns a single number representing the derivative estimate at d_0. If a negative derivative has been estimated, then a warning is given, as this violates the isotonic (non-decreasing) assumption.
Shawn Mankad
Fan J, Gijbels I (1996). Local polynomial modelling and its applications, volume 66 of Monographs on Statistics and Applied Probability. Chapman & Hall, London. ISBN 0-412-98321-4.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | explanatory = runif(50)
response = explanatory^2 + rnorm(50, sd=0.1)
estimateDeriv(explanatory, response, d_0=0.5,
sigmaSq=estimateSigmaSq(explanatory, response)$sigmaSq)
## The function is currently defined as
function (explanatory, response, d_0, sigmaSq)
{
deriv_estimateHelper <- function(explanatory, response, d_0,
sigmaSq) {
n = length(response)
p = 5
X = matrix(0, n, p)
for (i in 1:p) {
X[, i] = (explanatory - d_0)^i
}
beta_hat = lm(response ~ 0 + X)$coef
h = 0
for (i in (p - 1):(p + 1)) {
j = i - p + 2
h = h + beta_hat[i - 1] * factorial(j) * d_0^(j -
1)
}
return(2.275 * (sigmaSq/h^2)^(1/7) * n^(-1/7))
}
n = length(response)
p = 2
X = matrix(0, n, p)
X[, 1] = (explanatory - d_0)
X[, 2] = (explanatory - d_0)^2
bw_opt = deriv_estimateHelper(explanatory, response, d_0,
sigmaSq)
W = 0.75/bw_opt * sapply(1 - ((explanatory - d_0)/bw_opt)^2,
max, 0)
while (sum(W > 1) <= 1 & bw_opt <= max(explanatory) - min(explanatory)) {
bw_opt = bw_opt * 2
W = 0.75/bw_opt * sapply(1 - ((explanatory - d_0)/bw_opt)^2,
max, 0)
}
beta_hat = lm(response ~ 0 + X, weight = W)$coef
while (beta_hat[1] <= 0 & bw_opt <= max(explanatory) - min(explanatory)) {
bw_opt = bw_opt * 2
W = 0.75/bw_opt * sapply(1 - ((explanatory - d_0)/bw_opt)^2,
max, 0)
beta_hat = lm(response ~ 0 + X, weight = W)$coef
}
if (beta_hat[1] <= 0) {
warning("deriv_estimate:WARNING: NEGATIVE DERIVATIVE HAS BEEN ESTIMATED",
.call = FALSE)
return(1/log(n))
}
return(beta_hat[1])
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.