rtpa=read.csv("C:/Users/MAC/Downloads/thu thap so lieu rtPA 2019(3).csv")
attach(rtpa)
names(rtpa)
##  [1] "id"                  "Hotenbn"             "tel"                
##  [4] "Thangnv"             "mRSxv"               "mRS90"              
##  [7] "mRS90caithien"       "tv9Khong"            "Thangtk"            
## [10] "Toast"               "gioi"                "bddngv"             
## [13] "tuoi"                "cn"                  "cc"                 
## [16] "bmi"                 "Tdieutri"            "Tcuakim"            
## [19] "tha"                 "dtd"                 "rllp"               
## [22] "smoke"               "tsdotquy"            "hattnv"             
## [25] "hattrnv"             "NIHSSnv"             "NIHSS24h"           
## [28] "NIHSSgiam4"          "NIHSSxv"             "mRSnv"              
## [31] "mRSxv.1"             "Glynv"               "rungnhinv"          
## [34] "ASPECTnv"            "dautangquangCT"      "hepmachcKhongynghia"
## [37] "NIHSScaithien"       "xhn"                 "chaymaunhe"         
## [40] "diung"               "tvxv"                "mRS90.1"            
## [43] "mRS90caithien.1"     "tv90"                "X"
summary(rtpa)
##        id                   Hotenbn           tel        Thangnv  
##  Min.   : 1.0   ??ng Th? R?     : 1   không có  : 8   19-Apr :16  
##  1st Qu.:20.5   Châu T Thu Trang: 1             : 3   19-Feb :10  
##  Median :40.0   D? Th? M?i      : 1   377977628 : 2   19-Jul :10  
##  Mean   :40.0   D??ng Ti?n Côn  : 1   `         : 1   19-Jun : 8  
##  3rd Qu.:59.5   D??ng V?n Hòa   : 1   1247926894: 1   19-Mar : 7  
##  Max.   :79.0   Hu?nh T Khiêm   : 1   309973949 : 1   19-Aug : 6  
##                 (Other)         :73   (Other)   :63   (Other):22  
##      mRSxv           mRS90       mRS90caithien     tv9Khong     Thangtk  
##  Min.   :0.000   Min.   :0.000   Min.   :0.0000        :24   19-Jul :15  
##  1st Qu.:1.000   1st Qu.:0.000   1st Qu.:0.0000   Co   : 6   19-May :10  
##  Median :2.000   Median :1.000   Median :1.0000   Khong:49   19-Oct :10  
##  Mean   :2.506   Mean   :1.509   Mean   :0.7091              19-Nov : 8  
##  3rd Qu.:4.000   3rd Qu.:2.500   3rd Qu.:1.0000              19-Sep : 8  
##  Max.   :6.000   Max.   :6.000   Max.   :1.0000              19-Jun : 7  
##                  NA's   :24      NA's   :24                  (Other):21  
##       Toast     gioi        bddngv             tuoi             cn       
##  Khong Xd:35   Nam:47   Min.   :0.00000   Min.   :38.00   Min.   :39.00  
##  MM l?n  :17   Nu :32   1st Qu.:0.00000   1st Qu.:55.00   1st Qu.:53.00  
##  MM nho  :19            Median :0.00000   Median :64.00   Median :58.00  
##  Tim     : 8            Mean   :0.03797   Mean   :62.46   Mean   :58.67  
##                         3rd Qu.:0.00000   3rd Qu.:69.50   3rd Qu.:64.50  
##                         Max.   :1.00000   Max.   :79.00   Max.   :84.00  
##                                                                          
##        cc              bmi        Tdieutri        Tcuakim          tha    
##  Min.   :  1.65          :75   Min.   : 50.0   Min.   : 10.00   Co   :73  
##  1st Qu.:150.00   #DIV/0!: 3   1st Qu.:140.0   1st Qu.: 40.00   Khong: 6  
##  Median :165.00   18     : 1   Median :170.0   Median : 50.00             
##  Mean   :131.33                Mean   :169.8   Mean   : 53.08             
##  3rd Qu.:170.00                3rd Qu.:200.0   3rd Qu.: 60.00             
##  Max.   :170.00                Max.   :328.0   Max.   :130.00             
##  NA's   :74                                                               
##     dtd        rllp      smoke     tsdotquy      hattnv     
##  Co   :13   Co   :34   Co   : 8   Co   :11   Min.   : 90.0  
##  Khong:66   Khong:45   Khong:71   Khong:68   1st Qu.:140.0  
##                                              Median :150.0  
##                                              Mean   :153.8  
##                                              3rd Qu.:160.0  
##                                              Max.   :240.0  
##                                                             
##     hattrnv          NIHSSnv         NIHSS24h      NIHSSgiam4
##  Min.   : 60.00   Min.   : 4.00   Min.   : 0.000   Co   :34  
##  1st Qu.: 80.00   1st Qu.: 6.00   1st Qu.: 2.000   Khong:45  
##  Median : 80.00   Median :10.00   Median : 7.000             
##  Mean   : 85.22   Mean   :11.48   Mean   : 8.215             
##  3rd Qu.: 90.00   3rd Qu.:15.50   3rd Qu.:12.000             
##  Max.   :120.00   Max.   :24.00   Max.   :35.000             
##                                                              
##     NIHSSxv           mRSnv          mRSxv.1          Glynv      
##  Min.   : 0.000   Min.   :2.000   Min.   :0.000   Min.   : 52.0  
##  1st Qu.: 1.000   1st Qu.:3.000   1st Qu.:1.000   1st Qu.: 98.5  
##  Median : 6.000   Median :4.000   Median :2.000   Median :117.0  
##  Mean   : 7.734   Mean   :3.532   Mean   :2.494   Mean   :131.7  
##  3rd Qu.:11.500   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:136.5  
##  Max.   :35.000   Max.   :5.000   Max.   :6.000   Max.   :420.0  
##                                                                  
##  rungnhinv     ASPECTnv      dautangquangCT    hepmachcKhongynghia
##  Co   : 8   Min.   : 7.000   Min.   :0.00000   Co   :18           
##  Khong:71   1st Qu.: 8.000   1st Qu.:0.00000   Khong:61           
##             Median : 9.000   Median :0.00000                      
##             Mean   : 8.722   Mean   :0.03797                      
##             3rd Qu.: 9.500   3rd Qu.:0.00000                      
##             Max.   :10.000   Max.   :1.00000                      
##                                                                   
##  NIHSScaithien    xhn     chaymaunhe   diung       tvxv       mRS90.1   
##  Co   :36      Khong:79   Co   : 6   Khong:79   Co   : 3   Min.   :0.0  
##  Khong:43                 Khong:73              Khong:76   1st Qu.:0.0  
##                                                            Median :1.0  
##                                                            Mean   :0.6  
##                                                            3rd Qu.:1.0  
##                                                            Max.   :1.0  
##                                                            NA's   :74   
##  mRS90caithien.1      tv90             X     
##  Min.   :0.0     Min.   :0.0            :78  
##  1st Qu.:0.0     1st Qu.:0.0   TV th8/19: 1  
##  Median :1.0     Median :0.5                 
##  Mean   :0.6     Mean   :0.5                 
##  3rd Qu.:1.0     3rd Qu.:1.0                 
##  Max.   :1.0     Max.   :1.0                 
##  NA's   :74      NA's   :73
hist(tuoi)

hist(Tdieutri)

hist(Tcuakim)

hist(NIHSSnv)

hist(NIHSS24h)

hist(NIHSSxv)

hist(mRSnv)

hist(mRSxv)

# Kiem dinh phan phoi chuan (p<0.05 --> không  tuân  theo  lu???t  phân  ph???i  chu???n)
shapiro.test(NIHSSnv) 
## 
##  Shapiro-Wilk normality test
## 
## data:  NIHSSnv
## W = 0.86419, p-value = 5.715e-07
summary(NIHSSnv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    4.00    6.00   10.00   11.48   15.50   24.00
summary(NIHSS24h)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   2.000   7.000   8.215  12.000  35.000
summary(NIHSSxv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   1.000   6.000   7.734  11.500  35.000
summary(mRSnv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.000   3.000   4.000   3.532   4.000   5.000
summary(mRSxv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   1.000   2.000   2.506   4.000   6.000
summary(mRS90)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   0.000   1.000   1.509   2.500   6.000      24
# Kiem dinh kg theo pp chuan

wilcox.test(NIHSSnv, NIHSS24h)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  NIHSSnv and NIHSS24h
## W = 4149, p-value = 0.0003407
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(NIHSS24h, NIHSSxv)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  NIHSS24h and NIHSSxv
## W = 3305, p-value = 0.5209
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(NIHSSnv, NIHSSxv)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  NIHSSnv and NIHSSxv
## W = 4323, p-value = 2.788e-05
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(mRSnv, mRSxv)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  mRSnv and mRSxv
## W = 4324, p-value = 1.945e-05
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(mRSxv, mRS90)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  mRSxv and mRS90
## W = 2968.5, p-value = 0.0002503
## alternative hypothesis: true location shift is not equal to 0
boxplot(NIHSSnv, col=c("red", "blue"))  

boxplot(NIHSSnv, NIHSS24h, NIHSSxv, col=c("red", "blue"), xlab= "NIHSS lúc NV, 24h, XV", ylab="Di???m NIHSS")  

# Kiem dinh bat cap
t.test(NIHSSnv, NIHSS24h, paired=TRUE)
## 
##  Paired t-test
## 
## data:  NIHSSnv and NIHSS24h
## t = 5.4173, df = 78, p-value = 6.509e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  2.065648 4.465998
## sample estimates:
## mean of the differences 
##                3.265823
t.test(NIHSSnv, NIHSSxv, paired = TRUE)
## 
##  Paired t-test
## 
## data:  NIHSSnv and NIHSSxv
## t = 5.8394, df = 78, p-value = 1.144e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  2.469421 5.024250
## sample estimates:
## mean of the differences 
##                3.746835
t.test(mRSnv, mRSxv, paired=TRUE)
## 
##  Paired t-test
## 
## data:  mRSnv and mRSxv
## t = 6.2858, df = 78, p-value = 1.736e-08
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.7005793 1.3500536
## sample estimates:
## mean of the differences 
##                1.025316
table(tvxv)
## tvxv
##    Co Khong 
##     3    76
tapply(NIHSSnv, tvxv,mean)
##       Co    Khong 
## 20.00000 11.14474
boxplot(NIHSSnv~ tvxv, xlab = "Tu vong luc xuat vien",ylab = "NIHSS luc nhap vien")

t.test(NIHSSnv ~ tvxv)
## 
##  Welch Two Sample t-test
## 
## data:  NIHSSnv by tvxv
## t = 3.2374, df = 2.2846, p-value = 0.06999
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.614679 19.325205
## sample estimates:
##    mean in group Co mean in group Khong 
##            20.00000            11.14474
# Kiem dinh tvxv
logistic =glm(tvxv ~ tuoi+ gioi+ NIHSSnv+ NIHSSxv+mRSnv, family = "binomial")
summary(logistic)
## 
## Call:
## glm(formula = tvxv ~ tuoi + gioi + NIHSSnv + NIHSSxv + mRSnv, 
##     family = "binomial")
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -2.24775   0.00488   0.01538   0.06868   1.29776  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)  
## (Intercept)  21.7287    11.3568   1.913   0.0557 .
## tuoi         -0.1506     0.1193  -1.262   0.2068  
## gioiNu       -0.8745     1.7490  -0.500   0.6171  
## NIHSSnv       0.2525     0.2627   0.961   0.3364  
## NIHSSxv      -0.5111     0.2824  -1.810   0.0703 .
## mRSnv        -0.7892     1.6448  -0.480   0.6314  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 25.510  on 78  degrees of freedom
## Residual deviance: 10.113  on 73  degrees of freedom
## AIC: 22.113
## 
## Number of Fisher Scoring iterations: 9
## ty le % theo nhom
frequency= table(NIHSSgiam4)
frequency/sum(frequency)
## NIHSSgiam4
##        Co     Khong 
## 0.4303797 0.5696203
summary(NIHSSgiam4)
##    Co Khong 
##    34    45
frequency= table(mRSnv)
frequency=table(mRSnv)
frequency/sum(frequency)
## mRSnv
##         2         3         4         5 
## 0.1518987 0.3417722 0.3291139 0.1772152
summary(mRSnv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.000   3.000   4.000   3.532   4.000   5.000
table(mRSnv)
## mRSnv
##  2  3  4  5 
## 12 27 26 14
frequency= table(mRSxv)
frequency=table(mRSxv)
frequency/sum(frequency)
## mRSxv
##          0          1          2          3          4          5 
## 0.11392405 0.22784810 0.17721519 0.20253165 0.11392405 0.12658228 
##          6 
## 0.03797468
summary(mRSxv)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   1.000   2.000   2.506   4.000   6.000
table(mRSxv)
## mRSxv
##  0  1  2  3  4  5  6 
##  9 18 14 16  9 10  3
frequency=table(mRS90)
frequency/sum(frequency)
## mRS90
##          0          1          2          3          4          5 
## 0.47272727 0.18181818 0.09090909 0.03636364 0.12727273 0.01818182 
##          6 
## 0.07272727
table(mRS90)
## mRS90
##  0  1  2  3  4  5  6 
## 26 10  5  2  7  1  4
### Bang tong hop cac bien
library(table1)
## 
## Attaching package: 'table1'
## The following objects are masked from 'package:base':
## 
##     units, units<-
table1(~ tuoi+gioi+ tha+dtd+rllp+smoke+tsdotquy+ NIHSSnv +Tdieutri+Tcuakim+ Toast+ hattnv+Glynv+ NIHSS24h+mRSnv+mRSxv+NIHSScaithien+chaymaunhe)
Overall
(n=79)
tuoi
Mean (SD) 62.5 (10.5)
Median [Min, Max] 64.0 [38.0, 79.0]
gioi
Nam 47 (59.5%)
Nu 32 (40.5%)
tha
Co 73 (92.4%)
Khong 6 (7.6%)
dtd
Co 13 (16.5%)
Khong 66 (83.5%)
rllp
Co 34 (43.0%)
Khong 45 (57.0%)
smoke
Co 8 (10.1%)
Khong 71 (89.9%)
tsdotquy
Co 11 (13.9%)
Khong 68 (86.1%)
NIHSSnv
Mean (SD) 11.5 (6.22)
Median [Min, Max] 10.0 [4.00, 24.0]
Tdieutri
Mean (SD) 170 (48.8)
Median [Min, Max] 170 [50.0, 328]
Tcuakim
Mean (SD) 53.1 (23.0)
Median [Min, Max] 50.0 [10.0, 130]
Toast
Khong Xd 35 (44.3%)
MM l?n 17 (21.5%)
MM nho 19 (24.1%)
Tim 8 (10.1%)
hattnv
Mean (SD) 154 (29.2)
Median [Min, Max] 150 [90.0, 240]
Glynv
Mean (SD) 132 (60.4)
Median [Min, Max] 117 [52.0, 420]
NIHSS24h
Mean (SD) 8.22 (7.51)
Median [Min, Max] 7.00 [0.00, 35.0]
mRSnv
Mean (SD) 3.53 (0.959)
Median [Min, Max] 4.00 [2.00, 5.00]
mRSxv
Mean (SD) 2.51 (1.69)
Median [Min, Max] 2.00 [0.00, 6.00]
NIHSScaithien
Co 36 (45.6%)
Khong 43 (54.4%)
chaymaunhe
Co 6 (7.6%)
Khong 73 (92.4%)
summary(rtpa)
##        id                   Hotenbn           tel        Thangnv  
##  Min.   : 1.0   ??ng Th? R?     : 1   không có  : 8   19-Apr :16  
##  1st Qu.:20.5   Châu T Thu Trang: 1             : 3   19-Feb :10  
##  Median :40.0   D? Th? M?i      : 1   377977628 : 2   19-Jul :10  
##  Mean   :40.0   D??ng Ti?n Côn  : 1   `         : 1   19-Jun : 8  
##  3rd Qu.:59.5   D??ng V?n Hòa   : 1   1247926894: 1   19-Mar : 7  
##  Max.   :79.0   Hu?nh T Khiêm   : 1   309973949 : 1   19-Aug : 6  
##                 (Other)         :73   (Other)   :63   (Other):22  
##      mRSxv           mRS90       mRS90caithien     tv9Khong     Thangtk  
##  Min.   :0.000   Min.   :0.000   Min.   :0.0000        :24   19-Jul :15  
##  1st Qu.:1.000   1st Qu.:0.000   1st Qu.:0.0000   Co   : 6   19-May :10  
##  Median :2.000   Median :1.000   Median :1.0000   Khong:49   19-Oct :10  
##  Mean   :2.506   Mean   :1.509   Mean   :0.7091              19-Nov : 8  
##  3rd Qu.:4.000   3rd Qu.:2.500   3rd Qu.:1.0000              19-Sep : 8  
##  Max.   :6.000   Max.   :6.000   Max.   :1.0000              19-Jun : 7  
##                  NA's   :24      NA's   :24                  (Other):21  
##       Toast     gioi        bddngv             tuoi             cn       
##  Khong Xd:35   Nam:47   Min.   :0.00000   Min.   :38.00   Min.   :39.00  
##  MM l?n  :17   Nu :32   1st Qu.:0.00000   1st Qu.:55.00   1st Qu.:53.00  
##  MM nho  :19            Median :0.00000   Median :64.00   Median :58.00  
##  Tim     : 8            Mean   :0.03797   Mean   :62.46   Mean   :58.67  
##                         3rd Qu.:0.00000   3rd Qu.:69.50   3rd Qu.:64.50  
##                         Max.   :1.00000   Max.   :79.00   Max.   :84.00  
##                                                                          
##        cc              bmi        Tdieutri        Tcuakim          tha    
##  Min.   :  1.65          :75   Min.   : 50.0   Min.   : 10.00   Co   :73  
##  1st Qu.:150.00   #DIV/0!: 3   1st Qu.:140.0   1st Qu.: 40.00   Khong: 6  
##  Median :165.00   18     : 1   Median :170.0   Median : 50.00             
##  Mean   :131.33                Mean   :169.8   Mean   : 53.08             
##  3rd Qu.:170.00                3rd Qu.:200.0   3rd Qu.: 60.00             
##  Max.   :170.00                Max.   :328.0   Max.   :130.00             
##  NA's   :74                                                               
##     dtd        rllp      smoke     tsdotquy      hattnv     
##  Co   :13   Co   :34   Co   : 8   Co   :11   Min.   : 90.0  
##  Khong:66   Khong:45   Khong:71   Khong:68   1st Qu.:140.0  
##                                              Median :150.0  
##                                              Mean   :153.8  
##                                              3rd Qu.:160.0  
##                                              Max.   :240.0  
##                                                             
##     hattrnv          NIHSSnv         NIHSS24h      NIHSSgiam4
##  Min.   : 60.00   Min.   : 4.00   Min.   : 0.000   Co   :34  
##  1st Qu.: 80.00   1st Qu.: 6.00   1st Qu.: 2.000   Khong:45  
##  Median : 80.00   Median :10.00   Median : 7.000             
##  Mean   : 85.22   Mean   :11.48   Mean   : 8.215             
##  3rd Qu.: 90.00   3rd Qu.:15.50   3rd Qu.:12.000             
##  Max.   :120.00   Max.   :24.00   Max.   :35.000             
##                                                              
##     NIHSSxv           mRSnv          mRSxv.1          Glynv      
##  Min.   : 0.000   Min.   :2.000   Min.   :0.000   Min.   : 52.0  
##  1st Qu.: 1.000   1st Qu.:3.000   1st Qu.:1.000   1st Qu.: 98.5  
##  Median : 6.000   Median :4.000   Median :2.000   Median :117.0  
##  Mean   : 7.734   Mean   :3.532   Mean   :2.494   Mean   :131.7  
##  3rd Qu.:11.500   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:136.5  
##  Max.   :35.000   Max.   :5.000   Max.   :6.000   Max.   :420.0  
##                                                                  
##  rungnhinv     ASPECTnv      dautangquangCT    hepmachcKhongynghia
##  Co   : 8   Min.   : 7.000   Min.   :0.00000   Co   :18           
##  Khong:71   1st Qu.: 8.000   1st Qu.:0.00000   Khong:61           
##             Median : 9.000   Median :0.00000                      
##             Mean   : 8.722   Mean   :0.03797                      
##             3rd Qu.: 9.500   3rd Qu.:0.00000                      
##             Max.   :10.000   Max.   :1.00000                      
##                                                                   
##  NIHSScaithien    xhn     chaymaunhe   diung       tvxv       mRS90.1   
##  Co   :36      Khong:79   Co   : 6   Khong:79   Co   : 3   Min.   :0.0  
##  Khong:43                 Khong:73              Khong:76   1st Qu.:0.0  
##                                                            Median :1.0  
##                                                            Mean   :0.6  
##                                                            3rd Qu.:1.0  
##                                                            Max.   :1.0  
##                                                            NA's   :74   
##  mRS90caithien.1      tv90             X     
##  Min.   :0.0     Min.   :0.0            :78  
##  1st Qu.:0.0     1st Qu.:0.0   TV th8/19: 1  
##  Median :1.0     Median :0.5                 
##  Mean   :0.6     Mean   :0.5                 
##  3rd Qu.:1.0     3rd Qu.:1.0                 
##  Max.   :1.0     Max.   :1.0                 
##  NA's   :74      NA's   :73
table1(~ tha)
Overall
(n=79)
tha
Co 73 (92.4%)
Khong 6 (7.6%)
table1(~hattrnv)
Overall
(n=79)
hattrnv
Mean (SD) 85.2 (11.0)
Median [Min, Max] 80.0 [60.0, 120]
table1(~ Toast)
Overall
(n=79)
Toast
Khong Xd 35 (44.3%)
MM l?n 17 (21.5%)
MM nho 19 (24.1%)
Tim 8 (10.1%)
library(table1)

hist(tuoi, col="blue", border="white") 

hist(tuoi, col="blue", border="white", xlab="Tuoi", ylab="Frequency", main="Phan bo theo do tuoi") 

hist(tuoi, prob=T, col="blue", border="white", xlab="Tuoi", ylab="Frequency", main="Phan bo theo do tuoi") 
lines(density(tuoi), col="red", lwd=2)

hist(NIHSSnv, col="blue", border="white") 

hist(NIHSSnv, col="blue", border="white", xlab="NIHSS lúc NV", ylab="Frequency", main="Phân b??? t??? l??? NIHSS lúc NV") 

hist(NIHSSnv, prob=T, col="blue", border="white", xlab="NIHSS lúc NV", ylab="Frequency", main="Phân b??? t??? l??? NIHSS lúc NV") 
lines(density(NIHSSnv), col="red", lwd=2)

boxplot(tuoi ~ gioi, col=c("red", "blue"))  
boxplot(tuoi ~ gioi, col=c("red", "blue")) 

m0 = lm(tuoi ~ gioi, data=rtpa)
summary(m0)
## 
## Call:
## lm(formula = tuoi ~ gioi, data = rtpa)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -23.617  -7.152   1.383   7.848  17.383 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   61.617      1.537  40.097   <2e-16 ***
## gioiNu         2.070      2.414   0.858    0.394    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 10.54 on 77 degrees of freedom
## Multiple R-squared:  0.00946,    Adjusted R-squared:  -0.003405 
## F-statistic: 0.7353 on 1 and 77 DF,  p-value: 0.3938
boxplot(NIHSSnv ~ NIHSSxv, col=c("red", "blue")) 

boxplot(mRSxv ~ gioi, col=c("red", "blue"))  

boxplot(mRSxv ~ gioi, col=c("red", "blue"), xlab="Gi???i tính", ylab = "Di???m", main="S??? di???m mRS lúc xu???t vi???n theo gi???i")  

###### moi tuong quan mRS XV theo thoi gian dieu tri
plot(Tdieutri~mRSxv)

plot(Tdieutri~mRSxv, pch=16, col="blue")

plot(Tdieutri~mRSxv, pch=16, col="blue", xlab="Di???m mRS xu???t vi???n", ylab="Th???i gian di???u tr???", main="M???i tuong quan gi???a th???i gian di???u tr??? và s??? di???m mRS xu???t vi???n")
abline(lm(Tdieutri~mRSxv), col="red", lwd=2)

plot(Tcuakim~mRSxv)

plot(Tcuakim~mRSxv, pch=16, col="blue", xlab="Di???m mRS xu???t vi???n", ylab="Th???i gian c???a kim", main="M???i tuong quan gi???a th???i gian c???a kim và s??? di???m mRS xu???t vi???n")
abline(lm(Tcuakim~mRSxv), col="red", lwd=2)


library(ggplot2)

p=ggplot(data= rtpa, aes(x=NIHSSnv)) 
p + geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("NIHSSnv")+ylab(("%"))+ggtitle( "M???t d??? phân b??? NIHSSnv")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

##### Ve bieu do
library(ggplot2)
p= ggplot(rtpa, aes(x=Tcuakim))
p= p+ geom_histogram()
p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+theme_replace()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+ theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

summary(Tcuakim)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.00   40.00   50.00   53.08   60.00  130.00
p= ggplot(rtpa, aes(x=Tcuakim))
p= p+ geom_histogram()
p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+theme_replace()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+xlab("Thoi gian cua kim")+ylab(("Tan so"))+ggtitle( "Thoi gian cua kim")+ theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p= ggplot(rtpa, aes(x=mRSxv))
p= p+ geom_histogram()
p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("mRS xu???t vi???n")+ylab(("T??? l???"))+ggtitle( "T??? l??? s??? di???m mRS lúc xu???t vi???n")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("mRS xu???t vi???n")+ylab(("T??? l???"))+ggtitle( "T??? l??? s??? di???m mRS lúc xu???t vi???n")+theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(col="white", fill="blue")+xlab("mRS xu???t vi???n")+ylab(("T??? l???"))+ggtitle( "T??? l??? s??? di???m mRS lúc xu???t vi???n")+theme_replace()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

p+ geom_histogram(aes(fill=..count..), col="white")+scale_fill_gradient("count", low= "green", high="red")+xlab("mRS xu???t vi???n")+ylab("T??? l???")+ ggtitle("Bi???u d??? t??? l??? s??? di???m mRS lúc xu???t vi???n")+ theme_update()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

#### Ve kieu boxplot thoi gian cua kim theo gioi
b= ggplot(rtpa, aes(x=gioi, y=Tcuakim))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi))

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()

#### V??? KI???U boxplot NIHSSnv theo gioi
b= ggplot(rtpa, aes(x=gioi, y=NIHSSnv))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi))

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()

