sim_exposure: Simulate time series of exposure values

Description Usage Arguments Value Examples

View source: R/customizable_functions.R

Description

Simulates a time series of binary or continuous exposure values with or without seasonal trends. It also allows the user to use a custom function for the shape of the exposure trend.

Usage

1
2
3
4
sim_exposure(n, central = NULL, sd = NULL, trend = "no trend",
  slope = 1, amp = 0.6, exposure_type = NULL, start.date = "2001-01-01",
  cust_exp_func = NULL, cust_exp_args = NULL, cust_expdraw = NULL,
  cust_expdraw_args = list())

Arguments

n

A non-negative integer specifying the number of days to simulate.

central

A numeric value specifying the mean probability of exposure (for binary data) or the mean exposure value (for continuous data).

sd

A numeric value giving the standard deviation of the exposure values from the exposure trend line.

trend

A character string that specifies the desired trend function. Options are:

  • "no trend": No trend, either seasonal or long-term (default).

  • "cos1": A seasonal trend only.

  • "cos2": A seasonal trend with variable amplitude across years.

  • "cos3": A seasonal trend with steadily decreasing amplitude over time.

  • "linear": A linear long-term trend with no seasonal trend.

  • "curvilinear": A curved long-term trend with no seasonal trend.

  • "cos1linear": A seasonal trend plus a linear long-term trend.

See the package vignette for examples of the shapes of these trends.

slope

A numeric value specifying the slope of the trend, to be used with trend = "linear" or trend = "cos1linear".

amp

A numeric value specifying the amplitude of the seasonal trend. Must be between -1 and 1.

exposure_type

A character string specifying the type of exposure. Choices are "binary" or "continuous".

start.date

A date of the format "yyyy-mm-dd" from which to begin simulating daily exposures

cust_exp_func

An R object specifying the function to use to generate custom exposure values.

cust_exp_args

A list of arguments used in the user-specified custom function.

cust_expdraw

An R object specifying a user-created function which determines the distribution of random noise off of the trend line. This function must have inputs n and prob for a binary exposure function and inputs n and mean for a continuous exposure function. The custom function must output a vector of simulated exposure values.

cust_expdraw_args

A list of arguments other than n required by the cust_expdraw function.

Value

A data frame with two columns: date (date) and simulated exposure values (x).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sim_exposure(n = 5, central = 0.25, exposure_type = "binary")
sim_exposure(n = 5, central = 100, sd = 10, exposure_type = "continuous")
library(ggplot2)
x_cont <- sim_exposure(n = 1000, central = 100, sd = 10,
                       exposure_type = "continuous",
                       trend = "cos1linear", amp = 0.6)
ggplot(x_cont, aes(x = date, y = x)) + geom_point()
x_cust <- sim_exposure(n = 1000, cust_exp_func = "custom_exposure",
                       cust_exp_args = list(metric = "temp"))
ggplot(x_cust, aes(x = date, y = x)) + geom_point()

eesim documentation built on June 4, 2017, 1:03 a.m.