logistic_regression
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
logistic_regression [2024/12/11 11:13] – [coefficient값에 대한 테스트] hkimscil | logistic_regression [2024/12/11 11:57] (current) – [exercise: binary IV] hkimscil | ||
---|---|---|---|
Line 559: | Line 559: | ||
====== exercise: binary IV ====== | ====== exercise: binary IV ====== | ||
+ | < | ||
+ | ######################################## | ||
+ | # exercise | ||
+ | head(df) | ||
+ | table(df) | ||
+ | # base 바꾸기 | ||
+ | df.norm <- df %>% mutate(gene = relevel(gene, | ||
+ | df.mut <- df %>% mutate(gene = relevel(gene, | ||
+ | |||
+ | |||
+ | 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, | ||
+ | |||
+ | |||
+ | 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, | ||
+ | |||
+ | |||
+ | </ | ||
====== X: numeric variable ====== | ====== X: numeric variable ====== | ||
< | < |
logistic_regression.1733883233.txt.gz · Last modified: 2024/12/11 11:13 by hkimscil