#### V??? KI???U boxplot NIHSS 24 theo gioi
b= ggplot(rtpa, aes(x=gioi, y=NIHSS24h))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi))

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()

#### V??? KI???U boxplot mRSnv theo gioi
b= ggplot(rtpa, aes(x=gioi, y=mRSnv))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi))
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

#### V??? KI???U boxplot mRS nv theo gioi
b= ggplot(rtpa, aes(x=gioi, y=mRSnv))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 1, aes(fill= gioi))
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 1, aes(fill= gioi), outlier.colour="red", outlier.size=3)
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 1, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

b+ geom_boxplot(notch = T, notchwidth = 1, aes(fill= gioi), outlier.colour="red", outlier.size=3)
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 1, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()
## notch went outside hinges. Try setting notch=FALSE.
## notch went outside hinges. Try setting notch=FALSE.

#### V??? KI???U boxplot mRS XV theo gioi
b= ggplot(rtpa, aes(x=gioi, y=mRSxv))
b+ geom_boxplot()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi))

#### outlier màu d???
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

### v??? bieu do n???m + coord_flip()
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ coord_flip()

b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)

## v??? bd c??? di???n BW
b+ geom_boxplot(notch = T, notchwidth = 0.5, aes(fill= gioi), outlier.colour="red", outlier.size=3)+ theme_replace()+theme_update()

