new_Confounder: Create a confounder for simulated data

View source: R/PolyMRDataSim_Confounder.R

new_ConfounderR Documentation

Create a confounder for simulated data

Description

This function defines the Confounder class for use with PolyMRDataSim. It is a simplified way to add a confounder to an exposure-outcome pair, i.e. correlated error between two simulated phenotypes.

Usage

new_Confounder(
  sample_size,
  exposure_confounding_function = get_polynomial_function(0.2),
  outcome_confounding_function = get_polynomial_function(0.5)
)

Arguments

sample_size

Sample size of the simulated exposure-outcome data set.

exposure_confounding_function

A function that defines the confounder contribution to the exposure (default is function(x) 0.2*x). The function should accept a vector of confounder values (standardized) and return a vector of values to add to the un-confounded exposure.

outcome_confounding_function

A function that defines the confounder contribution to the outcome (default is function(x) 0.5*x). The function should accept a vector of confounder values (standardized) and return a vector of values to add to the un-confounded outcome.

Value

A list-like object of class Confounder, containing a vector of confounder values (confounder_values) and functions to calculate the confounder contribution to exposure and outcome (respectively exposure_confounding_function and outcome_confounding_function). Given an object polymr_data of class PolyMRDataSim, the confounder can be applied through simple addition, i.e. polymr_data + my_confounder.

Examples

  my_confounder <- new_Confounder(1000,
    exposure_confounding_function = function(x) 0.3*x,
    outcome_confounding_function  = function(x) 0.1*x + 0.05*x^2
  )

JonSulc/PolyMR documentation built on April 26, 2023, 10:42 a.m.