View source: R/export-PlottingModels.R
plot_lincombs | R Documentation |
Generates ggplot2 line plots of estimated linear combinations for age, period, and/or cohort effects from an INLA fit, stratified by a factor. Returns a named list of ggplot objects for each requested effect.
plot_lincombs(
inla_fit,
apc_model,
data,
strata_col,
reference_level,
family = NULL,
age_ind = "age",
period_ind = "period",
cohort_ind = "cohort",
age_title = NULL,
period_title = NULL,
cohort_title = NULL,
y_lab = NULL,
age_vals = NULL,
period_vals = NULL,
cohort_vals = NULL,
age_breaks = NULL,
age_limits = NULL,
period_breaks = NULL,
period_limits = NULL,
cohort_breaks = NULL,
cohort_limits = NULL,
PDF_export = FALSE
)
inla_fit |
An object returned by the |
apc_model |
Character string indicating the configuration of shared vs. stratum-specific time effects in the model. |
data |
The data frame used to fit |
strata_col |
Character name of the factor column in |
reference_level |
Character value of |
family |
Optional character; if |
age_ind |
Character name of the age variable in |
period_ind |
Character name of the period variable in |
cohort_ind |
Character name of the cohort variable in |
age_title |
Optional plot title for the age effect. |
period_title |
Optional plot title for the period effect. |
cohort_title |
Optional plot title for the cohort effect. |
y_lab |
Optional y-axis label; if |
age_vals |
Optional numeric vector of x-values for age; defaults to
|
period_vals |
Optional numeric vector of x-values for period; defaults to
|
cohort_vals |
Optional numeric vector of x-values for cohort; defaults to
|
age_breaks |
Optional vector of breaks for the age plot x-axis. |
age_limits |
Optional numeric vector of length 2 giving x-axis limits for age. |
period_breaks |
Optional vector of breaks for the period plot x-axis. |
period_limits |
Optional numeric vector of length 2 giving x-axis limits for period. |
cohort_breaks |
Optional vector of breaks for the cohort plot x-axis. |
cohort_limits |
Optional numeric vector of length 2 giving x-axis limits for cohort. |
PDF_export |
Logical; if |
A named list of ggplot
objects. Elements are
"age"
, "period"
, and/or "cohort"
depending on apc_model
.
if (requireNamespace("INLA", quietly = TRUE)) {
# Load toy dataset
data("toy_data")
# Filter away unobserved cohorts (see plot_missing_data() function):
require(dplyr)
toy_data.f <- toy_data %>% filter(sex == "female") %>% subset(cohort > 1931)
# Load precomputed 'mapc' object
apC_fit.f <- readRDS(system.file("extdata", "quickstart-apC_fit_f.rds", package = "MAPCtools"))
# Extract INLA object:
apC_fit.inla <- apC_fit.f$model_fit
apC_plots <- plot_lincombs(
inla_fit = apC_fit.inla,
apc_model = "apC",
data = toy_data.f,
strata_col = "education",
reference_level = "1",
family = "poisson",
)
# Display the age effect plot
print(apC_plots$age)
# Display the period effect plot
print(apC_plots$period)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.