Created
May 27, 2016 10:11
-
-
Save explodecomputer/d96c87939529efe355af8b5f91631042 to your computer and use it in GitHub Desktop.
matched case control logistic regression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <- 1000 | |
g <- rbinom(n, 2, 0.5) | |
y <- g + rnorm(n) | |
yb <- rep(0, n) | |
yb[y >= median(y)] <- 1 | |
dat <- data.frame(y=y, yb=yb, g=g) | |
dat <- dat[order(dat$yb), ] | |
dat$group <- rep(1:sum(yb==0), 2) | |
# Logistic regression fitting family as random effect | |
library(lme4) | |
model1 <- summary(glmer(yb ~ g + (1|group), family="binomial", data=dat)) | |
# Logistic regression fitting family as fixed effects | |
library(lme4) | |
model2 <- summary(glm(yb ~ g + as.factor(group), family="binomial", data=dat)) | |
# Using conditional logistic regression | |
library(survival) | |
model3 <- summary(clogit(yb ~ g + strata(group), data=dat )) | |
model1 | |
model2 | |
model3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment