epitable: Cross tabulation

View source: R/freq.R

epitableR Documentation

Cross tabulation

Description

Display a cross tabulation of two variables optionally with percentages (global perc or row or col percentages).

Chi Square with associated p.value are calculated. (optionally fisher)

Missing are counted and can optionally be included in the table

If table contain binary variable, then epiorder function is apply on the two variable to get a resulting table compatible with usual epidemiology interpretation. 0/1 variables are transformed into Yes/No and Yes is displayed before No Exposed Cases appear on upper left part of the table.

Usage

epitable(
  data,
  out,
  exp,
  epiorder = TRUE,
  missing = FALSE,
  row = FALSE,
  col = FALSE,
  perc = FALSE,
  fisher = TRUE,
  total = TRUE
)

Arguments

data

The dataframe to be analysed

out

"Outcome", variable or dataframe column name (character string) representing the outcome. Will be displayed in columns in the cross tabulation. Numeric, factors or text formats are supported.

exp

"Exposure" variable or dataframe column name (character string) representing the exposure. Will be displayed in rows in the cross tabulation. Numeric, factors or text formats are supported. Short syntax is available.

epiorder

Boolean. Should data be reordered to respect epi tables? Default to TRUE. (i.e., Yes/No)

missing

Boolean. If FALSE, missing are not included in the table. A summary output of number of missing values is added at the end

row

"Row percentages", boolean. If TRUE, percentages by row are displayed.

col

"Col percentages", boolean. If TRUE, percentages by column are displayed.

perc

"Table percentages", boolean. If TRUE, percentages by cell are displayed.

fisher

Boolean. If TRUE, display the fisher exact probability. Default to TRUE. If the cross tabulation is larger than 2*2, then Fisher is not calculated.

total

Boolean. If TRUE, display marginal total. Default to TRUE.

Details

EPITABLE

Value

An array containing values of

table : The resulting table

rowperc : The optional row percentage

colperc : The optional col percentage

totperc : The optional percentage

chisq : Chi Square value

p : Estimated probability of this distribution

fischer : Exact probability

missing : Number of missing values

Author(s)

Gilles Desve

References

Based on: Epi6 and Stata functionnality, available at https://github.com/.

See Also

freq for frequency distributions

Examples

data <- data.frame(id = 1:10,
                   cases = c(rep(1,3), rep(0,7)),
                   vacc = sample(c(0,1), replace = TRUE, size = 10))
data[8,2]<-NA                    
table(data$cases, data$vacc, useNA = "always")
result <- epitable(data,cases,vacc)
result$table
result$missing
result$chisq
result$fisher

epitable(data,cases,vacc,epiorder=FALSE)
epitable(data,"cases","vacc") 
epitable(data,out=cases,exp=vacc,missing=TRUE) 
epitable(data,out=cases,exp=vacc,row=TRUE) 

data <- data.frame(id = 1:10,
                   cases = c(rep(1,3), rep(0,7)),
                   vacc = sample(c(0,1,2), replace = TRUE, size = 10))
epitable(data,cases,vacc,perc=TRUE)


Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.