head(rtpa)
##   id          Hotenbn       tel Thangnv mRSxv mRS90 mRS90caithien tv9Khong
## 1  1     Tr?n V Quang 983373643  18-Nov     2     0             1    Khong
## 2  2 Ph?m T Li?u Th?m 395593559  18-Dec     2     2             0    Khong
## 3  3    Nguy?n V K?nh 384749610  18-Dec     0     0             0    Khong
## 4  4   D??ng Ti?n Côn 948443123  18-Dec     0     0             0    Khong
## 5  5       Lê V C??ng 945525663  18-Dec     3     2             1    Khong
## 6  6     Nguy?n T Von            19-Jan     2    NA            NA         
##   Thangtk    Toast gioi bddngv tuoi cn   cc     bmi Tdieutri Tcuakim   tha
## 1  19-Feb   MM l?n  Nam      0   51 50 1.65      18      180     130 Khong
## 2  19-Mar   MM nho   Nu      0   68 52   NA #DIV/0!      120      60    Co
## 3  19-Feb Khong Xd  Nam      0   66 66   NA #DIV/0!      200      20    Co
## 4  19-Feb   MM nho  Nam      0   46 68   NA #DIV/0!      180      76    Co
## 5  19-Feb   MM nho  Nam      0   75 54   NA              165      55    Co
## 6  19-Apr Khong Xd   Nu      0   73 58   NA              105      45    Co
##     dtd  rllp smoke tsdotquy hattnv hattrnv NIHSSnv NIHSS24h NIHSSgiam4
## 1 Khong Khong Khong    Khong    150      80       8        7      Khong
## 2 Khong    Co Khong       Co    130      80       9        1         Co
## 3 Khong Khong    Co    Khong    160      90       5        0         Co
## 4 Khong    Co    Co    Khong    210     100       6        0         Co
## 5 Khong Khong Khong    Khong    140      70       6        6      Khong
## 6    Co Khong Khong    Khong    160      90       5        2         Co
##   NIHSSxv mRSnv mRSxv.1 Glynv rungnhinv ASPECTnv dautangquangCT
## 1       7     2       2   138     Khong       10              0
## 2       1     4       2   112     Khong       10              0
## 3       0     2       0    91     Khong        9              0
## 4       0     3       0   128     Khong       10              0
## 5       6     3       3   150     Khong        7              0
## 6       2     2       2   281     Khong        8              0
##   hepmachcKhongynghia NIHSScaithien   xhn chaymaunhe diung  tvxv mRS90.1
## 1               Khong         Khong Khong      Khong Khong Khong      NA
## 2               Khong            Co Khong      Khong Khong Khong      NA
## 3               Khong            Co Khong      Khong Khong Khong       0
## 4               Khong            Co Khong      Khong Khong Khong       0
## 5               Khong         Khong Khong      Khong Khong Khong      NA
## 6               Khong         Khong Khong         Co Khong Khong      NA
##   mRS90caithien.1 tv90         X
## 1              NA   NA          
## 2              NA    0 TV th8/19
## 3               0    0          
## 4               0    0          
## 5              NA   NA          
## 6              NA   NA
summary(rtpa)
##        id                   Hotenbn           tel        Thangnv  
##  Min.   : 1.0   ??ng Th? R?     : 1   không có  : 8   19-Apr :16  
##  1st Qu.:20.5   Châu T Thu Trang: 1             : 3   19-Feb :10  
##  Median :40.0   D? Th? M?i      : 1   377977628 : 2   19-Jul :10  
##  Mean   :40.0   D??ng Ti?n Côn  : 1   `         : 1   19-Jun : 8  
##  3rd Qu.:59.5   D??ng V?n Hòa   : 1   1247926894: 1   19-Mar : 7  
##  Max.   :79.0   Hu?nh T Khiêm   : 1   309973949 : 1   19-Aug : 6  
##                 (Other)         :73   (Other)   :63   (Other):22  
##      mRSxv           mRS90       mRS90caithien     tv9Khong     Thangtk  
##  Min.   :0.000   Min.   :0.000   Min.   :0.0000        :24   19-Jul :15  
##  1st Qu.:1.000   1st Qu.:0.000   1st Qu.:0.0000   Co   : 6   19-May :10  
##  Median :2.000   Median :1.000   Median :1.0000   Khong:49   19-Oct :10  
##  Mean   :2.506   Mean   :1.509   Mean   :0.7091              19-Nov : 8  
##  3rd Qu.:4.000   3rd Qu.:2.500   3rd Qu.:1.0000              19-Sep : 8  
##  Max.   :6.000   Max.   :6.000   Max.   :1.0000              19-Jun : 7  
##                  NA's   :24      NA's   :24                  (Other):21  
##       Toast     gioi        bddngv             tuoi             cn       
##  Khong Xd:35   Nam:47   Min.   :0.00000   Min.   :38.00   Min.   :39.00  
##  MM l?n  :17   Nu :32   1st Qu.:0.00000   1st Qu.:55.00   1st Qu.:53.00  
##  MM nho  :19            Median :0.00000   Median :64.00   Median :58.00  
##  Tim     : 8            Mean   :0.03797   Mean   :62.46   Mean   :58.67  
##                         3rd Qu.:0.00000   3rd Qu.:69.50   3rd Qu.:64.50  
##                         Max.   :1.00000   Max.   :79.00   Max.   :84.00  
##                                                                          
##        cc              bmi        Tdieutri        Tcuakim          tha    
##  Min.   :  1.65          :75   Min.   : 50.0   Min.   : 10.00   Co   :73  
##  1st Qu.:150.00   #DIV/0!: 3   1st Qu.:140.0   1st Qu.: 40.00   Khong: 6  
##  Median :165.00   18     : 1   Median :170.0   Median : 50.00             
##  Mean   :131.33                Mean   :169.8   Mean   : 53.08             
##  3rd Qu.:170.00                3rd Qu.:200.0   3rd Qu.: 60.00             
##  Max.   :170.00                Max.   :328.0   Max.   :130.00             
##  NA's   :74                                                               
##     dtd        rllp      smoke     tsdotquy      hattnv     
##  Co   :13   Co   :34   Co   : 8   Co   :11   Min.   : 90.0  
##  Khong:66   Khong:45   Khong:71   Khong:68   1st Qu.:140.0  
##                                              Median :150.0  
##                                              Mean   :153.8  
##                                              3rd Qu.:160.0  
##                                              Max.   :240.0  
##                                                             
##     hattrnv          NIHSSnv         NIHSS24h      NIHSSgiam4
##  Min.   : 60.00   Min.   : 4.00   Min.   : 0.000   Co   :34  
##  1st Qu.: 80.00   1st Qu.: 6.00   1st Qu.: 2.000   Khong:45  
##  Median : 80.00   Median :10.00   Median : 7.000             
##  Mean   : 85.22   Mean   :11.48   Mean   : 8.215             
##  3rd Qu.: 90.00   3rd Qu.:15.50   3rd Qu.:12.000             
##  Max.   :120.00   Max.   :24.00   Max.   :35.000             
##                                                              
##     NIHSSxv           mRSnv          mRSxv.1          Glynv      
##  Min.   : 0.000   Min.   :2.000   Min.   :0.000   Min.   : 52.0  
##  1st Qu.: 1.000   1st Qu.:3.000   1st Qu.:1.000   1st Qu.: 98.5  
##  Median : 6.000   Median :4.000   Median :2.000   Median :117.0  
##  Mean   : 7.734   Mean   :3.532   Mean   :2.494   Mean   :131.7  
##  3rd Qu.:11.500   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:136.5  
##  Max.   :35.000   Max.   :5.000   Max.   :6.000   Max.   :420.0  
##                                                                  
##  rungnhinv     ASPECTnv      dautangquangCT    hepmachcKhongynghia
##  Co   : 8   Min.   : 7.000   Min.   :0.00000   Co   :18           
##  Khong:71   1st Qu.: 8.000   1st Qu.:0.00000   Khong:61           
##             Median : 9.000   Median :0.00000                      
##             Mean   : 8.722   Mean   :0.03797                      
##             3rd Qu.: 9.500   3rd Qu.:0.00000                      
##             Max.   :10.000   Max.   :1.00000                      
##                                                                   
##  NIHSScaithien    xhn     chaymaunhe   diung       tvxv       mRS90.1   
##  Co   :36      Khong:79   Co   : 6   Khong:79   Co   : 3   Min.   :0.0  
##  Khong:43                 Khong:73              Khong:76   1st Qu.:0.0  
##                                                            Median :1.0  
##                                                            Mean   :0.6  
##                                                            3rd Qu.:1.0  
##                                                            Max.   :1.0  
##                                                            NA's   :74   
##  mRS90caithien.1      tv90             X     
##  Min.   :0.0     Min.   :0.0            :78  
##  1st Qu.:0.0     1st Qu.:0.0   TV th8/19: 1  
##  Median :1.0     Median :0.5                 
##  Mean   :0.6     Mean   :0.5                 
##  3rd Qu.:1.0     3rd Qu.:1.0                 
##  Max.   :1.0     Max.   :1.0                 
##  NA's   :74      NA's   :73
# môi tuong quan NIHSSnv va mRSxv
p = ggplot(data=rtpa, aes(x=NIHSSnv, y=mRSxv))
p1 = p + geom_boxplot()
p2 = p + geom_point() + geom_smooth()
library(gridExtra) 
grid.arrange(p1, p2, ncol=2)
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

