Title: | Bayesian Multivariate Conway-Maxwell-Poisson Regression Model for Correlated Count Data |
---|---|
Description: | Fits a Bayesian Regression Model for multivariate count data. This model assumes that the data is distributed according to the Conway-Maxwell-Poisson distribution, and for each response variable it is associate different covariates. This model allows to account for correlations between the counts by using latent effects based on the Chib and Winkelmann (2001) <http://www.jstor.org/stable/1392277> proposal. |
Authors: | Mauro Florez [aut, cre] |
Maintainer: | Mauro Florez <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-11 04:16:21 UTC |
Source: | https://github.com/mauroflorez/cmp |
Sampler for the Conway-Maxwell-Poisson as described in Algorithm 2 - Benson & Friel (2021)
com_sampler(mu, nu, n = 1, ndraws = FALSE)
com_sampler(mu, nu, n = 1, ndraws = FALSE)
mu |
Location parameter |
nu |
Shape parameter |
n |
Number of draws (default = 1) |
ndraws |
Optional: Return the number of draws required to generate the n samples. |
A list or numeric in case ndraws = FALSE:
sample |
Values sampled from the distribution |
drawsa |
Number of draws required in the rejection sampler |
log_Bf |
Log of the boundary of the rejection sampler |
com_sampler(2, 0.2, n = 10, ndraws = TRUE) com_sampler(1, 2)
com_sampler(2, 0.2, n = 10, ndraws = TRUE) com_sampler(1, 2)
This function used an approach similar to the presented by Benson & Friel (2021) to calculate the BIC. We select S a sample size of the posterior samples to speed up computation
DIC_cmp(fit, S = 100)
DIC_cmp(fit, S = 100)
fit |
An object from the mcmc_cmp_mh |
S |
Number of iterations used to calculate the DIC |
Vector of approximated DIC
A data set with the scores of the games played during season 2020-2021 in the English Premier League (EPL)
epl_20_21
epl_20_21
A data frame with 380 rows and 4 variables:
Goals scored by home team.
Goals scored by away team.
Home team.
Away team.
<https://www.football-data.co.uk>
Rootograms plots - Multivariate CMP
fitting_plots(fit, type = "rootogram", S = 100)
fitting_plots(fit, type = "rootogram", S = 100)
fit |
An element from 'mcmc_cmp' |
type |
Wheter to do a bar plot or a rootogram |
S |
Optional. Indicates the number of posterior samples used (Default 100) |
No return value, called for plotting only
n = 50; J = 2 X = list(matrix(rnorm(3*n), ncol = 3), matrix(rnorm(3*n), ncol = 3)) beta <- list(c(1,0.1, 1), c(0, 0.5, -0.5)) mu <- exp(prod_list(X, beta)) y = matrix(rpois(n = length(mu), lambda = mu), nrow = n) fit <- mcmc_cmp(y, X, S = 1000, nburn = 1000, scale_cov_b = 0.8, scale_cov_beta = 0.04, scale_cov_gamma = 0.06) fitting_plots(fit)
n = 50; J = 2 X = list(matrix(rnorm(3*n), ncol = 3), matrix(rnorm(3*n), ncol = 3)) beta <- list(c(1,0.1, 1), c(0, 0.5, -0.5)) mu <- exp(prod_list(X, beta)) y = matrix(rpois(n = length(mu), lambda = mu), nrow = n) fit <- mcmc_cmp(y, X, S = 1000, nburn = 1000, scale_cov_b = 0.8, scale_cov_beta = 0.04, scale_cov_gamma = 0.06) fitting_plots(fit)
This function calculates the log likelihood of the distribution as described by Benson and Friel (2021)
llk_cmp(y, mu, nu, r = 1000)
llk_cmp(y, mu, nu, r = 1000)
y |
Count value |
mu |
Location parameter |
nu |
Shape parameter |
r |
Number of acceptances |
Estimation of the log likelihood of the distribution
llk_cmp(10, 5, 2)
llk_cmp(10, 5, 2)
Log density of the normalized component of the Conway-Maxwell-Poisson
log_cmp(y, mu, nu)
log_cmp(y, mu, nu)
y |
Value |
mu |
Location parameter |
nu |
Shape parameter |
Numeric corresponding to the log of the unnormalized component of the distribution
MCMC Algorithm to estimate the parameters in the regression model for multivariate correlated count data
mcmc_cmp( y, X, S = 10000, nburn = 5000, initial_beta, initial_gamma, initial_b, prior_mean_beta, prior_var_beta, prior_mean_gamma, prior_var_gamma, v_0, R_0, intercept = FALSE, scale_b, scale_beta, scale_gamma, scale_cov_b, scale_cov_beta, scale_cov_gamma, inc_burn = FALSE, re_chain = TRUE, way = 2, random_seed, ... )
mcmc_cmp( y, X, S = 10000, nburn = 5000, initial_beta, initial_gamma, initial_b, prior_mean_beta, prior_var_beta, prior_mean_gamma, prior_var_gamma, v_0, R_0, intercept = FALSE, scale_b, scale_beta, scale_gamma, scale_cov_b, scale_cov_beta, scale_cov_gamma, inc_burn = FALSE, re_chain = TRUE, way = 2, random_seed, ... )
y |
Matrix of observations |
X |
Covariates list, each element is the design matrix for each column of y |
S |
Number of MCMC samples to be drawn |
nburn |
Number of MCMC samples to burn-in |
initial_beta |
List with initial value of |
initial_gamma |
List with initial value of |
initial_b |
Initital value of |
prior_mean_beta |
Prior mean for |
prior_var_beta |
Prior covariance matrix for |
prior_mean_gamma |
Prior mean for |
prior_var_gamma |
Prior covariance matrix for |
v_0 |
Prior degrees of freedom of random effects |
R_0 |
Prior covariance matrix of random effects |
intercept |
Logical value indicating whether include the intercept |
scale_b |
Covariance matrix for RW proposals of the random effects (Default |
scale_beta |
List with initial values for the scale matrices of |
scale_gamma |
List with initial values for the scale matrices of |
scale_cov_b |
Scale parameter for the RW of random effects. (Default |
scale_cov_beta |
Scale parameter for the covariance of the proposals. |
scale_cov_gamma |
Scale parameter for the covariance of the proposals. |
inc_burn |
logical: include burned samples in the return |
re_chain |
logical: If the posterior samples for the r.e are include. False return just the mean |
way |
How to calculate the MCMC updates, based on Chib (2001) |
random_seed |
Random seed |
... |
Additional parameters of the MCMC algorithm |
A list:
posterior_b |
List with posterior values of the random effects |
estimation_beta |
Estimation of beta parameters |
posterior_beta |
List with posterior values of beta |
estimation_gamma |
Estimation of gamma parameters |
posterior_gamma |
List with posterior values of gamma |
posterior_D |
Values of covariance matrix D |
fitted_mu |
Posterior of location parameters for each response |
fitted_nu |
Posterior of shape parameters for ecah response |
accept_rate_b |
Acceptance rate of Random Effects |
accept_rate_beta |
Acceptance rate of beta |
accept_rate_gamma |
Acceptance rate of gamma |
scale_beta |
Estimated Scale matrix for beta parameters |
scale_gamma |
Estimated Scale matrix for gamma parameters |
X |
List of covariates used |
y |
Matrix of observed counts |
n = 50; J = 2 X = list(matrix(rnorm(3*n), ncol = 3), matrix(rnorm(3*n), ncol = 3)) beta <- list(c(1,0.1, 1), c(0, 0.5, -0.5)) mu <- exp(prod_list(X, beta)) y = matrix(rpois(n = length(mu), lambda = mu), nrow = n) fit <- mcmc_cmp(y, X, S = 10000, nburn = 1000, scale_cov_b = 0.8, scale_cov_beta = 0.04, scale_cov_gamma = 0.06)
n = 50; J = 2 X = list(matrix(rnorm(3*n), ncol = 3), matrix(rnorm(3*n), ncol = 3)) beta <- list(c(1,0.1, 1), c(0, 0.5, -0.5)) mu <- exp(prod_list(X, beta)) y = matrix(rpois(n = length(mu), lambda = mu), nrow = n) fit <- mcmc_cmp(y, X, S = 10000, nburn = 1000, scale_cov_b = 0.8, scale_cov_beta = 0.04, scale_cov_gamma = 0.06)
Product of lists between matrices
prod_list(X, beta)
prod_list(X, beta)
X |
Data |
beta |
Parameters |
A list with the products element-wise