comp_model: Statistical models with compositional exposure variables

View source: R/comp_model.R

comp_modelR Documentation

Statistical models with compositional exposure variables

Description

This is a wrapper for lm, glm and survival::coxph which performs the compositional transformation before generating the model.

Usage

comp_model(
  type = NULL,
  outcome = NULL,
  covariates = NULL,
  comp_labels,
  data,
  follow_up_time = NULL,
  event = NULL,
  rounded_zeroes = TRUE,
  det_limit = NULL,
  part_1 = NULL
)

Arguments

type

Type of statistical model to use. It should be one of "linear", "logistic", "cox".

outcome

Column name of outcome variable in data. If type is "linear", this should be a continuous variable. If type is "logistic", this should be a binary outcome. If type is "cox", if this is set it should be a Surv object from package survival (if it is set, the function defaults to attempt to use it, even if follow_up_time and event are set). If this is left as NULL, follow_up_time and event can be set instead.

covariates

Character vector of column names of covariates to adjust models for. As this is used as a character vector, special arguments to the standard models (like "strata(variable)" for a Cox model) can be used here.

comp_labels

The labels of the compositional columns.

data

Dataset to use for modelling.

follow_up_time

Only used if type is "cox" and outcome is NULL. Follow-up time.

event

Only used if type is "cox" and outcome is NULL.Binary variable indicating whether or not an event was observed.

rounded_zeroes

Are zeroes rounded zeroes?

det_limit

Detection limit if zeroes are to be imputed. This is needed when rounded_zeroes is TRUE. It should be the minimum measurable value in the compositional columns of data, and should be on the same scale as the (input) compositional columns. If rounded_zeroes is TRUE and there are zero values in the data, it throws an error. If the compositional columns do not have a constant sum, it also throws an error, as it cannot be automatically rescaled. Embedded zero imputation is for convenience only. It may be advisable to perform zero imputation prior to working with the data, particularly in more complex cases.

part_1

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

Value

Model using a compositional exposure variable (lm, glm or coxph object as appropriate).

Examples

comp_model(type = "linear",
outcome = "BMI",
covariates = c("agegroup", "sex"),
comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"),
data = simdata,
det_limit = 0.00119)

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