tips:clogit_paired_binary_data
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | tips:clogit_paired_binary_data [2019/07/03 08:12] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Conditional Logistic Regression for Paired Binary Data ===== | ||
+ | This is just a short illustration of how to fit the conditional logistic regression model for paired binary data using various functions, including the '' | ||
+ | |||
+ | Fist, let's create an illustrative dataset: | ||
+ | <code rsplus> | ||
+ | ### number of pairs | ||
+ | n <- 100 | ||
+ | ### create data | ||
+ | ai <- c(rep(0, | ||
+ | bi <- 1-ai | ||
+ | ci <- c(rep(0, | ||
+ | di <- 1-ci | ||
+ | ### change data to long format | ||
+ | event <- c(rbind(ai, | ||
+ | group <- rep(c(1,0), times=n) | ||
+ | id <- rep(1:n, each=2) | ||
+ | </ | ||
+ | |||
+ | Now we can fit the conditional logistic regression model with '' | ||
+ | <code rsplus> | ||
+ | library(survival) | ||
+ | summary(clogit(event ~ group + strata(id))) | ||
+ | </ | ||
+ | Results: | ||
+ | <code output> | ||
+ | Call: | ||
+ | coxph(formula = Surv(rep(1, 200L), event) ~ group + strata(id), | ||
+ | method = " | ||
+ | |||
+ | n= 200, number of events= 90 | ||
+ | |||
+ | coef exp(coef) se(coef) | ||
+ | group 0.8109 | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | exp(coef) exp(-coef) lower .95 upper .95 | ||
+ | group 2.25 | ||
+ | |||
+ | Rsquare= 0.02 (max possible= 0.165 ) | ||
+ | Likelihood ratio test= 3.95 on 1 df, | ||
+ | Wald test = 3.64 on 1 df, | ||
+ | Score (logrank) test = 3.85 on 1 df, | ||
+ | </ | ||
+ | |||
+ | For paired binary data, the same results can be obtained by fitting a mixed-effects logistic regression model: | ||
+ | <code rsplus> | ||
+ | library(lme4) | ||
+ | summary(glmer(event ~ group + (1 | id), family=binomial, | ||
+ | </ | ||
+ | Note that it is necessary to increase the number of quadrature points quite a bit to get sufficient accuracy here. Results: | ||
+ | <code output> | ||
+ | Generalized linear mixed model fit by maximum likelihood (Adaptive Gauss-Hermite Quadrature, nAGQ = 17) [' | ||
+ | | ||
+ | Formula: event ~ group + (1 | id) | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | Scaled residuals: | ||
+ | Min 1Q Median | ||
+ | -1.1703 -0.4314 -0.2876 | ||
+ | |||
+ | Random effects: | ||
+ | | ||
+ | | ||
+ | Number of obs: 200, groups: | ||
+ | |||
+ | Fixed effects: | ||
+ | Estimate Std. Error z value Pr(> | ||
+ | (Intercept) | ||
+ | group | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | Correlation of Fixed Effects: | ||
+ | (Intr) | ||
+ | group -0.555 | ||
+ | </ | ||
+ | |||
+ | We can also use '' | ||
+ | <code rsplus> | ||
+ | library(glmmML) | ||
+ | glmmML(event ~ group, cluster=id, family=binomial, | ||
+ | </ | ||
+ | Results: | ||
+ | <code output> | ||
+ | Call: glmmML(formula = event ~ group, family = binomial, cluster = id, method = " | ||
+ | |||
+ | |||
+ | coef se(coef) | ||
+ | (Intercept) -0.8110 | ||
+ | group 0.8109 | ||
+ | |||
+ | Scale parameter in mixing distribution: | ||
+ | Std. Error: | ||
+ | |||
+ | LR p-value for H_0: sigma = 0: 2.461e-07 | ||
+ | |||
+ | Residual deviance: 247.9 on 197 degrees of freedom | ||
+ | </ | ||
+ | |||
+ | For binary matched pair data, the MLE and corresponding SE can actually be given in closed form (see, for example, Agresti, 2002, // | ||
+ | <code rsplus> | ||
+ | tab <- table(ai, | ||
+ | </ | ||
+ | Then we can obtain the MLE of the log odds ratio with: | ||
+ | <code rsplus> | ||
+ | round(log(tab[2, | ||
+ | </ | ||
+ | <code output> | ||
+ | [1] 0.8109 | ||
+ | </ | ||
+ | And the corresponding SE: | ||
+ | <code rsplus> | ||
+ | round(sqrt(1/ | ||
+ | </ | ||
+ | <code output> | ||
+ | [1] 0.4249 | ||
+ | </ | ||
+ | |||
+ | Finally, let's use '' | ||
+ | <code rsplus> | ||
+ | library(metafor) | ||
+ | rma.glmm(measure=" | ||
+ | </ | ||
+ | <code output> | ||
+ | Fixed-Effects Model (k = 26) | ||
+ | Model Type: Conditional Model with Exact Likelihood | ||
+ | |||
+ | Tests for Heterogeneity: | ||
+ | Wld(df = 25) = NA, p-val = NA | ||
+ | LRT(df = 25) = 32.0966, p-val = 0.1552 | ||
+ | |||
+ | Model Results: | ||
+ | |||
+ | estimate | ||
+ | 0.8109 | ||
+ | |||
+ | --- | ||
+ | Signif. codes: | ||
+ | </ | ||
+ | Results again match what we obtained above. |
tips/clogit_paired_binary_data.txt · Last modified: 2022/08/03 11:31 by Wolfgang Viechtbauer