tvc: Create a time interaction variable

Description Usage Arguments Details Value See Also Examples

View source: R/smallUtils.R

Description

tvc creates a time interaction variable that can be used in a coxph model (or any other model with time interactions)

Usage

1
tvc(data, b, tvar, tfun = "linear", pow = NULL, vector = FALSE)

Arguments

data

a data frame

b

the non-time interacted variable's name. Either a single value or a vector of variable names can be entered.

tvar

the time variable's name

tfun

function of time that btvc was multiplied by. Default is tfun = "linear". Can also be tfun = 'log' (natural log) and tfun = 'power'. If tfun = 'power' then the pow argument needs to be specified also.

pow

if tfun = 'power', then use pow to specify what power to raise the time interaction to.

vector

logical. Whether or not to return one vector a or a data frame. Can only be used if only one b is included.

Details

Interacts a variable with a specified function of time. Possible functions of time include 'linear', natural 'log', and exponentiated ('power').

Value

a data frame or vector. If a data frame is returned it will include all of the original variables as well as the interactions denoted by a variable name 'bn_tfun', where bn is one variable name from b and tfun as entered into the function.

See Also

SurvExpand, simGG.simtvc, coxsimtvc, survival, and coxph

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Load Golub & Steunenberg (2007) Data
data('GolubEUPData')

# Subset PURELY TO SPEED UP THE EXAMPLE
GolubEUPData <- GolubEUPData[1:500, ]

# Expand data into equally spaced time intervals
GolubEUPData <- SurvExpand(GolubEUPData, GroupVar = 'caseno',
                  Time = 'begin', Time2 = 'end', event = 'event')

# Create natural log time interaction with the qmv variable
GolubEUPData$Lqmv <- tvc(GolubEUPData, b = 'qmv', tvar = 'end', tfun = 'log',
                         vector = TRUE)

# Create interactions for a vector of variables
BaseVars <- c('qmv', 'backlog', 'coop', 'codec', 'qmvpostsea', 'thatcher')

Test <- tvc(GolubEUPData, b = BaseVars, tvar = 'end', tfun = 'log')

simPH documentation built on Jan. 13, 2021, 6:52 a.m.