Skip to content

Commit 4618a43

Browse files
committed
Include geometric Poisson Tweedie facilities.
1 parent 770dfc7 commit 4618a43

9 files changed

+105
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: mcglm
22
Type: Package
33
Title: Multivariate Covariance Generalized Linear Models
44
Version: 0.5.0
5-
Date: 2019-03-19
5+
Date: 2019-09-10
66
Author: Wagner Hugo Bonat [aut, cre],
77
Walmes Marques Zeviani [ctb],
88
Fernando de Pol Mayer [ctb]

R/mc_build_sigma.R

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,81 @@ mc_build_sigma <- function(mu, Ntrial = 1, tau, power, Z, sparse,
259259
}
260260
}
261261
}
262+
if(variance == "geom_tweedie") {
263+
if (covariance == "identity" | covariance == "expm") {
264+
Omega <- mc_build_omega(tau = tau, Z = Z,
265+
covariance_link = covariance,
266+
sparse = sparse)
267+
V_sqrt <- mc_variance_function(
268+
mu = mu$mu, power = power,
269+
Ntrial = Ntrial, variance = "power", inverse = FALSE,
270+
derivative_power = !power_fixed,
271+
derivative_mu = compute_derivative_beta)
272+
Sigma <- forceSymmetric(Diagonal(length(mu$mu), mu$mu^2) +
273+
V_sqrt$V_sqrt %*%
274+
Omega$Omega %*% V_sqrt$V_sqrt)
275+
chol_Sigma <- chol(Sigma)
276+
inv_chol_Sigma <- solve(chol_Sigma)
277+
D_Sigma <- lapply(Omega$D_Omega, mc_sandwich,
278+
bord1 = V_sqrt$V_sqrt,
279+
bord2 = V_sqrt$V_sqrt)
280+
if (power_fixed == FALSE) {
281+
D_Sigma_power <- mc_sandwich_power(
282+
middle = Omega$Omega,
283+
bord1 = V_sqrt$V_sqrt, bord2 = V_sqrt$D_V_sqrt_p)
284+
D_Sigma <- c(D_Sigma_power = D_Sigma_power,
285+
D_Sigma_tau = D_Sigma)
286+
}
287+
output <- list(Sigma_chol = chol_Sigma,
288+
Sigma_chol_inv = inv_chol_Sigma,
289+
D_Sigma = D_Sigma)
290+
if (compute_derivative_beta == TRUE) {
291+
D_Sigma_beta <- mc_derivative_sigma_beta(
292+
D = mu$D,
293+
D_V_sqrt_mu = V_sqrt$D_V_sqrt_mu, Omega$Omega,
294+
V_sqrt = V_sqrt$V_sqrt, variance = variance)
295+
output$D_Sigma_beta <- D_Sigma_beta
296+
}
297+
}
298+
if (covariance == "inverse") {
299+
inv_Omega <- mc_build_omega(tau = tau, Z = Z,
300+
covariance_link = "inverse",
301+
sparse = sparse)
302+
Omega <- chol2inv(chol(inv_Omega$inv_Omega))
303+
V_sqrt <- mc_variance_function(
304+
mu = mu$mu, power = power,
305+
Ntrial = Ntrial, variance = "power", inverse = FALSE,
306+
derivative_power = !power_fixed,
307+
derivative_mu = compute_derivative_beta)
308+
D_Omega <- lapply(inv_Omega$D_inv_Omega,
309+
mc_sandwich_negative, bord1 = Omega,
310+
bord2 = Omega)
311+
D_Sigma <- lapply(D_Omega, mc_sandwich,
312+
bord1 = V_sqrt$V_sqrt,
313+
bord2 = V_sqrt$V_sqrt)
314+
Sigma <- forceSymmetric(Diagonal(length(mu$mu), mu$mu^2) +
315+
V_sqrt$V_sqrt %*% Omega %*%
316+
V_sqrt$V_sqrt)
317+
chol_Sigma <- chol(Sigma)
318+
inv_chol_Sigma <- solve(chol_Sigma)
319+
if (power_fixed == FALSE) {
320+
D_Sigma_p <- mc_sandwich_power(
321+
middle = Omega,
322+
bord1 = V_sqrt$V_sqrt,
323+
bord2 = V_sqrt$D_V_sqrt_power)
324+
D_Sigma <- c(D_Sigma_p, D_Sigma)
325+
}
326+
output <- list(Sigma_chol = chol_Sigma,
327+
Sigma_chol_inv = inv_chol_Sigma,
328+
D_Sigma = D_Sigma)
329+
if (compute_derivative_beta == TRUE) {
330+
D_Sigma_beta <- mc_derivative_sigma_beta(
331+
D = mu$D,
332+
D_V_sqrt_mu = V_sqrt$D_V_sqrt_mu, Omega = Omega,
333+
V_sqrt = V_sqrt$V_sqrt, variance = variance)
334+
output$D_Sigma_beta <- D_Sigma_beta
335+
}
336+
}
337+
}
262338
return(output)
263339
}

R/mc_derivative_sigma_beta.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ mc_derivative_sigma_beta <- function(D, D_V_sqrt_mu, Omega, V_sqrt,
3535
bord2 = D_V_sqrt_beta)
3636
}
3737
}
38+
if (variance == "geom_tweedie") {
39+
for (i in 1:n_beta) {
40+
D_V_sqrt_beta <- Diagonal(n_obs, D_V_sqrt_mu * D[, i])
41+
output[[i]] <- Diagonal(n_obs, 2*D[, i]) +
42+
mc_sandwich_power(middle = Omega, bord1 = V_sqrt,
43+
bord2 = D_V_sqrt_beta)
44+
}
45+
}
3846
return(output)
3947
}

