plot_transfers: plot_transfers: Plots model predictions.

View source: R/plot_transfers.R

plot_transfersR Documentation

plot_transfers: Plots model predictions.

Description

Plots model predictions for transfers/substitutions between the named parts.

Usage

plot_transfers(
  from_part,
  to_part,
  model,
  comp_labels,
  terms = TRUE,
  part_1 = NULL,
  yllimit = NULL,
  yulimit = NULL,
  xllimit = NULL,
  xulimit = NULL,
  y_label = NULL,
  plot_log = FALSE,
  lower_quantile = 0.05,
  upper_quantile = 0.95,
  units = "unitless",
  specified_units = NULL,
  fixed_values = NULL,
  granularity = 10000,
  point_specification = ggplot2::geom_point(size = 2),
  error_bar_colour = "grey",
  theme = NULL
)

Arguments

from_part

Should be an element of comp_labels.

to_part

Should be an element of comp_labels.

model

Model to use in estimates/predictions.

comp_labels

The labels of the compositional columns.

terms

Are estimates for differences in outcome associated with differences in compositional variables? If terms = TRUE all estimates and plots will be for difference in outcome associated with differences in the compositional variables. If terms = FALSE, fixed_values is used to set the values of the non-compositional covariates, and outputs are predictions for the outcome based on these values of the non-compositional covariates and the given value of the compositional variables (and confidence intervals include uncertainty due to all variables in the model, not just the compositional variables). Note that for logistic regression models with terms = TRUE estimates are odds ratios; for logistic regression models with terms = FALSE estimates are probabilities (i.e. predictions on the response scale).

part_1

Used with ilr-pivot coordinate transformation to specify which should be first part. Passed to alter_order_comp_labels unless NULL.

yllimit

Lower limit of y-axis shown on plot.

yulimit

Upper limit of y-axis shown on plot.

xllimit

Lower limit of x-axis shown on plot. Should be in same scale as units.

xulimit

Upper limit of x-axis shown on plot. Should be in same scale as units.

y_label

Label for y-axis. "suppressed" is a special value which will result in no label.

plot_log

If this is TRUE, the y-axis will be log-transformed.

lower_quantile

If set, this gives the lower limit of plotting (as a quantile for both variables of interest). In practice, the current behaviour is to calculate the range of both variables between the upper and lower quantile, and use the narrower one.

upper_quantile

If set, this gives the upper limit of plotting (as a quantile for both variables of interest).

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 argument should be set. Note that this doesn't specify the input units, as this is not relevant for any function.

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. c("hr/day", 24)

fixed_values

If terms = FALSE, this gives the fixed values of the non-compositional covariates at which to calculate the prediction. It is generated automatically if not set. It does not usually need setting, and makes no difference to the output if 'terms = TRUE'.

granularity

Does not usually require setting. If set, gives the number of points plotted on the graph. If it is too low, the plot will contain gaps. If it is too high, plotting will be slow.

point_specification

Should be a ggplot2::geom_point object specifying how the points on the graph will be plotted.

error_bar_colour

Should be an R-recognised colour for error bars, specified by name in quotation marks.

theme

Optional theme argument which can be set as a ggplot2::theme object and will control how the plot appears.

Value

Plot with balance of two parts plotted as exposure/ independent variable.

Examples


lm_outcome <- comp_model(type = "linear",
outcome = "BMI",
covariates = c("agegroup", "sex"),
data = simdata,
comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"),
rounded_zeroes = FALSE
)


epicoda::plot_transfers(from_part = "sedentary",
to_part = "moderate",
model = lm_outcome ,
comp_labels =c("vigorous", "moderate", "light", "sedentary", "sleep"),
y_label = "Model-predicted difference in BMI",
units = "hr/day",
terms = TRUE)


OxWearables/epicoda documentation built on Dec. 7, 2022, 9:07 p.m.