Description Usage Arguments Value See Also Examples
The function builds contingency tables: counts and row proportions.
When right-hand side formula contains more than 1 variable,
ctab
builds successive two-way tables, vertically and with same column-variable.
Three types of data are managed by ctab
:
Split individual data;
Grouped data with weights;
Grouped data of form “cbind(success, failure)”.
For grouped data, ctab
uses splitbin
.
1 2 3 4 |
formula |
A 2-sided formula describing the contincency table. The left-hand side represents the column-variable. See examples for syntax. |
data |
A data frame where |
weights |
Variable representing the weight for grouped data with weights. |
digits |
A scalar indicating the number of decimal digits left when rounding the result of the statictics. |
x |
An object of class “ctab”. |
... |
Further arguments to be passed to the functions. |
A list with components CALL
, formula
, f
, tab
, tab.counts
, tab.p
, counts
and digits
.
Component tab
is the basic contingency table.
Component counts
is the corresponding data frame (grouped data with weights).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #=== Example of the 3 types of data managed by ctab
# Split data
tmp <- data.frame(
treatment = c("B", "A", "C", "C", "B", "B", "C", "A", "B", "B", NA, "C"),
surv = c("YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", NA)
)
#tmp$treatment <- factor(tmp$treatment, levels = c("C", "A", "B"))
tmp
ctab(formula = surv ~ 1, data = tmp)
ctab(formula = surv ~ treatment, data = tmp, digits = 1)
# Grouped data with weights
tmp <- data.frame(
treatment = c("A", "B", "C", "A", "B", "C", NA, "C"),
surv = c("NO", "NO", "NO", "YES", "YES", "YES", "NO", NA),
n = c(1, 3, 1, 1, 2, 2, 1, 1)
)
tmp
ctab(formula = surv ~ 1, data = tmp, weights = n)
ctab(formula = surv ~ treatment, data = tmp, weights = n)
# Grouped data of the form "cbind(success, failure)"
tmp <- data.frame(
treatment = c("A", "B", "C", NA),
surv = c(1, 2, 2, 0),
death = c(1, 3, 1, 1)
)
tmp
ctab(formula = cbind(surv, death) ~ 1, data = tmp)
ctab(formula = cbind(surv, death) ~ treatment, data = tmp)
#=== Examples of tables
n <- 80
tmp <- data.frame(
y1 = sample(1:2, n, replace = TRUE),
y2 = sample(1:2, n, replace = TRUE),
y3 = sample(1:3, n, replace = TRUE),
y4 = sample(1:4, n, replace = TRUE)
)
head(tmp)
ctab(formula = y3 ~ 1, data = tmp)
res <- ctab(formula = y3 ~ y1, data = tmp)
res$tab
res$tab.p
ctab(formula = y3 ~ y1 + y2, data = tmp)
ctab(formula = y3 ~ y1 + y2 + y4, data = tmp)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.