constStrata {BuyseTest}R Documentation

Strata creation

Description

Create strata from several variables.

Usage

constStrata(
  data,
  strata,
  sep = ".",
  lex.order = FALSE,
  trace = TRUE,
  as.numeric = FALSE
)

Arguments

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?

Details

This function uses the interaction function from the base package to form the strata.

Value

A factor vector or a numeric vector.

Author(s)

Brice Ozenne

Examples

library(data.table)

library(survival) ## import veteran
  
# 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


[Package BuyseTest version 2.3.0 Index]