Checks for event categories and gives a warning message indicating which level is assumed to be the reference level.

checkArgsEventIndicator(data, event, censored.indicator)

Arguments

data

a data.frame or data.table containing the source dataset.

event

a character string giving the name of the event variable contained in data. See Details. If event is a numeric variable, then 0 needs to represent a censored observation, 1 needs to be the event of interest. Integers 2, 3, ... and so on are treated as competing events. If event is a factor or character and censored.indicator is not specified, this function will assume the reference level is the censored indicator

censored.indicator

a character string of length 1 indicating which value in event is the censored. This function will use relevel to set censored.indicator as the reference level. This argument is ignored if the event variable is a numeric

Value

A list of length two. The first element is the factored event, and the second element is the numeric representation of the event

Examples

if (requireNamespace("survival", quietly = TRUE)) {
library(survival) # for veteran data
checkArgsEventIndicator(data = veteran, event = "celltype",
                        censored.indicator = "smallcell")
checkArgsEventIndicator(data = veteran, event = "status")
}
#> assuming smallcell represents a censored observation and squamous is the event of interest
#> $event.factored
#>   [1] event    event    event    event    event    event    event    event   
#>   [9] event    censored event    event    event    censored event    event   
#>  [17] event    event    event    event    censored censored event    event   
#>  [25] event    event    event    event    event    event    event    event   
#>  [33] event    event    event    event    event    event    event    event   
#>  [41] event    event    event    event    event    event    event    event   
#>  [49] event    event    event    event    event    event    event    event   
#>  [57] event    event    event    event    event    event    event    censored
#>  [65] event    event    event    event    event    event    event    censored
#>  [73] censored event    event    event    event    event    event    event   
#>  [81] event    event    event    event    event    event    event    event   
#>  [89] event    event    censored event    event    event    event    event   
#>  [97] event    event    event    event    event    event    event    event   
#> [105] event    event    event    event    event    censored event    event   
#> [113] event    event    event    event    event    event    event    event   
#> [121] event    event    event    event    event    event    event    event   
#> [129] event    event    event    event    event    event    event    event   
#> [137] event   
#> Levels: censored event
#> 
#> $event.numeric
#>   [1] 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#>  [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1
#>  [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
#> [112] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> 
#> $nLevels
#> [1] 2
#> 
data("bmtcrr") # from casebase
checkArgsEventIndicator(data = bmtcrr, event = "Sex",
                        censored.indicator = "M")
#> assuming M represents a censored observation and F is the event of interest
#> $event.factored
#>   [1] M F M F F M M F M F M M F M M F M M M M F F M M M M F M M F M M F M F M M
#>  [38] M F F M M F M M M M M M M F F F F M F F M F M F M M F M F F M F M M M F F
#>  [75] M M F M M F M F M F F M F M M M F F M M F F M M F F F F F M M F F M F M M
#> [112] M F M F M F M M M M F F M M F M M F M F M F M M M M F M M F M F F F M M M
#> [149] F F M F M F M M M F F M F F M F F M F M M F F M M F M F M
#> Levels: M F
#> 
#> $event.numeric
#>   [1] 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0
#>  [38] 0 1 1 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 0 1 1 0 1 0 0 0 1 1
#>  [75] 0 0 1 0 0 1 0 1 0 1 1 0 1 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 0 1 1 0 1 0 0
#> [112] 0 1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 0 0
#> [149] 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 0 1 0 1 0
#> 
#> $nLevels
#> [1] 2
#> 
checkArgsEventIndicator(data = bmtcrr, event = "D",
                        censored.indicator = "AML")
