Description Usage Arguments Details Value Examples
View source: R/zero_est_core.R
Gradient of log_dhurdle1d_abk()
(with scalar v
and y
) with respect to a
, b
, k
.
1 | grad_a_b_k(V, Y, A, B, k)
|
V |
A logical vector, indicating if each entry in |
Y |
A numerical vector of i.i.d. 1-d Hurdle random variables. |
A |
A number or a vector of the same length |
B |
A number or a vector of the same length |
k |
A number, the |
The i
-th row of the returned matrix is the gradient of log_dhurdle1d_abk(V[i], Y[i], A[i], B[i], k)
with respect to A[i]
, B[i]
, k
if A
and B
are vectors, or with respect to A
and B
if they are scalars.
A matrix with 3 columns and number of rows equal to the length of Y
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | if (!requireNamespace("numDeriv", quietly = TRUE))
stop("Please install package \"numDeriv\".")
set.seed(1)
n <- 100
V <- rbinom(n, 1, 0.8)
Y <- rnorm(n) * V
A <- rnorm(n)
B <- rnorm(n)
k <- abs(rnorm(1))
grad_mat <- grad_a_b_k(V, Y, A, B, k)
numer_grad <- t(sapply(1:n,
function(i){numDeriv::grad(function(x){
log_dhurdle1d_abk(V[i], Y[i], x[1], x[2], x[3])}, c(A[i], B[i], k))}))
max(abs(grad_mat - numer_grad))
a <- rnorm(1)
b <- rnorm(1)
grad_mat <- grad_a_b_k(V, Y, a, b, k)
numer_grad <- t(sapply(1:n,
function(i){numDeriv::grad(function(x){
log_dhurdle1d_abk(V[i], Y[i], x[1], x[2], x[3])}, c(a, b, k))}))
max(abs(grad_mat - numer_grad))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.