p = ggplot(data=rtpa, aes(x=NIHSS24h, y=mRSxv))
p1 = p + geom_boxplot()
p2 = p + geom_point() + geom_smooth()
grid.arrange(p1, p2, ncol=2)
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

p = ggplot(data=rtpa, aes(x=mRSnv, y=mRSnv))
p1 = p + geom_boxplot()
p2 = p + geom_point() + geom_smooth()
library(gridExtra) 
grid.arrange(p1, p2, ncol=2)
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at 1.985
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 2.015
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 2.0227e-016
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 4.0602
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
## at 1.985
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
## 2.015
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : reciprocal
## condition number 2.0227e-016
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : There are other
## near singularities as well. 4.0602

p = ggplot(data=rtpa, aes(x=tuoi, y=mRSxv))
p1 = p + geom_point() + geom_smooth() 
p2 = p + geom_point() + geom_smooth(method="lm", formula=y~x+I(x^2)+I(x^3))
grid.arrange(p1, p2, ncol=2)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

# tuong quan da bien
# Bi???n c???n th??? hi???n 
#vars= rtpa[, c("gioi", "tuoi", "Tdieutri", "Tcuakim", "NIHSSxv", "mRSvx", "ASPECTnv")]
# vars = rtpa[, c("gioi", "tuoi", "Tdieutri", "Tcuakim", "NIHSSxv", "mRSvx", "ASPECTnv")] 
# V??? bi???u d??? tuong quan 
library(GGally) 
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
#ggpairs(data=rtpa, mapping = aes(color = gioi))
#summary(rtpa)
# Mói tuong quan da bi???n [lo???i b??? 2 bi???n s??? 1 và 2 (id, gender)]
dat = rtpa[, -c(1,2)] 
library("GGally")
ggcorr(dat, label=T)
## Warning in ggcorr(dat, label = T): data in column(s) 'tel', 'Thangnv',
## 'tv9Khong', 'Thangtk', 'Toast', 'gioi', 'bmi', 'tha', 'dtd', 'rllp',
## 'smoke', 'tsdotquy', 'NIHSSgiam4', 'rungnhinv', 'hepmachcKhongynghia',
## 'NIHSScaithien', 'xhn', 'chaymaunhe', 'diung', 'tvxv', 'X' are not numeric
## and were ignored
## Warning in cor(data, use = method[1], method = method[2]): the standard
## deviation is zero