R/mc_initial_values.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ mc_initial_values <- function(linear_pred, matrix_pred, link,
9393
}
9494
}
9595
if (variance[[i]] == "tweedie" |
96-
variance[[i]] == "poisson_tweedie") {
96+
variance[[i]] == "poisson_tweedie" |
97+
variance[[i]] == "geom_tweedie") {
9798
power_initial[[i]] <- 1
9899
if (!is.null(offset[[i]])) {
99100
data_temp <- data

R/mc_variance_function.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#'
3838
#' @source Bonat, W. H. and Jorgensen, B. (2016) Multivariate
3939
#' covariance generalized linear models.
40-
#' Journal of Royal Statistical Society - Series C X(X):XX--XX.
40+
#' Journal of Royal Statistical Society - Series C 65:649--675.
4141
#'
4242
#' @export
4343
#'

README.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ The `mcglm` package fits multivariate covariance generalized linear models
2121

2222
## Introduction
2323

24-
`mcglm` fits multivariate covariance generalized linear models. It allows use a different linear predictor for each response variable of a
24+
`mcglm` fits multivariate covariance generalized linear models.
25+
It allows use a different linear predictor for each response variable of a
2526
multivariate response. The response variable can be continous or
2627
dicrete, like counts and binary and also limited continuos ou
2728
discrete/continuous inflated responses. The most important and relevant

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

22

3-
# mcglm 0.4.0
3+
# mcglm 0.5.0
44

55
[![Build Status](https://travis-ci.org/wbonat/mcglm.svg?branch=master)](https://travis-ci.org/wbonat/mcglm)
66
Build status for the stable version (`master` branch)
77

88
[![Build Status](https://travis-ci.org/wbonat/mcglm.svg?branch=devel)](https://travis-ci.org/wbonat/mcglm)
99
Build status for the development version (`devel` branch)
1010

11-
The `mcglm` package fit multivariate covariance generalized linear models
12-
(Bonat and Jorgensen, 2015).
11+
The `mcglm` package fits multivariate covariance generalized linear models
12+
(Bonat and Jorgensen, 2016).
1313

1414
## Introduction
1515

16-
`mcglm` fit multivariate covariance generalized linear models. It allows
17-
use a different linear predictor for each response variable of a
16+
`mcglm` fits multivariate covariance generalized linear models.
17+
It allows use a different linear predictor for each response variable of a
1818
multivariate response. The response variable can be continous or
1919
dicrete, like counts and binary and also limited continuos ou
2020
discrete/continuous inflated responses. The most important and relevant
@@ -37,20 +37,20 @@ library(devtools)
3737
install_github("wbonat/mcglm")
3838
```
3939

40-
Alternatively, download the package tarball: [mcglm_0.4.0.tar.gz][]
40+
Alternatively, download the package tarball: [mcglm_0.5.0.tar.gz][]
4141
and run from a UNIX terminal (make sure you are on the container file
4242
directory):
4343

4444

4545
```
46-
R CMD INSTALL -l /path/to/your/R/library mcglm_0.4.0.tar.gz
46+
R CMD INSTALL -l /path/to/your/R/library mcglm_0.5.0.tar.gz
4747
```
4848

4949
Or, inside an `R` session:
5050

5151

5252
```
53-
install.packages("mcglm_0.4.0.tar.gz", repos = NULL,
53+
install.packages("mcglm_0.5.0.tar.gz", repos = NULL,
5454
lib.loc = "/path/to/your/R/library",
5555
dependencies = TRUE)
5656
```
@@ -62,13 +62,13 @@ library.
6262

6363
### Windows
6464

65-
Download Windows binary version: [mcglm_0.4.0.zip][] (**do not unzip
65+
Download Windows binary version: [mcglm_0.5.0.zip][] (**do not unzip
6666
it under Windows**), put the file in your working directory, and from
6767
inside `R`:
6868

6969

7070
```
71-
install.packages("mcglm_0.4.0.zip", repos = NULL,
71+
install.packages("mcglm_0.5.0.zip", repos = NULL,
7272
dependencies = TRUE)
7373
```
7474

@@ -119,10 +119,10 @@ See [LICENSE](./LICENSE)
119119
[GNU General Public License (GPL) v3.0]: http://www.gnu.org/licenses/gpl-3.0.html
120120
[`roxygen2`]: https://github.com/klutometis/roxygen
121121
[`devtools`]: https://github.com/hadley/devtools
122-
[mcglm_0.4.0.tar.gz]: https://github.com/wbonat/mcglm/raw/master/downloads/mcglm_0.4.0.tar.gz
123-
[mcglm_0.4.0.zip]: https://github.com/wbonat/mcglm/raw/master/downloads/mcglm_0.4.0.zip
122+
[mcglm_0.5.0.tar.gz]: https://github.com/wbonat/mcglm/raw/master/downloads/mcglm_0.5.0.tar.gz
123+
[mcglm_0.5.0.zip]: https://github.com/wbonat/mcglm/raw/master/downloads/mcglm_0.5.0.zip
124124
[mcglm-manual.pdf]: https://github.com/wbonat/mcglm/raw/master/downloads/mcglm-manual.pdf
125125
[Gitflow worflow]: http://nvie.com/posts/a-successful-git-branching-model/
126-
[Wagner Hugo Bonat]: http://www.leg.ufpr.br/doku.php/pessoais:wbonat
126+
[Wagner Hugo Bonat]: http://www.leg.ufpr.br/~wagner
127127
[Walmes Marques Zeviani]: http://www.leg.ufpr.br/~walmes
128128
[Fernando de Pol Mayer]: http://www.leg.ufpr.br/~fernandomayer

man/fit_mcglm.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mc_variance_function.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)