Skip to content

Instantly share code, notes, and snippets.

@markziemann
Created September 20, 2020 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markziemann/bfc2c382a3b343e948435a7521488f06 to your computer and use it in GitHub Desktop.
Save markziemann/bfc2c382a3b343e948435a7521488f06 to your computer and use it in GitHub Desktop.
# create the control data
IID <- paste("CTRL",1:20000,sep="")
ctrl <- as.data.frame(IID)
ctrl$GENO <- "AA"
ctrl[19209:19992,2] <- "AC"
ctrl[19993:20000,2] <- "CC"
ctrl$GENO <- as.factor(ctrl$GENO)
ctrl$PHENO <- "CONTROL"
# create the RA data
IID <- paste("RA",1:5500,sep="")
ra <- as.data.frame(IID)
ra$GENO <- "AA"
ra[5070:5491,2] <- "AC"
ra[5492:5500,2] <- "CC"
ra$GENO <- as.factor(ra$GENO)
ra$PHENO <- "CASE"
# merge
dat <- rbind(ctrl,ra)
# classify pheno
dat$newpheno=with(dat,ifelse(PHENO=="CASE",1,0))
# logistic regression (not additive) it calculates the OR separately for Het and Hom
model1=glm(newpheno~GENO,family=binomial(link="logit"),data=dat)
summary(model1)
# plot the data to get a better idea
plot(factor(PHENO)~factor(GENO), data=dat)
# now an additive model - more reasonable for complex disease genetics
dat$genoadd <- with(dat, 0 + 1*(GENO=="AC") + 2*(GENO=="CC"))
model3 <- glm(newpheno~genoadd,family=binomial(link="logit"),data=dat)
summary(model3)
# odds ratio
exp(model3$coefficients[2])
@markziemann
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment