Difference between revisions of "Regression Exercise"
From Statistical Genetics Courses
Serveradmin (Talk | contribs) (Created page with "__NOTITLE__ ==Regression exercise== In R: load("dbp.R")<br data-attributes="%20/" />ls()<br data-attributes="%20/" />dbp[1:5,]<br data-attributes="%20/" />#<br data-attribut...") |
Serveradmin (Talk | contribs) (→Regression exercise) |
||
(One intermediate revision by the same user not shown) | |||
Line 3: | Line 3: | ||
In R: | In R: | ||
− | load("dbp.R") | + | load("dbp.R") |
− | + | ls() | |
+ | dbp[1:5,] | ||
+ | # | ||
+ | result.snp12 = glm (affection ~ rs1112, family=binomial("logit"), data=dbp) | ||
+ | print (result.snp12) | ||
+ | print ( class (result.snp12) ) | ||
+ | print ( summary(result.snp12) ) | ||
+ | # | ||
+ | dev.geno = anova (result.snp12, test="Chi") | ||
+ | lrt.pvalue = pchisq(dev.geno[dim(dev.geno)[1],"Deviance"], df=2, ncp=0, FALSE) | ||
+ | print ( lrt.pvalue ) | ||
+ | # | ||
+ | print ( summary(result.snp12)$coefficients ) | ||
+ | snp.beta = summary(result.snp12)$coefficients[2:3,1] | ||
+ | print ( snp.beta ) | ||
+ | print ( exp(snp.beta) ) | ||
+ | ci = confint (result.snp12) | ||
+ | print (ci) | ||
+ | print ( exp(ci) ) | ||
+ | # | ||
+ | snp.data = dbp[,c("affection", "rs1112")] | ||
+ | summary(snp.data) | ||
+ | snp.data[,"rs1112"] <- as.numeric(snp.data[,"rs1112"]) - 1<br />summary(snp.data) | ||
+ | # | ||
+ | result.all = glm (affection ~ rs1112, family=binomial("logit"), data=snp.data) | ||
+ | dev.all = anova (result.all, test="Chi") | ||
+ | summary(result.all) | ||
+ | print(dev.all) | ||
+ | # | ||
+ | snp.data = dbp[,c("affection", "trait","sex", "age", "rs1112", "rs1117")] | ||
+ | summary(snp.data) | ||
+ | snp.data[,"rs1112"] <- as.numeric(snp.data[,"rs1112"]) - 1<br />snp.data[,"rs1117"] <- as.numeric(snp.data[,"rs1117"]) - 1 | ||
+ | # | ||
+ | result.adj = glm (affection ~ sex + rs1112 , family=binomial("logit"), data=snp.data) | ||
+ | summary(result.adj) | ||
+ | # | ||
+ | result.adj = glm (affection ~ age + rs1112 , family=binomial("logit"), data=snp.data) | ||
+ | summary(result.adj) | ||
+ | # | ||
+ | result.adj = glm (affection ~ sex + age + rs1112, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.adj) | ||
+ | # | ||
+ | result.adj = glm (affection ~ rs1117 + rs1112, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.adj) | ||
+ | anova (result.adj, test="Chi") | ||
+ | result.adj = glm (affection ~ rs1112 + rs1117, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.adj) | ||
+ | anova (result.adj, test="Chi") | ||
+ | # | ||
+ | result.adj = lm (trait ~ rs1112, data=snp.data) | ||
+ | summary(result.adj) | ||
+ | result.adj = lm (trait ~ sex + rs1112, data=snp.data) | ||
+ | summary(result.adj) | ||
+ | # | ||
+ | result.inter = glm (affection ~ sex * rs1112, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.inter) | ||
+ | result.inter = glm (affection ~ age * rs1112, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.inter) | ||
+ | # | ||
+ | result.inter = glm (affection ~ rs1112 * rs1117, family=binomial("logit"), data=snp.data) | ||
+ | summary(result.inter) | ||
+ | # | ||
+ | q() |
Latest revision as of 03:30, 8 March 2017
Regression exercise
In R:
load("dbp.R") ls() dbp[1:5,] # result.snp12 = glm (affection ~ rs1112, family=binomial("logit"), data=dbp) print (result.snp12) print ( class (result.snp12) ) print ( summary(result.snp12) ) # dev.geno = anova (result.snp12, test="Chi") lrt.pvalue = pchisq(dev.geno[dim(dev.geno)[1],"Deviance"], df=2, ncp=0, FALSE) print ( lrt.pvalue ) # print ( summary(result.snp12)$coefficients ) snp.beta = summary(result.snp12)$coefficients[2:3,1] print ( snp.beta ) print ( exp(snp.beta) ) ci = confint (result.snp12) print (ci) print ( exp(ci) ) # snp.data = dbp[,c("affection", "rs1112")] summary(snp.data) snp.data[,"rs1112"] <- as.numeric(snp.data[,"rs1112"]) - 1
summary(snp.data) # result.all = glm (affection ~ rs1112, family=binomial("logit"), data=snp.data) dev.all = anova (result.all, test="Chi") summary(result.all) print(dev.all) # snp.data = dbp[,c("affection", "trait","sex", "age", "rs1112", "rs1117")] summary(snp.data) snp.data[,"rs1112"] <- as.numeric(snp.data[,"rs1112"]) - 1
snp.data[,"rs1117"] <- as.numeric(snp.data[,"rs1117"]) - 1 # result.adj = glm (affection ~ sex + rs1112 , family=binomial("logit"), data=snp.data) summary(result.adj) # result.adj = glm (affection ~ age + rs1112 , family=binomial("logit"), data=snp.data) summary(result.adj) # result.adj = glm (affection ~ sex + age + rs1112, family=binomial("logit"), data=snp.data) summary(result.adj) # result.adj = glm (affection ~ rs1117 + rs1112, family=binomial("logit"), data=snp.data) summary(result.adj) anova (result.adj, test="Chi") result.adj = glm (affection ~ rs1112 + rs1117, family=binomial("logit"), data=snp.data) summary(result.adj) anova (result.adj, test="Chi") # result.adj = lm (trait ~ rs1112, data=snp.data) summary(result.adj) result.adj = lm (trait ~ sex + rs1112, data=snp.data) summary(result.adj) # result.inter = glm (affection ~ sex * rs1112, family=binomial("logit"), data=snp.data) summary(result.inter) result.inter = glm (affection ~ age * rs1112, family=binomial("logit"), data=snp.data) summary(result.inter) # result.inter = glm (affection ~ rs1112 * rs1117, family=binomial("logit"), data=snp.data) summary(result.inter) # q()