#ggpairs(rtpa)

dat = rtpa[, -c(1,2)]
library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
#pairs.panels(dat)

 #???nh hu???ng c???a tu???i mRSvx ?
  m1 = lm(mRSxv ~ tuoi, data=rtpa)
summary(m1)
## 
## Call:
## lm(formula = mRSxv ~ tuoi, data = rtpa)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -2.666 -1.450 -0.176  1.180  3.853 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.70545    1.14335   0.617    0.539
## tuoi         0.02883    0.01806   1.597    0.114
## 
## Residual standard error: 1.677 on 77 degrees of freedom
## Multiple R-squared:  0.03206,    Adjusted R-squared:  0.01949 
## F-statistic:  2.55 on 1 and 77 DF,  p-value: 0.1144
#Khác bi???t v??? mRSxv nam và n??? ?
  m2 = lm(mRSxv~ gioi, data=rtpa)
summary(m2)
## 
## Call:
## lm(formula = mRSxv ~ gioi, data = rtpa)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8750 -1.2553 -0.2553  1.1250  3.7447 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.2553     0.2446   9.222 4.48e-14 ***
## gioiNu        0.6197     0.3842   1.613    0.111    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.677 on 77 degrees of freedom
## Multiple R-squared:  0.03267,    Adjusted R-squared:  0.02011 
## F-statistic: 2.601 on 1 and 77 DF,  p-value: 0.1109
# ==> N??? có mRSxv l???n hon nam 25% (SE 0.4%%), và s??? khác bi???t này có ý nghia th???ng kê (P < 0.0001)
m3=lm(Tcuakim ~ mRSxv, data=rtpa)
summary(m3)
## 
## Call:
## lm(formula = Tcuakim ~ mRSxv, data = rtpa)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -41.366 -14.136  -3.636   8.864  77.499 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   50.231      4.652  10.798   <2e-16 ***
## mRSxv          1.135      1.541   0.737    0.464    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 23.05 on 77 degrees of freedom
## Multiple R-squared:  0.006998,   Adjusted R-squared:  -0.005898 
## F-statistic: 0.5426 on 1 and 77 DF,  p-value: 0.4636
# mRSxv tang, thoi gian cua kim tang 0.76% (SE 1.69), và m???i liên quan này có ý nghia th???ng kê (P < 0.0001)
m3=lm(Tcuakim ~ mRSxv, data=rtpa)
plot(rtpa$Tcuakim ~rtpa$mRSxv, pch=16, col="blue")
abline(m3, col="red")

