<jupyter_start><jupyter_text>Stratified Analysis: Fluoridated Water and Dental Caries  Summary  Introduction  Analysis<jupyter_code>from opyn.generic.pandasloader import PandasLoader
from opyn.stats import epidemeology as epyn
from pandas.api.types import CategoricalDtype<jupyter_output><empty_output><jupyter_text>Load the data<jupyter_code>f = "dentalcaries"
pdloader = PandasLoader()
# pdloader.get_description(f)
dat = pdloader.get(f)
dat<jupyter_output><empty_output><jupyter_text>Copy the dataframe to preserve the immutable nature of the data, and then recode the `exposure`, `outcome`, and `level` columns as ordered categorical data.<jupyter_code>copieddat = dat.copy(deep=True)
copieddat["exposure"] = copieddat["exposure"].astype(
    CategoricalDtype(["fluoridated", "not fluoridated"], True)
)
copieddat["outcome"] = copieddat["outcome"].astype(
    CategoricalDtype(["no caries", "caries"], True)
)
copieddat["level"] = copieddat["level"].astype(
    CategoricalDtype(["age 8 years", "age 9 years", "age 10 years", "age 11-12 years"], True)
)<jupyter_output><empty_output><jupyter_text>Sort the dataframe to ensure the data is as expected.<jupyter_code>sorteddat = copieddat.sort_values(by=["level", "exposure", "outcome"])
sorteddat<jupyter_output><empty_output><jupyter_text>Extract the `count` column as a `2x2x2` `ndarray`.<jupyter_code>resarr = sorteddat["count"].to_numpy().reshape((4, 2, 2))
resarr<jupyter_output><empty_output><jupyter_text>It is this new reshaped `ndarray` that we will pass to the various functions for analysis.  Stratum-specific odds ratio<jupyter_code>epyn.oddsratio(resarr[0])  # age 8
epyn.oddsratio(resarr[2])  # age 10
epyn.oddsratio(resarr[3])  # age 11-12<jupyter_output><empty_output><jupyter_text>Unadjusted odds ratio<jupyter_code>epyn.crude_oddsratio(resarr)<jupyter_output><empty_output><jupyter_text>Tarone's test of homogeneity<jupyter_code>epyn.test_equalodds(resarr)<jupyter_output><empty_output><jupyter_text>Adjusted odds ratio<jupyter_code>epyn.adjusted_oddsratio(resarr)<jupyter_output><empty_output><jupyter_text>Test of no association<jupyter_code>epyn.test_nullodds(resarr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12165898617511521, 'fraction_numerical': 0.011059907834101382, 'mean_word_length': 9.53883495145631, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '340254', 'license': 'MIT', 'n_tokens_mistral': 823, 'n_tokens_neox': 773, 'n_words': 144, 'path': 'jupyter/1_medical_statistics/1_04_ljk_stratifiedanalysis_dentalcaries.ipynb', 'repo_name': 'ljk233/py_m249', 'size': '2170'}