bayesplain.contingency¶
-
bayesplain.contingency(table, prior=
'uninformed', scheme='independent_multinomial', fixed='rows', effect='auto', threshold=None, row_labels=None, col_labels=None, n_draws=None, seed='unset')[source]¶ Test whether the rows and columns of a table are related.
- Parameters:¶
- table : array_like¶
Counts, shape
(R, C). Rows are the groups you sampled; columns are the categories you counted within each group. A pandas crosstab works directly, and its labels are picked up automatically.- prior : str, float, or ConcentrationPrior, default 'uninformed'¶
Dirichlet concentration over the cells. See
bayesplain.priors.describe().- scheme : str, default 'independent_multinomial'¶
Which Gunel-Dickey sampling scheme the study design justifies; one of
bayesplain.core.dirichlet_multinomial.SCHEMES. The default matches “we sampled a fixed number of cases in each group”, which is how planning data is usually gathered. The choice only affects the Bayes factor, never the posterior over the effect size.- fixed : {'rows', 'columns'}, default 'rows'¶
Which margin the design fixed, for the independent-multinomial scheme.
- effect : {'auto', 'cramers_v', 'log_odds_ratio'}, default 'auto'¶
The effect size to put a posterior on.
'auto'uses the log odds ratio for a 2x2 table, where zero means exactly no association, and Cramer’s V otherwise.- threshold : float, optional¶
The value the reported probability is measured against. Defaults to 0 for the log odds ratio and to
SMALL_EFFECT_Vfor Cramer’s V.- row_labels : sequence of str, optional¶
Names for the rows and columns. Read from a pandas object when not supplied.
- col_labels : sequence of str, optional¶
Names for the rows and columns. Read from a pandas object when not supplied.
- n_draws : int, optional¶
Number of draws. Defaults to the package setting.
- seed : int or None, optional¶
Seed for the draws.
- Returns:¶
Call
.summary()for the full report.- Return type:¶
Examples
The doll-preference study of Hraba and Grant (1970), as analysed by Jamil et al. (2017): 62 of 89 African American children preferred a black doll, while 60 of 71 white children preferred a white doll.
>>> import bayesplain as bp >>> res = bp.contingency( ... [[62, 27], [11, 60]], ... row_labels=["Black children", "white children"], ... col_labels=["black doll", "white doll"], ... ) >>> round(res.bayes_factor().log_bf10, 2) 23.03 >>> res.frequentist.pvalue < 0.001 TrueNotes
The Bayes factor is validated against the published values in Jamil et al. (2017) for all four sampling schemes.