#> assuming AML represents a censored observation and ALL is the event of interest
#> $event.factored
#>   [1] ALL AML ALL ALL ALL ALL ALL ALL ALL ALL ALL AML AML ALL ALL ALL ALL AML
#>  [19] ALL AML ALL ALL ALL ALL AML ALL ALL AML ALL AML AML AML ALL ALL ALL AML
#>  [37] ALL AML AML ALL AML AML AML AML AML AML ALL AML AML AML AML AML AML ALL
#>  [55] ALL AML ALL AML AML ALL AML ALL AML AML AML AML AML ALL ALL ALL ALL AML
#>  [73] ALL ALL ALL AML AML AML AML ALL AML AML ALL AML ALL AML AML ALL AML AML
#>  [91] AML AML AML AML AML ALL AML ALL ALL ALL AML ALL AML AML ALL AML AML AML
#> [109] AML AML AML AML AML AML AML ALL AML AML ALL ALL ALL AML ALL ALL ALL ALL
#> [127] AML AML AML ALL AML AML AML AML ALL AML AML AML ALL AML AML AML AML ALL
#> [145] AML ALL ALL AML ALL AML ALL AML AML AML AML AML ALL ALL AML AML ALL AML
#> [163] AML AML ALL AML ALL ALL ALL AML AML AML AML AML AML AML AML
#> Levels: AML ALL
#> 
#> $event.numeric
#>   [1] 1 0 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1
#>  [38] 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1
#>  [75] 1 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0
#> [112] 0 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 1 1 0
#> [149] 1 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0
#> 
#> $nLevels
#> [1] 2
#> 
checkArgsEventIndicator(data = bmtcrr, event = "Status")
#> $event.factored
#>   [1] competing event event           censored        competing event
#>   [5] competing event competing event censored        competing event
#>   [9] censored        event           competing event competing event
#>  [13] competing event event           competing event competing event
#>  [17] censored        competing event competing event competing event
#>  [21] event           competing event event           event          
#>  [25] competing event event           event           censored       
#>  [29] event           censored        event           censored       
#>  [33] competing event censored        event           competing event
#>  [37] event           censored        competing event competing event
#>  [41] competing event competing event competing event competing event
#>  [45] event           censored        event           event          
#>  [49] competing event competing event censored        competing event
#>  [53] competing event competing event censored        censored       
#>  [57] competing event event           competing event event          
#>  [61] competing event competing event competing event censored       
#>  [65] censored        event           competing event event          
#>  [69] competing event censored        censored        censored       
#>  [73] competing event event           event           censored       
#>  [77] event           event           censored        competing event
#>  [81] event           event           competing event censored       
#>  [85] event           censored        censored        censored       
#>  [89] competing event event           event           competing event
#>  [93] competing event censored        competing event event          
#>  [97] competing event event           competing event censored       
#> [101] event           censored        competing event censored       
#> [105] competing event event           censored        event          
#> [109] competing event censored        competing event competing event
#> [113] competing event competing event competing event event          
#> [117] competing event event           competing event competing event
#> [121] censored        censored        event           event          
#> [125] event           competing event competing event competing event
#> [129] censored        competing event competing event competing event
#> [133] event           censored        censored        censored       
#> [137] event           competing event event           event          
#> [141] censored        event           competing event censored       
#> [145] event           competing event event           event          
#> [149] event           event           censored        event          
#> [153] competing event competing event competing event competing event
#> [157] event           event           competing event competing event
#> [161] competing event competing event competing event competing event
#> [165] censored        censored        censored        competing event
#> [169] event           censored        event           event          
#> [173] censored        event           censored        censored       
#> [177] event          
#> Levels: censored event competing event
#> 
#> $event.numeric
#>   [1] 2 1 0 2 2 2 0 2 0 1 2 2 2 1 2 2 0 2 2 2 1 2 1 1 2 1 1 0 1 0 1 0 2 0 1 2 1
#>  [38] 0 2 2 2 2 2 2 1 0 1 1 2 2 0 2 2 2 0 0 2 1 2 1 2 2 2 0 0 1 2 1 2 0 0 0 2 1
#>  [75] 1 0 1 1 0 2 1 1 2 0 1 0 0 0 2 1 1 2 2 0 2 1 2 1 2 0 1 0 2 0 2 1 0 1 2 0 2
#> [112] 2 2 2 2 1 2 1 2 2 0 0 1 1 1 2 2 2 0 2 2 2 1 0 0 0 1 2 1 1 0 1 2 0 1 2 1 1
#> [149] 1 1 0 1 2 2 2 2 1 1 2 2 2 2 2 2 0 0 0 2 1 0 1 1 0 1 0 0 1
#> 
#> $nLevels
#> [1] 3
#>