# Kiem tra gia d???nh mo hinh
m3=lm(mRSxv ~ NIHSSnv, data=rtpa)
library(ggfortify)
autoplot(m3)

# Phan tich don bi???n
summary(lm(mRSxv~NIHSSnv), data=rtpa)
## 
## Call:
## lm(formula = mRSxv ~ NIHSSnv)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.3443 -1.0825  0.0047  1.0504  2.9770 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.82072    0.34089   2.408   0.0185 *  
## NIHSSnv      0.14682    0.02615   5.615 2.98e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.436 on 77 degrees of freedom
## Multiple R-squared:  0.2905, Adjusted R-squared:  0.2813 
## F-statistic: 31.53 on 1 and 77 DF,  p-value: 2.98e-07
summary(lm(mRSxv~ NIHSS24h), data= rtpa)
## 
## Call:
## lm(formula = mRSxv ~ NIHSS24h)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.6587 -0.4207 -0.1054  0.5793  1.9238 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.9113     0.1453   6.271 1.93e-08 ***
## NIHSS24h      0.1942     0.0131  14.825  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8683 on 77 degrees of freedom
## Multiple R-squared:  0.7405, Adjusted R-squared:  0.7372 
## F-statistic: 219.8 on 1 and 77 DF,  p-value: < 2.2e-16
summary(lm(mRSxv~ NIHSSxv), data= rtpa)
## 
## Call:
## lm(formula = mRSxv ~ NIHSSxv)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.8910 -0.4475 -0.1513  0.4663  1.8361 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.97893    0.12423    7.88 1.73e-11 ***
## NIHSSxv      0.19749    0.01146   17.23  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7736 on 77 degrees of freedom
## Multiple R-squared:  0.794,  Adjusted R-squared:  0.7914 
## F-statistic: 296.9 on 1 and 77 DF,  p-value: < 2.2e-16
summary(lm(mRSxv~ mRSnv), data= rtpa)
## 
## Call:
## lm(formula = mRSxv ~ mRSnv)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.93589 -1.01872  0.06411  1.06411  3.06411 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -0.7328     0.6295  -1.164    0.248    
## mRSnv         0.9172     0.1721   5.329 9.52e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.457 on 77 degrees of freedom
## Multiple R-squared:  0.2695, Adjusted R-squared:   0.26 
## F-statistic:  28.4 on 1 and 77 DF,  p-value: 9.521e-07
# phan tich da bien

