<jupyter_start><jupyter_text>Marital status, Alcohol Consumption and Fatal Car Accidents**Date:** 2021-11-29**Reference:** M249, Book 1, Part 2<jupyter_code>suppressPackageStartupMessages(library(tidyverse))
library(R249)
library(DescTools)<jupyter_output><empty_output><jupyter_text>Summary  Get the data<jupyter_code>(dat <- as_tibble(read.csv(file = "..\\..\\data\\drinkdriving.csv")))<jupyter_output><empty_output><jupyter_text>Prepare the data  Prepare the dataCast the `exposure`, `outcome`, `level` columns to factors.<jupyter_code>labexp <- c("under 100mg", "over 100mg")
labout <- c("control", "case")
lablev <- c("not married", "married")
(sorteddat <- dat %>%
    mutate(exposure = factor(dat$exposure, labexp)) %>%
    mutate(outcome = factor(dat$outcome, labout)) %>%
    mutate(level = factor(dat$level, lablev)) %>%
    arrange(level, exposure, outcome))<jupyter_output><empty_output><jupyter_text>Filter the tibble on each specific `level`, pull the `count` column as a vector and initilise a matrix.Append this new matrix to an array.<jupyter_code>notmarried <- filter(sorteddat, level == "not married") %>%
    pull(count) %>%
    matrix(nrow = 2, ncol = 2, byrow = TRUE, dimnames = list(labexp, labout))
married <- filter(sorteddat, level == "married") %>%
    pull(count) %>%
    matrix(nrow = 2, ncol = 2, byrow = TRUE, dimnames = list(labexp, labout))
datarr <- array(
    c(notmarried, married),
    dim = c(2, 2, 2),
    dimnames = list(labexp, labout, lablev)
)
print(datarr)<jupyter_output>, , not married

            control case
under 100mg      43    5
over 100mg        3   10

, , married

            control case
under 100mg     103    5
over 100mg        5    4<jupyter_text>Stratum-specific odds ratios<jupyter_code># not married
oddsratio(datarr[, , 1])
# married
oddsratio(datarr[, , 2])
oddsratio_crude(datarr)<jupyter_output><empty_output><jupyter_text>Tarone's test for homogeneity<jupyter_code>BreslowDayTest(datarr, correct = TRUE)<jupyter_output><empty_output><jupyter_text>Mantel-Haenszel odds ratio and chi-squared test<jupyter_code>mantelhaen.test(datarr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13883677298311445, 'fraction_numerical': 0.025797373358348967, 'mean_word_length': 5.255131964809384, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '657378', 'license': 'MIT', 'n_tokens_mistral': 832, 'n_tokens_neox': 739, 'n_words': 165, 'path': 'jupyter/1_medical_statistics/1_03_stratifiedanalysis.ipynb', 'repo_name': 'ljk233/R249', 'size': '2132'}