constStrata {BuyseTest} | R Documentation |
Create strata from several variables.
constStrata(data, strata, sep = ".", lex.order = FALSE, trace = TRUE, as.numeric = FALSE)
data |
[data.frame] dataset. |
strata |
[character vector] A vector of the variables capturing the stratification factors. |
sep |
[character] string to construct the new level labels by joining the constituent ones. |
lex.order |
[logical] Should the order of factor concatenation be lexically ordered ? |
trace |
[logical] Should the execution of the function be traced ? |
as.numeric |
[logical] Should the strata be converted from factors to numeric? |
This function uses the interaction
function from the base package to form the strata.
A factor vector or a numeric vector.
data(veteran,package="survival") # strata with two variables : celltype and karno veteran$strata1 <- constStrata(veteran,c("celltype","karno")) table(veteran$strata1) # strata with three variables : celltype, karno and age dichotomized at 60 years veteran$age60 <- veteran$age>60 veteran$age60 <- factor(veteran$age60,labels=c("<=60",">60")) # convert to factor with labels veteran$strata2 <- constStrata(veteran,c("celltype","karno","age60")) table(veteran$strata2) # factor strata variable veteran$strata2 <- constStrata(veteran,c("celltype","karno","age60"), as.numeric=TRUE) table(veteran$strata2) # numeric strata variable