View source: R/forest_plot_examples.R
forest_plot_comp | R Documentation |
This function takes a named list of compositions, and plots model predictions for each composition. Please note that with the default terms = TRUE
predictions are relative to at the (compositional) mean composition in the data used to create the model. Please note that if there is missing data in the original data (e.g. in covariates or outcomes) this may not be the same as the compositional mean in the original data.
forest_plot_comp( composition_list, model = NULL, models_list = NULL, comp_labels, x_label = NULL, xllimit = NULL, xulimit = NULL, plot_log = FALSE, text_settings = NULL, pred_name = NULL, boxsize = 0.05, terms = TRUE, units = "unitless", specified_units = NULL, part_1 = NULL, fixed_values = NULL, ... )
composition_list |
Named list of compositions. Note each composition should be stored as a data frame. For example, use the output of |
model |
Model to use in estimates/predictions. |
models_list |
If |
comp_labels |
The labels of the compositional columns. |
x_label |
x-axis label. |
xllimit |
Minimum value for x-axis. |
xulimit |
Maximum value for x-axis. |
plot_log |
If this is |
text_settings |
An optional argument to specify text formatting. It should be an |
pred_name |
Name for column of predictions in plot. |
boxsize |
Sets the size of boxes for estimates on the forest plot. |
terms |
Are estimates for differences in outcome associated with differences in compositional variables? If |
units |
What should the units of the compositional variables be in any output? Currently available are "unitless" (where working in terms of proportions), "hr/day", "hr/wk", "min/day", "min/wk" and "specified", in which case the |
specified_units |
If units are being specified via the composition sum, this is where it is done. It should be a vector where the first argument is a string describing the units, and the second argument is the expected sum of a composition e.g. |
part_1 |
Used with ilr-pivot coordinate transformation to specify which should be first part. Passed to |
fixed_values |
If |
... |
Arguments passed on to |
Forest plot showing model predictions.
# Example using a list of models # First we set up composition list df <- as.data.frame(comp_mean(data = simdata, comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"), units = "hr/day", rounded_zeroes = FALSE)) new_comp <- change_composition(composition = df, main_part = "moderate", main_change = +0.5, comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep")) new_comp2 <- change_composition(composition = df, main_part = "sedentary", main_change = -3.5, comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep")) list_for_plot <- list("Extra 0.5 hr/day moderate" = new_comp, "3.5 hr/day less sedentary" = new_comp2) # Then calculate models lm_BMI_unadjusted <- comp_model(type = "linear", outcome = "BMI", data = simdata, comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"), rounded_zeroes = FALSE) lm_BMI_age_group_only <- comp_model(type = "linear", outcome = "BMI", covariates = c("agegroup"), data = simdata, comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"), rounded_zeroes = FALSE) # Finally, plot forest_plot_comp(composition_list = list_for_plot, models_list = list("Unadjusted" = lm_BMI_unadjusted, "Age-adjusted" = lm_BMI_age_group_only), comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.