-
Notifications
You must be signed in to change notification settings - Fork 0
/
cci.rmd
138 lines (118 loc) · 4.01 KB
/
cci.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: "logistic regression 실습"
author: "Hyungseok Lee"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## introduction
>A. "cci.csv" file
comorbidities and 1 year mortality in 100 patients
>B. Covariables
* patientID (char3): patients ID
* sex (char1): M0, F1
* agegroup (char2): 0 year = 0, 0-4 year = 1, 5~9 year = 2, 10~14 year = 3, ... over 85 = 18
* DM1 (char1): DM without complications, yes 1, no 0
* DM2 (char1): DM with complications, yes 1, no 0
* PAD (char1): peripheral arterial disease, yes 1, no 0
* CHF (char1): congestive heart failure, yes 1, no 0
* OMI (char1): old myocardial infarction, yes 1, no 0
* COPD (char1): chronic obstructive pulmonary disease, yes 1, no 0
* liver1 (char1): liver disease, mild, yes 1, no 0
* liver2 (char1): liver disease, severe, yes 1, no 0
* CKD (char1): chronic kidney disease, yes 1, no 0
* CVD (char1) cerebrovascular disease, yes 1, no 0
* rheuma (char1): rheumatologic disease, yes 1, no 0
* ulcer (char1): peptic ulcer disease, yes 1, no 0
* dementia (char1): dementia, yes 1, no 0
* mailg (char1): mailgnancy, yes 1, no 0
* meta (char1): metastatic cancer, yes 1, no 0
* hemi (char1): hemiplegia, paraplegia, yes 1, no 0
* HIV (char1): AIDS, yes 1, no 0
* death_1yr (char1): death with in 1 year 1, alive over 1 year 0
>C. baseline characteristics table
>D. logistic regression analysis
## read.csv
```{r}
cci <- read.csv("cci.csv", sep=",", header = T)
dim(cci)
head(cci)
str(cci)
```
### Table1
```{r}
library(moonBook)
table1 <- mytable(death_1yr~.-patientsID, show.total = T, method = 3, max.ylev = 20, data=cci)
table1
```
Table 1 - sex, agegroup, malig, meta - significant in chi square test
```{r}
library(car)
# multicollinerity check
fit <- glm(data = cci, death_1yr~.-patientsID-DM2)
sqrt(vif(fit))>1.4
# dipersion test
fit <- glm(data = cci, death_1yr~.-patientsID-DM2, family = 'binomial')
fit.od <- glm(data = cci, death_1yr~.-patientsID-DM2, family = 'quasibinomial')
pchisq(summary(fit.od)$dispersion * fit$df.residual, fit$df.residual, lower = F)
```
### logistic regression
```{r}
result_glm <- glm(data = cci, death_1yr~.-patientsID-DM2)
summary(result_glm)
```
## variable slection
```{r}
result_glm <- step(result_glm, directon ="backward")
summary(result_glm)
```
names(cci)
## backward, forward selection
```{r}
full.model <-glm(death_1yr~.-patientsID-DM2, data = cci)
reduced.model <- step(full.model, direction = "backward")
min.model <- glm(death_1yr~1, data = cci)
fwd.model <- step(min.model, direction = "forward",
scope = (death_1yr ~ sex+agegroup+DM1+PAD+CHF+OMI+COPD+
liver1+CKD+CVD+rheuma+ulcer+dementia+malig+
meta+hemi+HIV))
summary(reduced.model)
summary(fwd.model)
```
```{r}
library(leaps)
leaps <- regsubsets(death_1yr ~ sex+agegroup+DM1+PAD+CHF+OMI+COPD+
liver1+CKD+CVD+rheuma+ulcer+dementia+malig+
meta+hemi+HIV, data = cci, nbest = 10)
plot(leaps, scale='adjr2', main='Adjusted R^2')
```
## top black : agegroup, OMI, dementia, malig, meta
## logistic regression with agegroup, OMI, dementia, malig, meta
```{r}
result_1 <- glm(data = cci, death_1yr~agegroup+OMI+dementia+malig+meta)
summary(result_1)
```
```{r}
ORtable=function(x,digits=2){
suppressMessages(a<-confint(x))
result=data.frame(exp(coef(x)),exp(a))
result=round(result,digits)
result=cbind(result,round(summary(x)$coefficient[,4],3))
colnames(result)=c("OR","2.5%","97.5%","p")
result
}
exp(result_1$coefficients)
ORtable(result_1)
ORplot(result_1,type=2,show.OR=T,show.CI=T)
```
## check interaction between mailg and meta
```{r}
result_2 <- glm(data = cci, death_1yr~malig*meta+agegroup+OMI+dementia+malig+meta)
summary(result_2)
```