Learn R Programming

Epi (version 2.16)

addCov.Lexis: Add covariates (typically clinical measurements) taken at known times to a Lexis object.

Description

When follow-up in a multistate model is represented in a Lexis object we may want to add information on covariates, for example clinical measurements, taken at different times. This function cuts the follow-up time (see cutLexis) at the times of measurement and carries the measurements forward in time. Several measurements per person is allowed in which case measurements from one occasion are only carried forward to the next.

Usage

# S3 method for Lexis
addCov(Lx, clin,
                       timeScale = 1,
                       addScales = FALSE,
                       exnam,
                       tfc = "tfc")

Arguments

Lx

A Lexis object with follow-up of a cohort

clin

A data frame with the covariates to add (typically clinical measurements). Must contain a variable lex.id identifying the persons represented in Lx, as well as a variable with the same name as one of the timeScales in Lx, identifying the time at which covariates are measured.

timeScale

Numerical or character. If numerical, the number of a timescale in Lx. The clin data frame must have a variable of this name indicating the time at which the clinical measurements are taken (assumed to be all other variables than lex.id, timeScale and exnam.)

addScales

Logical. Should timescales representing time since each covariate time be added? They will be named paste("tf",exnam). Not implemented, argument ignored.

exnam

Character. Name of the variable in clin with the examination name (such as wave1, wave2 etc.). Must not be repeated within person. Will be carried over to the resulting Lexis object. If omitted, a variable called exnam with values ex.1, ex.2 etc. will be constructed.

tfc

Character (time from covariate). Name of the variable in the result which will contain the time since the most recent covariate date. This is not a time scale as it is reset to 0 at each new covariate time. Also note that this is meaningless if you splitLexis after using addCov.Lexis.

Value

A Lexis object representing the same follow-up as in Lx, with cuts added at the times of examination, and clinical measurements added for all records representing follow-up after the most recent time of measurement.

See Also

cutLexis, mcutLexis, splitLexis, Lexis

Examples

Run this code
# NOT RUN {
# A small bogus cohort
xcoh <- structure( list( id = c("A", "B", "C"),
                      birth = c("1952-07-14", "1954-04-01", "1987-06-10"),
                      entry = c("1965-08-04", "1972-09-08", "1991-12-23"),
                       exit = c("1997-06-27", "1995-05-23", "1998-07-24"),
                       fail = c(1, 0, 1) ),
                     .Names = c("id", "birth", "entry", "exit", "fail"),
                  row.names = c("1", "2", "3"),
                      class = "data.frame" )

# Convert the character dates into numerical variables (fractional years)
xcoh$bt <- cal.yr( xcoh$birth )
xcoh$en <- cal.yr( xcoh$entry )
xcoh$ex <- cal.yr( xcoh$exit  )

# Define as Lexis object with timescales calendar time and age
Lcoh <- Lexis( entry = list( per=en ),
                exit = list( per=ex, age=ex-bt ),
         exit.status = factor( fail, 0:1, c("Alive","Dead") ),
                data = xcoh )
str( Lcoh )
Lx <- Lcoh[,1:7]

# Data frame with clinical examination data, date of examination in
clin <- data.frame( lex.id = c(1,1,3,2),
                       per = c(1977,1971,1996,1990),
                        bp = c(120,140,160,157),
                      chol = c(5,7,8,9) )
Lx
clin 

# Works with time split BEFORE adding clinical data:
Lb <- addCov.Lexis( splitLexis( Lx,
                                time.scale="age",
                                breaks=seq(0,80,5) ),
                    clin,
                    exnam="clX" )
Lb
# With time split AFTER adding clinincal data, variable tfc is meaningless:
La <- splitLexis( addCov.Lexis( Lx,
                                clin,
                                exnam="clX" ),
                  breaks=seq(0,80,5),
                  time.scale="age" )
La
# }

Run the code above in your browser using DataLab