User Tools

Site Tools


logistic_regression

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
logistic_regression [2024/12/11 11:13] – [coefficient값에 대한 테스트] hkimscillogistic_regression [2024/12/11 11:57] (current) – [exercise: binary IV] hkimscil
Line 559: Line 559:
 ====== exercise: binary IV ====== ====== exercise: binary IV ======
  
 +<code>
 +########################################
 +# exercise
  
 +head(df)
 +table(df)
 +# base 바꾸기
 +df.norm <- df %>% mutate(gene = relevel(gene, ref = "norm"))
 +df.mut <- df %>% mutate(gene = relevel(gene, ref = "mutant"))
 +
 +
 +logm.cancer.gene.1 <- glm(cancer ~ gene, family = binomial, data = df.norm)
 +summary(logm.cancer.gene.1)
 +a <- logm.cancer.gene.1$coefficients[1]
 +b <- logm.cancer.gene.1$coefficients[2]
 +a
 +b
 +a+b
 +# when b = 0; 즉, mutant = 0 일 때
 +# log(odds.norm) = a 이므로
 +# odds.norm = e^a
 +exp(a)
 +# 확인
 +odds(p.can.norm)
 +# odds.mut = e^(a+b)
 +exp(a+b)
 +odds(p.can.mut)
 +# odds.ratio = e^(b)
 +exp(b)
 +odds.ratio(p.can.mut, p.can.norm)
 +
 +
 +logm.cancer.gene.2 <- glm(cancer ~ gene, family = binomial, data = df.mut)
 +summary(logm.cancer.gene.2)
 +a <- logm.cancer.gene.2$coefficients[1]
 +b <- logm.cancer.gene.2$coefficients[2]
 +a
 +b
 +a+b
 +# when b = 0; 즉, mutant = 0 일 때
 +# log(odds.norm) = a 이므로
 +# odds.norm = e^a
 +exp(a)
 +# 확인
 +odds(p.can.mut)
 +# odds.mut = e^(a+b)
 +exp(a+b)
 +odds(p.can.norm)
 +# odds.ratio = e^(b)
 +exp(b)
 +odds.ratio(p.can.norm, p.can.mut)
 +
 +
 +</code>
 ====== X: numeric variable ====== ====== X: numeric variable ======
 <code> <code>
logistic_regression.1733883233.txt.gz · Last modified: 2024/12/11 11:13 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki