predict_fit_and_ci: Predict fit and confidence interval

View source: R/predict_fit_and_ci.R

predict_fit_and_ciR Documentation

Predict fit and confidence interval

Description

Principally intended as input to forest_plot_examples and plot_transfers.

Usage

predict_fit_and_ci(
  model,
  new_data,
  comp_labels,
  terms = TRUE,
  part_1 = NULL,
  units = "unitless",
  specified_units = NULL,
  fixed_values = NULL
)

Arguments

model

Model to use in estimates/predictions.

new_data

New data 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.

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'.

Details

Note that confidence intervals use the t-distribution with the appropriate degrees of freedom for linear regression, and the z-distribution for logistic and Cox regression, to match the behaviour of summary() for these model objects. As long as there are a reasonable number of samples (at least 30, say) the difference between the two is negligible.

Value

Data frame with estimates/predictions.

Examples

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

old_comp <- comp_mean(simdata,
comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"),
rounded_zeroes = FALSE
)
new_comp <-
change_composition(
 composition = old_comp,
 main_part = "moderate",
 main_change = +0.5,
 comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep")
)

predict_fit_and_ci(model = lm_outcome,
new_data = new_comp,
comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"))

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