using RCall
R"""
library(tidyverse)
df.forMH <- tribble(
~X, ~L, ~Y, ~n,
0, 0, 0, 325,
0, 0, 1, 273,
0, 1, 0, 324,
0, 1, 1, 363,
1, 0, 0, 292,
1, 0, 1, 321,
1, 1, 0, 278,
1, 1, 1, 323
)
df.MH1 <- uncount(df.forMH, weights = n)
"""
┌ Warning: RCall.jl: -- Attaching packages --------------------------------------- tidyverse 1.3.1 -- │ v ggplot2 3.3.5 v purrr 0.3.4 │ v tibble 3.1.6 v dplyr 1.0.8 │ v tidyr 1.2.0 v stringr 1.4.0 │ v readr 2.1.2 v forcats 0.5.1 │ -- Conflicts ------------------------------------------ tidyverse_conflicts() -- │ x dplyr::filter() masks stats::filter() │ x dplyr::lag() masks stats::lag() └ @ RCall D:\.julia\packages\RCall\6kphM\src\io.jl:172
RObject{VecSxp} # A tibble: 2,499 x 3 X L Y <dbl> <dbl> <dbl> 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0 7 0 0 0 8 0 0 0 9 0 0 0 10 0 0 0 # ... with 2,489 more rows
R"""
library(samplesizeCMH)
partial_tables <- table(df.MH1[,c("X","Y","L")])
partial_tables
"""
RObject{IntSxp} , , L = 0 Y X 0 1 0 325 273 1 292 321 , , L = 1 Y X 0 1 0 324 363 1 278 323
R"""
result_mh <- mantelhaen.test(partial_tables)
"""
RObject{VecSxp} Mantel-Haenszel chi-squared test with continuity correction data: partial_tables Mantel-Haenszel X-squared = 3.319, df = 1, p-value = 0.06848 alternative hypothesis: true common odds ratio is not equal to 1 95 percent confidence interval: 0.9921162 1.3588118 sample estimates: common odds ratio 1.161077
R"""
mantelhaen.test(partial_tables)
library(jtools)
log.model <- glm(Y ~ X + L, data=df.MH1, family = binomial)
result_logistic <- summ(log.model, exp=T, digits=5)
"""
RObject{VecSxp} MODEL INFO: Observations: 2499 Dependent Variable: Y Type: Generalized linear model Family: binomial Link function: logit MODEL FIT: χ²(2) = 7.90056, p = 0.01925 Pseudo-R² (Cragg-Uhler) = 0.00421 Pseudo-R² (McFadden) = 0.00228 AIC = 3460.95990, BIC = 3478.43084 Standard errors: MLE ---------------------------------------------------------------------- exp(Est.) 2.5% 97.5% z val. p ----------------- ----------- --------- --------- ---------- --------- (Intercept) 0.89251 0.77739 1.02469 -1.61387 0.10656 X 1.16124 0.99218 1.35911 1.86222 0.06257 L 1.19097 1.01759 1.39389 2.17714 0.02947 ----------------------------------------------------------------------
R"df_MH1 <- df.MH1"
@rget df_MH1
2,499 rows × 3 columns
X | L | Y | |
---|---|---|---|
Float64 | Float64 | Float64 | |
1 | 0.0 | 0.0 | 0.0 |
2 | 0.0 | 0.0 | 0.0 |
3 | 0.0 | 0.0 | 0.0 |
4 | 0.0 | 0.0 | 0.0 |
5 | 0.0 | 0.0 | 0.0 |
6 | 0.0 | 0.0 | 0.0 |
7 | 0.0 | 0.0 | 0.0 |
8 | 0.0 | 0.0 | 0.0 |
9 | 0.0 | 0.0 | 0.0 |
10 | 0.0 | 0.0 | 0.0 |
11 | 0.0 | 0.0 | 0.0 |
12 | 0.0 | 0.0 | 0.0 |
13 | 0.0 | 0.0 | 0.0 |
14 | 0.0 | 0.0 | 0.0 |
15 | 0.0 | 0.0 | 0.0 |
16 | 0.0 | 0.0 | 0.0 |
17 | 0.0 | 0.0 | 0.0 |
18 | 0.0 | 0.0 | 0.0 |
19 | 0.0 | 0.0 | 0.0 |
20 | 0.0 | 0.0 | 0.0 |
21 | 0.0 | 0.0 | 0.0 |
22 | 0.0 | 0.0 | 0.0 |
23 | 0.0 | 0.0 | 0.0 |
24 | 0.0 | 0.0 | 0.0 |
25 | 0.0 | 0.0 | 0.0 |
26 | 0.0 | 0.0 | 0.0 |
27 | 0.0 | 0.0 | 0.0 |
28 | 0.0 | 0.0 | 0.0 |
29 | 0.0 | 0.0 | 0.0 |
30 | 0.0 | 0.0 | 0.0 |
⋮ | ⋮ | ⋮ | ⋮ |
@rget partial_tables
2×2×2 Array{Int64, 3}: [:, :, 1] = 325 273 292 321 [:, :, 2] = 324 363 278 323