logistic_regression
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| logistic_regression [2024/12/11 02:14] – [exercise: binary IV] hkimscil | logistic_regression [2024/12/11 02:57] (current) – [exercise: binary IV] hkimscil | ||
|---|---|---|---|
| Line 560: | Line 560: | ||
| < | < | ||
| - | dat | + | ######################################## |
| + | # 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.1733883292.txt.gz · Last modified: by hkimscil
