Title: | Zero-and-One Inflated Dirichlet Regression Modelling in TMB |
---|---|
Description: | Fits Dirichlet regression and zero-and-one inflated Dirichlet regression with Bayesian methods implemented in Stan. These models are sometimes referred to as trinomial mixture models; covariates and overdispersion can optionally be included. |
Authors: | Eric J. Ward [aut, cre] , Alexander J. Jensen [aut] , Ryan P. Kelly [aut] , Andrew O. Shelton [aut] , William H. Satterthwaite [aut] , Eric C. Anderson [aut] |
Maintainer: | Eric J. Ward <[email protected]> |
License: | GPL (>=3) |
Version: | 1.3.0 |
Built: | 2024-11-26 16:29:38 UTC |
Source: | https://github.com/noaa-nwfsc/zoidtmb |
Random generation of datasets using the dirichlet broken stick method
broken_stick( n_obs = 1000, n_groups = 10, ess_fraction = 1, tot_n = 100, p = NULL )
broken_stick( n_obs = 1000, n_groups = 10, ess_fraction = 1, tot_n = 100, p = NULL )
n_obs |
Number of observations (rows of data matrix to simulate). Defaults to 10 |
n_groups |
Number of categories for each observation (columns of data matrix). Defaults to 10 |
ess_fraction |
The effective sample size fraction, defaults to 1 |
tot_n |
The total sample size to simulate for each observation. This is approximate and the actual simulated sample size will be slightly smaller. Defaults to 100 |
p |
The stock proportions to simulate from, as a vector. Optional, and when not included, random draws from the dirichlet are used |
A 2-element list, whose 1st element X_obs
is the simulated dataset, and whose
2nd element is the underlying vector of proportions p
used to generate the data
y <- broken_stick(n_obs = 3, n_groups = 5, tot_n = 100) # add custom proportions y <- broken_stick( n_obs = 3, n_groups = 5, tot_n = 100, p = c(0.1, 0.2, 0.3, 0.2, 0.2) )
y <- broken_stick(n_obs = 3, n_groups = 5, tot_n = 100) # add custom proportions y <- broken_stick( n_obs = 3, n_groups = 5, tot_n = 100, p = c(0.1, 0.2, 0.3, 0.2, 0.2) )
Data from Satterthwaite, W.H., Ciancio, J., Crandall, E., Palmer-Zwahlen, M.L., Grover, A.M., O’Farrell, M.R., Anson, E.C., Mohr, M.S. & Garza, J.C. (2015). Stock composition and ocean spatial distribution from California recreational chinook salmon fisheries using genetic stock identification. Fisheries Research, 170, 166–178. The data genetic data collected from port-based sampling of recreationally-landed Chinook salmon in California from 1998-2002.
chinook
chinook
A data frame.
Data from Magnussen, E. 2011. Food and feeding habits of cod (Gadus morhua) on the Faroe Bank. – ICES Journal of Marine Science, 68: 1909–1917. The data here are Table 3 from the paper, with sample proportions (columns w) multiplied by total weight to yield total grams (g) for each sample-diet item combination. Dashes have been replaced with 0s.
coddiet
coddiet
A data frame.
Fit a trinomial mixture model that optionally includes covariates to estimate effects of factor or continuous variables on proportions.
fit_zoidTMB( formula = NULL, design_matrix, data_matrix, overdispersion = FALSE, overdispersion_sd = 5, prior_sd = NA )
fit_zoidTMB( formula = NULL, design_matrix, data_matrix, overdispersion = FALSE, overdispersion_sd = 5, prior_sd = NA )
formula |
The model formula for the design matrix. Does not need to have a response specified. If =NULL, then the design matrix is ignored and all rows are treated as replicates |
design_matrix |
A data frame, dimensioned as number of observations, and covariates in columns |
data_matrix |
A matrix, with observations on rows and number of groups across columns |
overdispersion |
Whether or not to include overdispersion parameter, defaults to FALSE |
overdispersion_sd |
Prior standard deviation on 1/overdispersion parameter, Defaults to inv-Cauchy(0,5) |
prior_sd |
Optional prior sd / penalty for fixed effects |
# fit a model with 1 factor #design <- data.frame("fac" = c("spring", "spring", "fall")) #fit <- fit_zoidTMB(formula = ~fac, design_matrix = design, data_matrix = y)
# fit a model with 1 factor #design <- data.frame("fac" = c("spring", "spring", "fall")) #fit <- fit_zoidTMB(formula = ~fac, design_matrix = design, data_matrix = y)
Fit a trinomial mixture model that optionally includes covariates to estimate effects of factor or continuous variables on proportions.
parse_re_formula(formula, data)
parse_re_formula(formula, data)
formula |
The model formula for the design matrix. |
data |
The data matrix used to construct RE design matrix |