Description Usage Arguments Details 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_full_vec(V, Y, A, B, k11, Vo, Yo, minus_Y = TRUE)
|
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 |
k11 |
A number, the |
Vo |
A numerical vector of the same dimension as |
Yo |
A numerical vector, a sample for the parent nodes (regressors). |
minus_Y |
A logical, argument as in |
The derivative of log_dhurdle_vec_abk(V[,1], Y[,1], A, B, k)
with respect to aa
, bb
and k
, where A=sum_A_mat(aa, V[,2:p], Y[,2:p])
and B=sum_B_mat(bb, V[,2:p], Y[,2:p], minus_Y)
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | set.seed(1)
n <- 100; p <- 10
V <- matrix(rbinom(n*p, 1, 0.8), nrow=n, ncol=p)
Y <- matrix(rnorm(n*p) * V, nrow=n, ncol=p)
aa <- rnorm(2*p-1)
bb <- rnorm(2*p-1)
k <- abs(rnorm(1))
grad_vec <- grad_full_vec(V[,1], Y[,1], sum_A_mat(aa, V[,2:p], Y[,2:p]),
sum_B_mat(bb, V[,2:p], Y[,2:p], minus_Y=TRUE), k, V[,2:p], Y[,2:p], minus_Y=TRUE)
numer_grad <- numDeriv::grad(function(x){
log_dhurdle_vec_abk(V[,1], Y[,1], sum_A_mat(x[1:(2*p-1)], V[,2:p], Y[,2:p]),
sum_B_mat(x[(2*p):(4*p-2)], V[,2:p], Y[,2:p], minus_Y=TRUE), x[4*p-1])}, c(aa, bb, k))
max(abs(grad_vec - numer_grad))
grad_vec <- grad_full_vec(V[,1], Y[,1], sum_A_mat(aa, V[,2:p], Y[,2:p]),
sum_B_mat(bb, V[,2:p], Y[,2:p], minus_Y=FALSE), k, V[,2:p], Y[,2:p], minus_Y=FALSE)
numer_grad <- numDeriv::grad(function(x){
log_dhurdle_vec_abk(V[,1], Y[,1], sum_A_mat(x[1:(2*p-1)], V[,2:p], Y[,2:p]),
sum_B_mat(x[(2*p):(4*p-2)], V[,2:p], Y[,2:p], minus_Y=FALSE), x[4*p-1])}, c(aa, bb, k))
max(abs(grad_vec - numer_grad))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.