Compute the variance function and its derivatives with respect to regression, dispersion and power parameters.
Usage
mt_variance_function(mu, power, Ntrial, variance,
derivative_power, derivative_mu)
mt_tweedie(mu, power, Ntrial, derivative_power, derivative_mu)
mt_binomialP(mu, power, Ntrial,
derivative_power, derivative_mu)
mt_binomialPQ(mu, power, Ntrial,
derivative_power, derivative_mu)
mt_constant(mu, power, Ntrial, derivative_power, derivative_mu)
Source
Bonat, W. H. and Jorgensen, B. (2016) Multivariate covariance generalized linear models. Journal of Royal Statistical Society - Series C 65:649–675.
Arguments
- mu
a numeric vector. In general the output from
mt_link_function
.- power
a numeric value (
tweedie
andbinomialP
) or a vector (binomialPQ
) of the power parameters.- Ntrial
number of trials, useful only when dealing with binomial response variables.
- variance
a string specifying the name (
constant, tweedie, binomialP or binomialPQ
) of the variance function.- derivative_power
logical if compute (TRUE) or not (FALSE) the derivatives with respect to the power parameter.
- derivative_mu
logical if compute (TRUE) or not (FALSE) the derivative with respect to the mu parameter.
Details
The function mt_variance_function
computes three
features related with the variance function. Depending on the
logical arguments, the function returns \(V^{1/2}\) and its
derivatives with respect to the parameters power and mu,
respectivelly. The output is a named list, completely
informative about what the function has been computed. For
example, if derivative_power = TRUE
and derivative_mu = TRUE
.
The output will be a list, with three elements: V_sqrt, D_V_sqrt_power and
D_V_sqrt_mu.
Author
Wagner Hugo Bonat, wbonat@ufpr.br
Examples
x1 <- seq(-1, 1, l = 5)
X <- model.matrix(~x1)
mu <- mt_link_function(beta = c(1, 0.5), X = X, offset = NULL,
link = "logit")
mt_variance_function(mu = mu$mu, power = c(2, 1), Ntrial = 1,
variance = "binomialPQ",
derivative_power = TRUE, derivative_mu = TRUE)
#> $V_sqrt
#> 5 x 5 diagonal matrix of class "ddiMatrix"
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.382466 . . . .
#> [2,] . 0.3846942 . . .
#> [3,] . . 0.3791238 . .
#> [4,] . . . 0.3668165 .
#> [5,] . . . . 0.3491967
#>
#> $D_V_sqrt_p
#> 5 x 5 diagonal matrix of class "ddiMatrix"
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] -0.09065917 . . . .
#> [2,] . -0.07441352 . . .
#> [3,] . . -0.05938248 . .
#> [4,] . . . -0.04620587 .
#> [5,] . . . . -0.03516643
#>
#> $D_V_sqrt_q
#> 5 x 5 diagonal matrix of class "ddiMatrix"
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] -0.1862757 . . . .
#> [2,] . -0.2186738 . . .
#> [3,] . . -0.2489444 . .
#> [4,] . . . -0.2754662 .
#> [5,] . . . . -0.2970639
#>
#> $D_V_inv_sqrt_mu
#> [1] -0.7377650 0.2239011 1.2957812 2.6134777 4.3463022
#>