Learn R Programming

reporttools (version 1.1.3)

displayCrossTabs: Function to display a set of K x C frequency tables, including p-value

Description

For each column of a dataframe, generate a LaTeX table against a given variable using displayKbyC and add a suitable \(p\)-value: If the expected frequencies are all \(>5\) then a \(\chi^2\)-test is computed, otherwise Fisher's exact test.

Usage

displayCrossTabs(vars, v0, nam0, lab0, 
    percentage = c("none", "row", "col", "total")[1], 
    add.p = TRUE)

Arguments

vars

Dataframe of nominal variables.

v0

Nominal variable to tabulate all columns of vars against.

nam0

Name of v0.

lab0

Initial string for table label. The column number of vars will be added, so that each table has a unique label.

percentage

Add percentages with respect to row, column, or table total.

add.p

Logical. If true, add \(p\)-value as described above.

Value

Displays LaTeX K x C tables and returns a list containing all the information.

Examples

Run this code
# NOT RUN {
set.seed(1977)
v0 <- round(runif(20, 0, 5))
v1 <- round(runif(20, 0, 3))
v2 <- round(runif(20, 0, 4))
displayCrossTabs(vars = data.frame(v1, v2), v0, nam0 = "v0", lab0 = "Q1") 
# }

Run the code above in your browser using DataLab