statsmodels.stats.contingency_tables.Table2x2

class statsmodels.stats.contingency_tables.Table2x2(table, shift_zeros=True)[source]

Analyses that can be performed on a 2x2 contingency table.

Parameters:
tablearray_like

A 2x2 contingency table

shift_zerosbool

If true, 0.5 is added to all cells of the table if any cell is equal to zero.

Notes

The inference procedures used here are all based on a sampling model in which the units are independent and identically distributed, with each unit being classified with respect to two categorical variables.

Note that for the risk ratio, the analysis is not symmetric with respect to the rows and columns of the contingency table. The two rows define population subgroups, column 0 is the number of ‘events’, and column 1 is the number of ‘non-events’.

Attributes:
chi2_contribs

Returns the contributions to the chi^2 statistic for independence.

The returned table contains the contribution of each cell to the chi^2 test statistic for the null hypothesis that the rows and columns are independent.

cumulative_log_oddsratios

Returns cumulative log odds ratios.

The cumulative log odds ratios for a contingency table with ordered rows and columns are calculated by collapsing all cells to the left/right and above/below a given point, to obtain a 2x2 table from which a log odds ratio can be calculated.

cumulative_oddsratios

Returns the cumulative odds ratios for a contingency table.

See documentation for cumulative_log_oddsratio.

fittedvalues

Returns fitted cell counts under independence.

The returned cell counts are estimates under a model where the rows and columns of the table are independent.

independence_probabilities

Returns fitted joint probabilities under independence.

The returned table is outer(row, column), where row and column are the estimated marginal distributions of the rows and columns.

local_log_oddsratios

Returns local log odds ratios.

The local log odds ratios are the log odds ratios calculated for contiguous 2x2 sub-tables.

local_oddsratios

Returns local odds ratios.

See documentation for local_log_oddsratios.

log_oddsratio

Returns the log odds ratio for a 2x2 table.

log_oddsratio_se

Returns the standard error for the log odds ratio.

log_riskratio

Returns the log of the risk ratio.

log_riskratio_se

Returns the standard error of the log of the risk ratio.

marginal_probabilities

Estimate marginal probability distributions for the rows and columns.

rowndarray

Marginal row probabilities

colndarray

Marginal column probabilities

oddsratio

Returns the odds ratio for a 2x2 table.

resid_pearson

Returns Pearson residuals.

The Pearson residuals are calculated under a model where the rows and columns of the table are independent.

riskratio

Returns the risk ratio for a 2x2 table.

The risk ratio is calculated with respect to the rows.

standardized_resids

Returns standardized residuals under independence.

Methods

from_data(data[, shift_zeros])

Construct a Table object from data.

homogeneity([method])

Compare row and column marginal distributions.

log_oddsratio_confint([alpha, method])

A confidence level for the log odds ratio.

log_oddsratio_pvalue([null])

P-value for a hypothesis test about the log odds ratio.

log_riskratio_confint([alpha, method])

A confidence interval for the log risk ratio.

log_riskratio_pvalue([null])

p-value for a hypothesis test about the log risk ratio.

oddsratio_confint([alpha, method])

A confidence interval for the odds ratio.

oddsratio_pvalue([null])

P-value for a hypothesis test about the odds ratio.

riskratio_confint([alpha, method])

A confidence interval for the risk ratio.

riskratio_pvalue([null])

p-value for a hypothesis test about the risk ratio.

summary([alpha, float_format, method])

Summarizes results for a 2x2 table analysis.

symmetry([method])

Test for symmetry of a joint distribution.

test_nominal_association()

Assess independence for nominal factors.

test_ordinal_association([row_scores, ...])

Assess independence between two ordinal variables.

Properties

chi2_contribs

Returns the contributions to the chi^2 statistic for independence.

cumulative_log_oddsratios

Returns cumulative log odds ratios.

cumulative_oddsratios

Returns the cumulative odds ratios for a contingency table.

fittedvalues

Returns fitted cell counts under independence.

independence_probabilities

Returns fitted joint probabilities under independence.

local_log_oddsratios

Returns local log odds ratios.

local_oddsratios

Returns local odds ratios.

log_oddsratio

Returns the log odds ratio for a 2x2 table.

log_oddsratio_se

Returns the standard error for the log odds ratio.

log_riskratio

Returns the log of the risk ratio.

log_riskratio_se

Returns the standard error of the log of the risk ratio.

marginal_probabilities

Estimate marginal probability distributions for the rows and columns.

oddsratio

Returns the odds ratio for a 2x2 table.

resid_pearson

Returns Pearson residuals.

riskratio

Returns the risk ratio for a 2x2 table.

standardized_resids

Returns standardized residuals under independence.