SAS中Proc logisitc過(guò)程提供了很完善的logistic回歸的分析功能,學(xué)習(xí)R中完成此過(guò)程只是想比較一下兩個(gè)軟件在完成此過(guò)程的差別。雖然有很多帖子介紹如何采用R完成logistic回歸過(guò)程,但是都相對(duì)過(guò)于簡(jiǎn)單,對(duì)于以下常用細(xì)節(jié)很少涉及。
1、模型篩選方法
2、如何簡(jiǎn)單設(shè)定啞變量
3、針對(duì)分類(lèi)變量,如何選取特定水平作為參考水平
4、如何簡(jiǎn)單輸出OR值及置信區(qū)間
5、如何構(gòu)建條件logistic回歸過(guò)程
6、不同模型的預(yù)測(cè)效果比較
雖然之前有很多帖子比較SAS與R的差別,但是多是基于宏觀層面的。通過(guò)比較實(shí)現(xiàn)某一具體過(guò)程的細(xì)微差別,估計(jì)更能體會(huì)兩者的功能差異。
以下是自己學(xué)習(xí)的筆記,附有一些簡(jiǎn)單說(shuō)明,供參考,希望對(duì)大家有幫助
1. library(stats)
2. help(infert) # Description of data
3. infert <- data.frame(infert)
4. str(infert) # Check type of variables
5. summary(infert) # Statistical summary
6.
7. ## Model1 Develop a simple logistic regression:
1. model1 <- glm(case ~ spontaneous+induced, data = infert, family = binomial())
2.
3. ## Model output
4. summary(model1) # Output summary information
5. confint(model1) # Output 95% CI for the coefficients
6. exp(coef(model1)) # Output OR (exponentiated coefficients)
7. exp(confint(model1)) # 95% CI for exponentiated coefficients
8. predict(model1, type="risk") # predicted values
9. residuals(model1, type="deviance") # residuals
10.
11. ## Model2 Develop a logistic regression adjusted for other potential confounders:
1. summary(model1) # Output summary information
2. confint(model1) # Output 95% CI for the coefficients
3. exp(coef(model1)) # Output OR (exponentiated coefficients)
4. exp(confint(model1)) # 95% CI for exponentiated coefficients
5. predict(model1, type="risk") # predicted values
6. residuals(model1, type="deviance") # residuals
7.
8. ## Model2 Develop a logistic regression adjusted for other potential confounders:
9. summary(model4)
10.
11. ## Model5 Conditional logistic regression
12. ## Conduct a subgroup analysis
13. ## "subset" is not aviable for "clogit"
14. ## create the subset first
15.
16. str(infert$education)
17.
18. infert1 <- subset(infert,education =="12+ yrs")
19.
20. model5 <- clogit(case ~ factor(spontaneous)+ factor(induced)+ strata(stratum),
21. data = infert1)
22. summary(model5)
23.
24. ## Model6 General logistic regression








暫無(wú)數(shù)據(jù)