Learn R Programming

survMisc (version 0.4.6)

tableRhs: Table the outcome against all predictors in a formula

Description

Table the outcome against all predictors in a formula

Usage

tableRhs(formula = y ~ ., data = parent.frame(), return = c("summary",
  "zeros", "zEq", "counts", "all"), nlf = 2)

Arguments

formula
A formula. Works with formulas where the left-hand side is a Surv object describing right-censored data.
data
A data.frame.
return
See Value below.
nlf
Number of levels defining a factor. Predictors with $>nlf$ levels are considered continuous and are not tabulated. Needs to be less than the number of observations (rows) in the model specified by the formula.

Value

    • Ifreturn="summary"(the default), atablewith one row per predictor and three columns:[object Object],[object Object],[object Object]
    Other values return a list of tables. Each element is named after the predictor.
    • Ifreturn="zeros", onetablefor each predictor with a least one zero present. Eachtableshows only those levels of the predictor for which one level of the outcome is zero.
    • Ifreturn="zEq", onetablefor each predictor with a least onezero present or one level which hasequal outcomes. Eachtableshows only those levels where one of the above apply.
    • Ifreturn="counts", eachtablegives the total number of levels where zeros and equal outcomes are present and absent.
    • Ifreturn="all", a list oftables of outcomes foralllevels of each predictor.

Details

Cross-tabulation of outcomes against levels of a predictor. This is a useful step prior to fitting survival models where the outcome has limited values.

Examples

Run this code
set.seed(1)
d1 <- genSurvDf(c=3, rc=0.5, model=FALSE)
tableRhs(Surv(t1, e) ~ ., data=d1, return="summary", nlf=2)
t1 <- tableRhs(Surv(t1, e) ~ ., data=d1, return="c", nlf=99)
### simple graph
p <- par()
par( mfrow=c(2, 2))
for (i in 1:length(t1)){
    graphics::mosaicplot(t1[[i]], main="", cex=1.5)
    title(main=list(names(t1[i]), cex=3))
}
par <- p
set.seed(2)
d1 <- genSurvDf(f=1, n=10, model=FALSE)
t1 <- tableRhs(Surv(t1, e) ~ x1, nlf=9, data=d1)
tableRhs(e ~ x1, nlf=9, r="zEq", data=d1)
tableRhs(e ~ ., nlf=3, r="c", data=d1)

Run the code above in your browser using DataLab