R/expand.covs.R
expand.covs.Rd
Given a competing risks dataset in stacked format, and one or more covariates, this function adds type-specific covariates to the dataset. The original dataset with the type-specific covariates appended is returned.
expand.covs(data, ...)
data | An object of class |
---|---|
... | Further arguments to be passed to or from other methods. They are ignored in this function. |
An data frame object of the same class as the data argument,
containing the design matrix for the type-specific covariates, either on its
own (append
=FALSE
) or appended to the data
(append
=TRUE
).
Type-specific covariates can be used to analyse separate effects on all
event types in a single analysis based on a stacked data set (Putter, Fiocco
& Geskus (2007) and Geskus (2016)). It is only unambiguously defined for
numeric covariates or for explicit codings. Rows that contain the data for
that specific event type have the value copied from the original covariate
in case it is numeric. In all other rows it has the value zero. If the
covariate is a factor, it will be expanded on the design matrix given by
model.matrix
. For standard "treatment
contrasts" this means that dummy variables are created. If the covariate is
a factor, the column name combines the name of the covariate with the
specific event type. If longnames
=TRUE
, both parts are
intersected by the specific labels in the coding. Missing values in the
basic covariates are allowed and result in missing values in the expanded
covariates.
Putter H, Fiocco M, Geskus RB (2007). Tutorial in biostatistics: Competing risks and multi-state models. Statistics in Medicine 26, 2389--2430.
Geskus, Ronald B. (2016). Data Analysis with Competing Risks and Intermediate States. CRC Press, Boca Raton.
Ronald Geskus and Hein Putter H.Putter@lumc.nl
# small data set in stacked format tg <- data.frame(time=c(5,5,1,1,9,9),status=c(1,0,2,2,0,1),failcode=rep(c("I","II"),3), x1=c(1,1,2,2,2,2),x2=c(3,3,2,2,1,1)) tg$x1 <- factor(tg$x1,labels=c("male","female")) # expanded covariates expand.covs(tg,covs=c("x1","x2"))#> time status failcode x1 x2 x1.I x1.II x2.I x2.II #> 1 5 1 I male 3 0 0 3 0 #> 2 5 0 II male 3 0 0 0 3 #> 3 1 2 I female 2 1 0 2 0 #> 4 1 2 II female 2 0 1 0 2 #> 5 9 0 I female 1 1 0 1 0 #> 6 9 1 II female 1 0 1 0 1#> time status failcode x1 x2 x1female.I x1female.II x2.I x2.II #> 1 5 1 I male 3 0 0 3 0 #> 2 5 0 II male 3 0 0 0 3 #> 3 1 2 I female 2 1 0 2 0 #> 4 1 2 II female 2 0 1 0 2 #> 5 9 0 I female 1 1 0 1 0 #> 6 9 1 II female 1 0 1 0 1#> x1.I x1.II x2.I x2.II #> 1 0 0 3 0 #> 2 0 0 0 3 #> 3 1 0 2 0 #> 4 0 1 0 2 #> 5 1 0 1 0 #> 6 0 1 0 1