Gradient of the multinomial likelihood sum
Examples
calc_prob_null_gradient(t(c(.28, .32, .4)),
matrix(c(2, 2, 1, 1, 2, 2, 0, 3, 2), ncol = 3),
rep(TRUE, 3))
#> [,1] [,2] [,3]
#> [1,] 0.199254 0.1102833 0.02679112
# numerically
testenv <- new.env()
testenv$SSpacearr <- matrix(c(2, 2, 1, 1, 2, 2, 0, 3, 2), ncol = 3)
testenv$thistheta <- c(.28, .32, .4)
numericDeriv(quote(sum(exp((.colSums(t(SSpacearr) * log(thistheta), m = 3, n = 3))))),
theta = "thistheta", rho = testenv, central = TRUE)
#> [1] 0.03018932
#> attr(,"gradient")
#> [,1] [,2] [,3]
#> [1,] 0.199254 0.1102833 0.02679112