View source: R/export-ModelEstimation.R
fit_all_MAPC | R Documentation |
Fits all configurations of shared vs. stratum-specific time effects:
Shared age and period effects, stratum-specific cohort effects.
Shared age and cohort effects, stratum-specific period effects.
Shared period and cohort effects, stratum-specific age effects.
Shared age effects, stratum-specific period and cohort effects.
Shared period effects, stratum-specific age and cohort effects.
Shared cohort effects, stratum-specific age and period effects.
Uses the fit_MAPC
function.
The multivariate APC model is based on Riebler and Held (2010) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biostatistics/kxp037")}.
For handling complex survey data, we follow Mercer et al. (2014) \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.spasta.2013.12.001")},
implemented using the survey package.
fit_all_MAPC(
data,
response,
family,
stratify_by,
reference_strata = NULL,
age = "age",
period = "period",
grid.factor = 1,
all_models = c("apC", "aPc", "Apc", "aPC", "ApC", "APc"),
extra.fixed = NULL,
extra.random = NULL,
extra.models = NULL,
extra.hyper = NULL,
apc_prior = "rw1",
include.random = FALSE,
binomial.n = NULL,
poisson.offset = NULL,
apc_hyperprior = NULL,
survey.design = NULL,
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE),
track.progress = FALSE,
verbose = FALSE
)
data |
A data frame containing the age, period, response, and stratification variables.
Age and period are assumed to be on the raw scale, not transformed to 1-indexed index columns.
Factor/character columns are handled, as long as they are properly sorted by |
response |
A string naming the response (outcome) variable in |
family |
A string indicating the likelihood family. The default is |
stratify_by |
The column in |
reference_strata |
Level of |
age |
The age column in |
period |
The period column in |
grid.factor |
(Optional) Grid factor, defined as the ratio of age interval width to period interval width; defaults to 1. |
all_models |
(Optional) Character vectors of valid APC-formats (e.g. |
extra.fixed |
(Optional) If desired, the user can specify additional fixed effects to be added. This is passed as a character argument,
specifying the name of the variable to be added. Multiple variables can be added by passing a character vector of names.
Defaults to |
extra.random |
(Optional) If desired, the user can specify additional random effects to be added. This is passed as a character argument,
specifying the name of the variable to be added. Multiple variables can be added by passing a character vector of names.
Defaults to |
extra.models |
(Optional) If the user specifies one or more additional random effects to be added in |
extra.hyper |
(Optional) If the user specifies one or more additional random effects to be added in |
apc_prior |
(Optional) A string specifying the prior for the age, period, and cohort effects (e.g. |
include.random |
(Optional) Logical; if |
binomial.n |
(Optional) For the |
poisson.offset |
(Optional) For the |
apc_hyperprior |
(Optional) If the user wants non-default hyperpriors for the time effects, this can be achieved by passing the entire
prior specification as a string. If e.g. |
survey.design |
(Optional) In the case of complex survey data, explicit handling of unequal sampling probabilities can be required.
The user can pass a |
control.compute |
(Optional) A list of control variables passed to the |
track.progress |
(Optional) Whether to report progress of the estimation of models in the console; defaults to |
verbose |
(Optional) This is argument is passed along to the |
The returned object is of class all_mapc
, which is a container for multiple mapc
model fits (each typically fitted with a different APC formats).
It also contains a model_selection
element, which holds plots summarizing comparative fit metrics (DIC, WAIC and log-scores).
The following S3 methods are available:
print()
: Prints a compact summary for each individual model fit.
summary()
: Calls summary()
on each contained mapc
object, providing detailed posterior summaries.
plot()
: Displays model comparison plots (DIC/WAIC/log-score comparisons).
These methods are intended to streamline multi-model workflows and allow quick comparison of results across model specifications.
A named list of mapc
objects, one for each configuration of shared vs. stratum-specific time effects: APc, ApC, aPC, Apc, aPc, apC.
Rue, H., Martino, S., & Chopin, N. (2009). Approximate Bayesian inference for latent Gaussian models by using Integrated Nested Laplace Approximations. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 71(2), 319-392. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.1467-9868.2008.00700.x")} See also https://www.r-inla.org for more information about the INLA method and software.
fit_MAPC
for fitting a single model (more flexible; can pass your own formula and lincombs),
and the function inla()
from the INLA
package for the estimation machinery.
For complex survey data, see svydesign
for the creation of a survey design object which can be passed to survey.design
.
data("toy_data")
fits <- fit_all_MAPC(
data = toy_data,
response = count,
family = "poisson",
stratify_by = education,
reference_strata = 1,
age = age,
period = period,
apc_prior = "rw2",
include.random = TRUE
)
# Print concise summary of the models and estimation procedure
print(fits)
# Plot comparison plots, based on comparative fit metrics
plot(fits)
# Optional: view full summary of all models (can be long)
# summary(fits)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.