m4 = lm(mRSxv ~ NIHSSnv+ NIHSS24h +mRSnv, data=rtpa)
summary(m4)
## 
## Call:
## lm(formula = mRSxv ~ NIHSSnv + NIHSS24h + mRSnv, data = rtpa)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.63870 -0.36748  0.02531  0.56683  1.77765 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.39576    0.39599   0.999  0.32080    
## NIHSSnv     -0.08207    0.02847  -2.883  0.00514 ** 
## NIHSS24h     0.21581    0.01787  12.075  < 2e-16 ***
## mRSnv        0.36239    0.15893   2.280  0.02544 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8334 on 75 degrees of freedom
## Multiple R-squared:  0.7672, Adjusted R-squared:  0.7579 
## F-statistic: 82.39 on 3 and 75 DF,  p-value: < 2.2e-16
# giai thich
#mRSxv=0.39-0.08NIHSSSnv+0.21NIHSS24h+0.36mRSnv
# moi diem NIHSSnv giam co lien quan den 8% giam diem mRSxv
# moi diem NIHSS24h tang co lien quan den 21% tang diem mRSxv,
# moi diem mRSnv tang co lq den 36% tang diem mRSxv. 
# Ba yeu to NIHSSnv, NIHSS24h, mRSnv giai thich 76% khac biet ve mRSxv giua cac bn.
summary(rtpa)
##        id                   Hotenbn           tel        Thangnv  
##  Min.   : 1.0   ??ng Th? R?     : 1   không có  : 8   19-Apr :16  
##  1st Qu.:20.5   Châu T Thu Trang: 1             : 3   19-Feb :10  
##  Median :40.0   D? Th? M?i      : 1   377977628 : 2   19-Jul :10  
##  Mean   :40.0   D??ng Ti?n Côn  : 1   `         : 1   19-Jun : 8  
##  3rd Qu.:59.5   D??ng V?n Hòa   : 1   1247926894: 1   19-Mar : 7  
##  Max.   :79.0   Hu?nh T Khiêm   : 1   309973949 : 1   19-Aug : 6  
##                 (Other)         :73   (Other)   :63   (Other):22  
##      mRSxv           mRS90       mRS90caithien     tv9Khong     Thangtk  
##  Min.   :0.000   Min.   :0.000   Min.   :0.0000        :24   19-Jul :15  
##  1st Qu.:1.000   1st Qu.:0.000   1st Qu.:0.0000   Co   : 6   19-May :10  
##  Median :2.000   Median :1.000   Median :1.0000   Khong:49   19-Oct :10  
##  Mean   :2.506   Mean   :1.509   Mean   :0.7091              19-Nov : 8  
##  3rd Qu.:4.000   3rd Qu.:2.500   3rd Qu.:1.0000              19-Sep : 8  
##  Max.   :6.000   Max.   :6.000   Max.   :1.0000              19-Jun : 7  
##                  NA's   :24      NA's   :24                  (Other):21  
##       Toast     gioi        bddngv             tuoi             cn       
##  Khong Xd:35   Nam:47   Min.   :0.00000   Min.   :38.00   Min.   :39.00  
##  MM l?n  :17   Nu :32   1st Qu.:0.00000   1st Qu.:55.00   1st Qu.:53.00  
##  MM nho  :19            Median :0.00000   Median :64.00   Median :58.00  
##  Tim     : 8            Mean   :0.03797   Mean   :62.46   Mean   :58.67  
##                         3rd Qu.:0.00000   3rd Qu.:69.50   3rd Qu.:64.50  
##                         Max.   :1.00000   Max.   :79.00   Max.   :84.00  
##                                                                          
##        cc              bmi        Tdieutri        Tcuakim          tha    
##  Min.   :  1.65          :75   Min.   : 50.0   Min.   : 10.00   Co   :73  
##  1st Qu.:150.00   #DIV/0!: 3   1st Qu.:140.0   1st Qu.: 40.00   Khong: 6  
##  Median :165.00   18     : 1   Median :170.0   Median : 50.00             
##  Mean   :131.33                Mean   :169.8   Mean   : 53.08             
##  3rd Qu.:170.00                3rd Qu.:200.0   3rd Qu.: 60.00             
##  Max.   :170.00                Max.   :328.0   Max.   :130.00             
##  NA's   :74                                                               
##     dtd        rllp      smoke     tsdotquy      hattnv     
##  Co   :13   Co   :34   Co   : 8   Co   :11   Min.   : 90.0  
##  Khong:66   Khong:45   Khong:71   Khong:68   1st Qu.:140.0  
##                                              Median :150.0  
##                                              Mean   :153.8  
##                                              3rd Qu.:160.0  
##                                              Max.   :240.0  
##                                                             
##     hattrnv          NIHSSnv         NIHSS24h      NIHSSgiam4
##  Min.   : 60.00   Min.   : 4.00   Min.   : 0.000   Co   :34  
##  1st Qu.: 80.00   1st Qu.: 6.00   1st Qu.: 2.000   Khong:45  
##  Median : 80.00   Median :10.00   Median : 7.000             
##  Mean   : 85.22   Mean   :11.48   Mean   : 8.215             
##  3rd Qu.: 90.00   3rd Qu.:15.50   3rd Qu.:12.000             
##  Max.   :120.00   Max.   :24.00   Max.   :35.000             
##                                                              
##     NIHSSxv           mRSnv          mRSxv.1          Glynv      
##  Min.   : 0.000   Min.   :2.000   Min.   :0.000   Min.   : 52.0  
##  1st Qu.: 1.000   1st Qu.:3.000   1st Qu.:1.000   1st Qu.: 98.5  
##  Median : 6.000   Median :4.000   Median :2.000   Median :117.0  
##  Mean   : 7.734   Mean   :3.532   Mean   :2.494   Mean   :131.7  
##  3rd Qu.:11.500   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:136.5  
##  Max.   :35.000   Max.   :5.000   Max.   :6.000   Max.   :420.0  
##                                                                  
##  rungnhinv     ASPECTnv      dautangquangCT    hepmachcKhongynghia
##  Co   : 8   Min.   : 7.000   Min.   :0.00000   Co   :18           
##  Khong:71   1st Qu.: 8.000   1st Qu.:0.00000   Khong:61           
##             Median : 9.000   Median :0.00000                      
##             Mean   : 8.722   Mean   :0.03797                      
##             3rd Qu.: 9.500   3rd Qu.:0.00000                      
##             Max.   :10.000   Max.   :1.00000                      
##                                                                   
##  NIHSScaithien    xhn     chaymaunhe   diung       tvxv       mRS90.1   
##  Co   :36      Khong:79   Co   : 6   Khong:79   Co   : 3   Min.   :0.0  
##  Khong:43                 Khong:73              Khong:76   1st Qu.:0.0  
##                                                            Median :1.0  
##                                                            Mean   :0.6  
##                                                            3rd Qu.:1.0  
##                                                            Max.   :1.0  
##                                                            NA's   :74   
##  mRS90caithien.1      tv90             X     
##  Min.   :0.0     Min.   :0.0            :78  
##  1st Qu.:0.0     1st Qu.:0.0   TV th8/19: 1  
##  Median :1.0     Median :0.5                 
##  Mean   :0.6     Mean   :0.5                 
##  3rd Qu.:1.0     3rd Qu.:1.0                 
##  Max.   :1.0     Max.   :1.0                 
##  NA's   :74      NA's   :73
# Chonn mô hinh tot nhat mRSxv
library(BMA)
## Loading required package: survival
## Loading required package: leaps
## Loading required package: robustbase
## 
## Attaching package: 'robustbase'
## The following object is masked from 'package:survival':
## 
##     heart
## The following object is masked from 'package:psych':
## 
##     cushny
## Loading required package: inline
## Loading required package: rrcov
## Scalable Robust Estimators with High Breakdown Point (version 1.4-7)
yvar = rtpa[, ("mRSxv")]
xvars = rtpa[, c("gioi", "tuoi", "Tdieutri", "Tcuakim", "NIHSSnv")]
bma = bicreg(xvars, yvar, strict=FALSE, OR=20)
summary(bma)
## 
## Call:
## bicreg(x = xvars, y = yvar, strict = FALSE, OR = 20)
## 
## 
##   7  models were selected
##  Best  5  models (cumulative posterior probability =  0.9283 ): 
## 
##            p!=0    EV         SD        model 1     model 2     model 3   
## Intercept  100.0   6.200e-01  0.716090    0.820720    0.642877   -0.362615
## gioiNu      26.2   1.327e-01  0.278727       .        0.508921       .    
## tuoi        16.8   3.200e-03  0.009548       .           .        0.019611
## Tdieutri     9.7  -2.167e-04  0.001237       .           .           .    
## Tcuakim      5.6  -8.041e-05  0.001749       .           .           .    
## NIHSSnv    100.0   1.458e-01  0.026224    0.146817    0.144352    0.143204
##                                                                           
## nVar                                        1           2           2     
## r2                                        0.291       0.312       0.305   
## BIC                                     -22.746280  -20.859589  -20.025199
## post prob                                 0.489       0.190       0.125   
##            model 4     model 5   
## Intercept    1.157364    0.885189
## gioiNu          .           .    
## tuoi            .           .    
## Tdieutri    -0.002077       .    
## Tcuakim         .       -0.001432
## NIHSSnv      0.148220    0.147823
##                                  
## nVar           2           2     
## r2           0.294       0.291   
## BIC        -18.774239  -18.416929
## post prob    0.067       0.056
imageplot.bma(bma)

# Chon mô hinh tot nhat 2
library(BMA)
yvar = rtpa[, ("mRSxv")]
xvars = rtpa[, c("Tdieutri","Tcuakim","NIHSSnv", "NIHSS24h", "mRSnv")]
bma = bicreg(xvars, yvar, strict=FALSE, OR=20)
summary(bma)
## 
## Call:
## bicreg(x = xvars, y = yvar, strict = FALSE, OR = 20)
## 
## 
##   10  models were selected
##  Best  5  models (cumulative posterior probability =  0.8513 ): 
## 
##            p!=0    EV         SD         model 1     model 2   
## Intercept  100.0   8.053e-01  0.4392503   9.113e-01   3.958e-01
## Tdieutri     9.8  -9.546e-05  0.0006938       .           .    
## Tcuakim      9.3  -1.336e-04  0.0014010       .           .    
## NIHSSnv     57.0  -3.727e-02  0.0410661       .      -8.207e-02
## NIHSS24h   100.0   2.067e-01  0.0197505   1.942e-01   2.158e-01
## mRSnv       38.8   1.286e-01  0.1967720       .       3.624e-01
##                                                                
## nVar                                        1           3      
## r2                                        0.741       0.767    
## BIC                                      -1.022e+02  -1.020e+02
## post prob                                 0.308       0.282    
##            model 3     model 4     model 5   
## Intercept   1.175e+00   1.120e+00   1.027e+00
## Tdieutri        .      -1.237e-03       .    
## Tcuakim         .           .      -2.326e-03
## NIHSSnv    -3.968e-02       .           .    
## NIHSS24h    2.175e-01   1.944e-01   1.951e-01
## mRSnv           .           .           .    
##                                              
## nVar          2           2           2      
## r2          0.751       0.742       0.742    
## BIC        -1.011e+02  -9.823e+01  -9.814e+01
## post prob   0.178       0.042       0.040
imageplot.bma(bma)