Load thư viện
library(car)
## Loading required package: carData
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
##
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
##
## format.pval, units
library(psych)
##
## Attaching package: 'psych'
## The following object is masked from 'package:Hmisc':
##
## describe
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
## The following object is masked from 'package:car':
##
## logit
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## src, summarize
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Đọc dữ liệu từ file .csv (Heart.csv)
data = read.csv('https://raw.githubusercontent.com/pnhuy/datasets/master/heart_uci/heart.csv')
attach(data)
head(data)
## X Age Sex ChestPain RestBP Chol Fbs RestECG MaxHR ExAng Oldpeak Slope Ca
## 1 1 63 1 typical 145 233 1 2 150 0 2.3 3 0
## 2 2 67 1 asymptomatic 160 286 0 2 108 1 1.5 2 3
## 3 3 67 1 asymptomatic 120 229 0 2 129 1 2.6 2 2
## 4 4 37 1 nonanginal 130 250 0 0 187 0 3.5 3 0
## 5 5 41 0 nontypical 130 204 0 2 172 0 1.4 1 0
## 6 6 56 1 nontypical 120 236 0 0 178 0 0.8 1 0
## Thal AHD
## 1 fixed No
## 2 normal Yes
## 3 reversable Yes
## 4 normal No
## 5 normal No
## 6 normal No
Tạo một biến Gender tương ứng với biến Sex (0 : Female , 1 : Male )
Gender = factor(Sex, levels = c(0,1), labels = c('Female','Male'))
Phân tích tương quan
Tương quan một biến
plot(MaxHR ~ Age, pch = 16 , col = 'red')

cor.test(MaxHR, Age)
##
## Pearson's product-moment correlation
##
## data: MaxHR and Age
## t = -7.4329, df = 301, p-value = 1.109e-12
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.4849644 -0.2941816
## sample estimates:
## cor
## -0.3938058
cor.test(MaxHR, Age)
##
## Pearson's product-moment correlation
##
## data: MaxHR and Age
## t = -7.4329, df = 301, p-value = 1.109e-12
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.4849644 -0.2941816
## sample estimates:
## cor
## -0.3938058
Tương quan đa biến
vars = cbind(MaxHR,Age,Chol,RestBP,Oldpeak,Thal)
corr.test(vars)
## Call:corr.test(x = vars)
## Correlation matrix
## MaxHR Age Chol RestBP Oldpeak Thal
## MaxHR 1.00 -0.39 0.00 -0.05 -0.34 -0.12
## Age -0.39 1.00 0.21 0.28 0.20 0.06
## Chol 0.00 0.21 1.00 0.13 0.05 0.08
## RestBP -0.05 0.28 0.13 1.00 0.19 0.06
## Oldpeak -0.34 0.20 0.05 0.19 1.00 0.21
## Thal -0.12 0.06 0.08 0.06 0.21 1.00
## Sample Size
## MaxHR Age Chol RestBP Oldpeak Thal
## MaxHR 303 303 303 303 303 301
## Age 303 303 303 303 303 301
## Chol 303 303 303 303 303 301
## RestBP 303 303 303 303 303 301
## Oldpeak 303 303 303 303 303 301
## Thal 301 301 301 301 301 301
## Probability values (Entries above the diagonal are adjusted for multiple tests.)
## MaxHR Age Chol RestBP Oldpeak Thal
## MaxHR 0.00 0.00 1.00 1.00 0.00 0.29
## Age 0.00 0.00 0.00 0.00 0.00 1.00
## Chol 0.95 0.00 0.00 0.19 1.00 0.97
## RestBP 0.43 0.00 0.02 0.00 0.01 1.00
## Oldpeak 0.00 0.00 0.42 0.00 0.00 0.00
## Thal 0.04 0.29 0.16 0.32 0.00 0.00
##
## To see confidence intervals of the correlations, print with the short=FALSE option
pairs.panels(vars)

Hồi quy tuyến tính một biến
Hồi quy tuyến tính với biến liên tục
res = lm(MaxHR ~ Age)
summary(res)
##
## Call:
## lm(formula = MaxHR ~ Age)
##
## Residuals:
## Min 1Q Median 3Q Max
## -66.088 -12.040 3.965 15.937 44.955
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 203.8634 7.3991 27.553 < 2e-16 ***
## Age -0.9966 0.1341 -7.433 1.11e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 21.06 on 301 degrees of freedom
## Multiple R-squared: 0.1551, Adjusted R-squared: 0.1523
## F-statistic: 55.25 on 1 and 301 DF, p-value: 1.109e-12
Vẽ biểu đồ
plot(MaxHR ~ Age, col = 'blue', pch = 16)
abline(res, col = 2)

Tính y^
predict(res)
## 1 2 3 4 5 6 7 8
## 141.0750 137.0884 137.0884 166.9876 163.0011 148.0514 142.0716 147.0548
## 9 10 11 12 13 14 15 16
## 141.0750 151.0414 147.0548 148.0514 148.0514 160.0111 152.0380 147.0548
## 17 18 19 20 21 22 23 24
## 156.0246 150.0447 156.0246 155.0279 140.0783 146.0582 146.0582 146.0582
## 25 26 27 28 29 30 31 32
## 144.0649 154.0313 146.0582 138.0850 161.0078 163.9977 135.0951 144.0649
## 33 34 35 36 37 38 39 40
## 140.0783 145.0615 160.0111 162.0044 161.0078 147.0548 149.0481 143.0682
## 41 42 43 44 45 46 47 48
## 139.0817 163.9977 133.1018 145.0615 143.0682 146.0582 153.0347 154.0313
## 49 50 51 52 53 54 55 56
## 139.0817 151.0414 163.0011 139.0817 160.0111 160.0111 144.0649 150.0447
## 57 58 59 60 61 62 63 64
## 154.0313 163.0011 150.0447 153.0347 153.0347 158.0179 146.0582 150.0447
## 65 66 67 68 69 70 71 72
## 150.0447 144.0649 144.0649 150.0447 145.0615 158.0179 139.0817 137.0884
## 73 74 75 76 77 78 79 80
## 142.0716 139.0817 160.0111 139.0817 144.0649 153.0347 156.0246 146.0582
## 81 82 83 84 85 86 87 88
## 159.0145 151.0414 164.9944 136.0917 152.0380 160.0111 157.0212 151.0414
## 89 90 91 92 93 94 95 96
## 151.0414 153.0347 138.0850 142.0716 142.0716 160.0111 141.0750 152.0380
## 97 98 99 100 101 102 103 104
## 145.0615 144.0649 152.0380 156.0246 159.0145 169.9776 147.0548 133.1018
## 105 106 107 108 109 110 111 112
## 155.0279 150.0447 145.0615 147.0548 143.0682 164.9944 143.0682 148.0514
## 113 114 115 116 117 118 119 120
## 152.0380 161.0078 142.0716 163.0011 146.0582 168.9809 141.0750 139.0817
## 121 122 123 124 125 126 127 128
## 156.0246 141.0750 153.0347 149.0481 139.0817 159.0145 148.0514 150.0447
## 129 130 131 132 133 134 135 136
## 160.0111 142.0716 150.0447 153.0347 174.9608 153.0347 161.0078 149.0481
## 137 138 139 140 141 142 143 144
## 134.0985 142.0716 168.9809 153.0347 145.0615 145.0615 152.0380 140.0783
## 145 146 147 148 149 150 151 152
## 146.0582 157.0212 147.0548 163.0011 159.0145 144.0649 152.0380 162.0044
## 153 154 155 156 157 158 159 160
## 137.0884 149.0481 140.0783 134.0985 153.0347 146.0582 144.0649 136.0917
## 161 162 163 164 165 166 167 168
## 158.0179 127.1220 150.0447 146.0582 156.0246 147.0548 152.0380 150.0447
## 169 170 171 172 173 174 175 176
## 168.9809 159.0145 134.0985 151.0414 145.0615 142.0716 140.0783 147.0548
## 177 178 179 180 181 182 183 184
## 152.0380 148.0514 161.0078 151.0414 156.0246 148.0514 162.0044 145.0615
## 185 186 187 188 189 190 191 192
## 144.0649 141.0750 162.0044 138.0850 150.0447 135.0951 154.0313 153.0347
## 193 194 195 196 197 198 199 200
## 161.0078 142.0716 136.0917 137.0884 135.0951 159.0145 154.0313 145.0615
## 201 202 203 204 205 206 207 208
## 154.0313 140.0783 147.0548 140.0783 161.0078 159.0145 146.0582 154.0313
## 209 210 211 212 213 214 215 216
## 149.0481 142.0716 166.9876 165.9910 163.0011 138.0850 152.0380 148.0514
## 217 218 219 220 221 222 223 224
## 158.0179 158.0179 140.0783 145.0615 163.0011 150.0447 164.9944 151.0414
## 225 226 227 228 229 230 231 232
## 141.0750 169.9776 157.0212 137.0884 150.0447 138.0850 152.0380 149.0481
## 233 234 235 236 237 238 239 240
## 155.0279 130.1119 150.0447 150.0447 148.0514 158.0179 155.0279 162.0044
## 241 242 243 244 245 246 247 248
## 163.0011 163.0011 155.0279 143.0682 144.0649 137.0884 146.0582 157.0212
## 249 250 251 252 253 254 255 256
## 152.0380 142.0716 147.0548 146.0582 140.0783 153.0347 161.0078 162.0044
## 257 258 259 260 261 262 263 264
## 137.0884 128.1186 134.0985 147.0548 160.0111 146.0582 144.0649 160.0111
## 265 266 267 268 269 270 271 272
## 143.0682 162.0044 152.0380 145.0615 163.9977 162.0044 143.0682 138.0850
## 273 274 275 276 277 278 279 280
## 158.0179 133.1018 145.0615 140.0783 138.0850 164.9944 147.0548 146.0582
## 281 282 283 284 285 286 287 288
## 147.0548 157.0212 149.0481 168.9809 143.0682 146.0582 146.0582 146.0582
## 289 290 291 292 293 294 295 296
## 148.0514 148.0514 137.0884 149.0481 160.0111 141.0750 141.0750 163.0011
## 297 298 299 300 301 302 303
## 145.0615 147.0548 159.0145 136.0917 147.0548 147.0548 165.9910
Phân tích phương sai
aov = anova(res)
aov
## Analysis of Variance Table
##
## Response: MaxHR
## Df Sum Sq Mean Sq F value Pr(>F)
## Age 1 24507 24507.2 55.248 1.109e-12 ***
## Residuals 301 133519 443.6
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Phân tích residual
Phân phối chuẩn
m = resid(res)
m
## 1 2 3 4 5
## 8.925045921 -29.088386747 -8.088386747 20.012358269 8.998925601
## 6 7 8 9 10
## 29.948553092 17.928404089 15.945194925 5.925045921 3.958627594
## 11 12 13 14 15
## 0.945194925 4.948553092 -6.051446908 12.988851099 9.961985761
## 16 17 18 19 20
## 26.945194925 11.975418430 9.955269427 -17.024581570 15.972060263
## 21 22 23 24 25
## 3.921687754 15.941836758 13.941836758 26.941836758 -12.064879577
## 26 27 28 29 30
## 3.968702095 25.941836758 -24.085028580 9.992209266 -49.997716232
## 31 32 33 34 35
## 15.904896918 15.935120423 17.921687754 15.938478590 18.988851099
## 36 37 38 39 40
## 15.995567433 -41.007790734 -35.054805075 -17.048088741 -6.068237744
## 41 42 43 44 45
## -25.081670413 14.002283768 28.898180584 11.938478590 25.931762256
## 46 47 48 49 50
## 18.941836758 -30.034656072 -26.031297905 17.918329587 0.958627594
## 51 52 53 54 55
## 4.998925601 0.918329587 -7.011148901 27.988851099 -0.064879577
## 56 57 58 59 60
## -41.044730573 8.968702095 -5.001074399 1.955269427 -28.034656072
## 61 62 63 64 65
## -11.034656072 1.982134764 -15.058163242 19.955269427 -37.044730573
## 66 67 68 69 70
## -2.064879577 10.935120423 14.955269427 -5.061521410 -11.017865236
## 71 72 73 74 75
## 8.918329587 25.911613253 -43.071595911 18.918329587 16.988851099
## 76 77 78 79 80
## 11.918329587 -3.064879577 -11.034656072 23.975418430 -35.058163242
## 81 82 83 84 85
## -11.014507068 -8.041372406 17.005641935 13.908255085 19.961985761
## 86 87 88 89 90
## 19.988851099 -1.021223403 -36.041372406 8.958627594 -4.034656072
## 91 92 93 94 95
## 12.914971420 2.928404089 3.928404089 14.988851099 30.925045921
## 96 97 98 99 100
## 8.961985761 -3.061521410 12.935120423 5.961985761 29.975418430
## 101 102 103 104 105
## 25.985492932 4.022432771 11.945194925 -3.101819416 -16.027939737
## 106 107 108 109 110
## 5.955269427 16.938478590 2.945194925 -3.068237744 -24.994358065
## 111 112 113 114 115
## 2.931762256 -4.051446908 37.961985761 -25.007790734 -45.071595911
## 116 117 118 119 120
## -31.001074399 18.941836758 13.019074604 -9.074954079 -12.081670413
## 121 122 123 124 125
## -6.024581570 12.925045921 -10.034656072 -38.048088741 34.918329587
## 126 127 128 129 130
## 15.985492932 -15.051446908 -24.044730573 9.988851099 20.928404089
## 131 132 133 134 135
## -3.044730573 0.965343928 27.039223607 32.965343928 3.992209266
## 136 137 138 139 140
## 11.951911259 -9.098461249 -39.071595911 -38.980925396 12.965343928
## 141 142 143 144 145
## 18.938478590 13.938478590 31.961985761 -9.078312246 7.941836758
## 146 147 148 149 150
## -5.021223403 -23.054805075 15.998925601 10.985492932 15.935120423
## 151 152 153 154 155
## 25.961985761 -40.004432567 22.911613253 -4.048088741 -44.078312246
## 156 157 158 159 160
## -25.098461249 19.965343928 24.941836758 25.935120423 14.908255085
## 161 162 163 164 165
## -2.017865236 34.878031580 7.955269427 -24.058163242 18.975418430
## 166 167 168 169 170
## 20.945194925 16.961985761 8.955269427 -12.980925396 -21.014507068
## 171 172 173 174 175
## -22.098461249 -40.041372406 -2.061521410 14.928404089 -8.078312246
## 176 177 178 179 180
## -59.054805075 -5.038014239 -43.051446908 0.992209266 21.958627594
## 181 182 183 184 185
## 9.975418430 1.948553092 15.995567433 -0.061521410 16.935120423
## 186 187 188 189 190
## 37.925045921 31.995567433 -18.085028580 44.955269427 10.904896918
## 191 192 193 194 195
## 8.968702095 -31.034656072 -18.007790734 -36.071595911 -21.091744915
## 196 197 198 199 200
## -12.088386747 -4.095103082 -7.014507068 7.968702095 -20.061521410
## 201 202 203 204 205
## 4.968702095 13.921687754 25.945194925 -7.078312246 -0.007790734
## 206 207 208 209 210
## -12.014507068 -16.058163242 -28.031297905 5.951911259 11.928404089
## 211 212 213 214 215
## 3.012358269 16.009000102 4.998925601 26.914971420 7.961985761
## 216 217 218 219 220
## 13.948553092 13.982134764 -6.017865236 -18.078312246 36.938478590
## 221 222 223 224 225
## 8.998925601 16.955269427 14.005641935 -56.041372406 27.925045921
## 226 227 228 229 230
## 22.022432771 -14.021223403 34.911613253 -42.044730573 -6.085028580
## 231 232 233 234 235
## 16.961985761 -32.048088741 -29.027939737 -9.111893918 12.955269427
## 236 237 238 239 240
## -34.044730573 -45.051446908 -14.017865236 6.972060263 -0.004432567
## 241 242 243 244 245
## -10.001074399 -0.001074399 7.972060263 1.931762256 -48.064879577
## 246 247 248 249 250
## -66.088386747 9.941836758 -39.021223403 15.961985761 -2.071595911
## 251 252 253 254 255
## -21.054805075 -41.058163242 -35.078312246 3.965343928 19.992209266
## 256 257 258 259 260
## 10.995567433 4.911613253 -12.118610252 8.901538751 -6.054805075
## 261 262 263 264 265
## -11.011148901 5.941836758 26.935120423 8.988851099 -18.068237744
## 266 267 268 269 270
## -37.004432567 3.961985761 -11.061521410 17.002283768 -12.004432567
## 271 272 273 274 275
## -5.068237744 -0.085028580 -38.017865236 -8.101819416 16.938478590
## 276 277 278 279 280
## 14.921687754 13.914971420 -12.994358065 16.945194925 -15.058163242
## 281 282 283 284 285
## -4.054805075 21.978776597 -19.048088741 5.019074604 17.931762256
## 286 287 288 289 290
## -6.058163242 -0.058163242 -2.058163242 14.948553092 20.948553092
## 291 292 293 294 295
## 12.911613253 16.951911259 -16.011148901 2.925045921 -5.074954079
## 296 297 298 299 300
## 18.998925601 -55.061521410 -24.054805075 -27.014507068 4.908255085
## 301 302 303
## -32.054805075 26.945194925 7.009000102
- Kiểm định phân phối chuẩn
hist(m)

qqnorm(m, pch = 16)
qqline(m, col = 2, lwd = 3)

shapiro.test(m)
##
## Shapiro-Wilk normality test
##
## data: m
## W = 0.96133, p-value = 3.296e-07
mean(m)
## [1] -6.282132e-16
ncvTest(res)
## Non-constant Variance Score Test
## Variance formula: ~ fitted.values
## Chisquare = 0.7229959, Df = 1, p = 0.39516
spreadLevelPlot(res, pch = 16)

##
## Suggested power transformation: 1.217132
Hồi quy tuyến tính với biến phân nhóm
res1 = lm(MaxHR ~ Gender)
summary(res1)
##
## Call:
## lm(formula = MaxHR ~ Gender)
##
## Residuals:
## Min 1Q Median 3Q Max
## -77.845 -16.036 2.773 16.155 53.155
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 151.227 2.324 65.080 <2e-16 ***
## GenderMale -2.382 2.818 -0.845 0.399
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 22.89 on 301 degrees of freedom
## Multiple R-squared: 0.002368, Adjusted R-squared: -0.0009463
## F-statistic: 0.7145 on 1 and 301 DF, p-value: 0.3986
boxplot(MaxHR ~ Gender, col = c('red','blue'))

Hồi quy tuyến tính đa biến
res2 = lm(MaxHR ~ RestBP + Age + Thal)
summary(res2)
##
## Call:
## lm(formula = MaxHR ~ RestBP + Age + Thal)
##
## Residuals:
## Min 1Q Median 3Q Max
## -70.046 -12.269 3.579 14.086 52.824
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 172.57393 11.48221 15.030 < 2e-16 ***
## RestBP 0.13314 0.06932 1.921 0.055720 .
## Age -0.98287 0.13478 -7.292 2.8e-12 ***
## Thalnormal 18.34722 5.04476 3.637 0.000325 ***
## Thalreversable 7.69466 5.11709 1.504 0.133721
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.19 on 296 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.2301, Adjusted R-squared: 0.2197
## F-statistic: 22.12 on 4 and 296 DF, p-value: 5.425e-16
Ảnh hưởng tương tác
res3 = lm(MaxHR ~ RestBP + Age + Thal + Thal:Age)
summary(res3)
##
## Call:
## lm(formula = MaxHR ~ RestBP + Age + Thal + Thal:Age)
##
## Residuals:
## Min 1Q Median 3Q Max
## -67.300 -11.528 3.407 13.211 56.347
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 128.95595 36.95280 3.490 0.000558 ***
## RestBP 0.12410 0.06902 1.798 0.073191 .
## Age -0.19128 0.63802 -0.300 0.764534
## Thalnormal 74.23500 37.37503 1.986 0.047937 *
## Thalreversable 32.78480 38.65078 0.848 0.396999
## Age:Thalnormal -0.99950 0.65603 -1.524 0.128693
## Age:Thalreversable -0.43675 0.67762 -0.645 0.519725
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 20.07 on 294 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.2444, Adjusted R-squared: 0.2289
## F-statistic: 15.85 on 6 and 294 DF, p-value: 8.885e-16
Xây dựng mô hình thống kê tối ưu
dt = select(data, c(2:14))
head(dt)
## Age Sex ChestPain RestBP Chol Fbs RestECG MaxHR ExAng Oldpeak Slope Ca
## 1 63 1 typical 145 233 1 2 150 0 2.3 3 0
## 2 67 1 asymptomatic 160 286 0 2 108 1 1.5 2 3
## 3 67 1 asymptomatic 120 229 0 2 129 1 2.6 2 2
## 4 37 1 nonanginal 130 250 0 0 187 0 3.5 3 0
## 5 41 0 nontypical 130 204 0 2 172 0 1.4 1 0
## 6 56 1 nontypical 120 236 0 0 178 0 0.8 1 0
## Thal
## 1 fixed
## 2 normal
## 3 reversable
## 4 normal
## 5 normal
## 6 normal
model = lm(MaxHR ~ ., data = na.omit(dt))
op = step(model)
## Start: AIC=1740.99
## MaxHR ~ Age + Sex + ChestPain + RestBP + Chol + Fbs + RestECG +
## ExAng + Oldpeak + Slope + Ca + Thal
##
## Df Sum of Sq RSS AIC
## - Sex 1 0.5 93705 1739.0
## - Thal 2 714.5 94419 1739.2
## - RestECG 1 103.5 93808 1739.3
## - Fbs 1 130.9 93836 1739.4
## - Oldpeak 1 204.4 93909 1739.6
## - Ca 1 260.5 93965 1739.8
## <none> 93705 1741.0
## - Chol 1 753.7 94458 1741.4
## - RestBP 1 1062.2 94767 1742.3
## - ChestPain 3 3261.9 96967 1745.2
## - Slope 1 4418.0 98123 1752.7
## - ExAng 1 4689.1 98394 1753.5
## - Age 1 13092.8 106798 1777.8
##
## Step: AIC=1738.99
## MaxHR ~ Age + ChestPain + RestBP + Chol + Fbs + RestECG + ExAng +
## Oldpeak + Slope + Ca + Thal
##
## Df Sum of Sq RSS AIC
## - RestECG 1 105.5 93811 1737.3
## - Thal 2 747.6 94453 1737.3
## - Fbs 1 131.6 93837 1737.4
## - Oldpeak 1 203.9 93909 1737.6
## - Ca 1 260.0 93965 1737.8
## <none> 93705 1739.0
## - Chol 1 774.6 94480 1739.4
## - RestBP 1 1070.6 94776 1740.4
## - ChestPain 3 3303.9 97009 1743.3
## - Slope 1 4477.9 98183 1750.8
## - ExAng 1 4704.6 98410 1751.5
## - Age 1 13253.5 106959 1776.3
##
## Step: AIC=1737.32
## MaxHR ~ Age + ChestPain + RestBP + Chol + Fbs + ExAng + Oldpeak +
## Slope + Ca + Thal
##
## Df Sum of Sq RSS AIC
## - Thal 2 758.0 94569 1735.7
## - Fbs 1 140.8 93951 1735.8
## - Oldpeak 1 206.8 94017 1736.0
## - Ca 1 240.7 94051 1736.1
## <none> 93811 1737.3
## - Chol 1 871.6 94682 1738.1
## - RestBP 1 1137.1 94948 1738.9
## - ChestPain 3 3251.5 97062 1741.4
## - Slope 1 4392.3 98203 1748.9
## - ExAng 1 4686.0 98497 1749.8
## - Age 1 13184.0 106995 1774.4
##
## Step: AIC=1735.71
## MaxHR ~ Age + ChestPain + RestBP + Chol + Fbs + ExAng + Oldpeak +
## Slope + Ca
##
## Df Sum of Sq RSS AIC
## - Fbs 1 90.2 94659 1734.0
## - Oldpeak 1 223.5 94792 1734.4
## - Ca 1 331.9 94901 1734.8
## <none> 94569 1735.7
## - RestBP 1 1020.2 95589 1736.9
## - Chol 1 1085.9 95655 1737.1
## - ChestPain 3 3653.3 98222 1741.0
## - ExAng 1 5008.0 99577 1749.0
## - Slope 1 5152.4 99721 1749.5
## - Age 1 13186.6 107755 1772.5
##
## Step: AIC=1734
## MaxHR ~ Age + ChestPain + RestBP + Chol + ExAng + Oldpeak + Slope +
## Ca
##
## Df Sum of Sq RSS AIC
## - Oldpeak 1 251.0 94910 1732.8
## - Ca 1 285.6 94944 1732.9
## <none> 94659 1734.0
## - Chol 1 1070.5 95729 1735.3
## - RestBP 1 1147.3 95806 1735.6
## - ChestPain 3 3830.4 98489 1739.8
## - ExAng 1 4969.9 99629 1747.2
## - Slope 1 5086.7 99746 1747.5
## - Age 1 13121.8 107781 1770.5
##
## Step: AIC=1732.78
## MaxHR ~ Age + ChestPain + RestBP + Chol + ExAng + Slope + Ca
##
## Df Sum of Sq RSS AIC
## - Ca 1 445.4 95355 1732.2
## <none> 94910 1732.8
## - RestBP 1 1042.6 95952 1734.0
## - Chol 1 1065.2 95975 1734.1
## - ChestPain 3 3999.2 98909 1739.0
## - ExAng 1 5269.1 100179 1746.8
## - Slope 1 8707.8 103618 1756.9
## - Age 1 13067.3 107977 1769.1
##
## Step: AIC=1732.17
## MaxHR ~ Age + ChestPain + RestBP + Chol + ExAng + Slope
##
## Df Sum of Sq RSS AIC
## <none> 95355 1732.2
## - Chol 1 1014.0 96369 1733.3
## - RestBP 1 1054.1 96409 1733.4
## - ChestPain 3 4757.4 100113 1740.6
## - ExAng 1 5310.0 100665 1746.3
## - Slope 1 8761.6 104117 1756.3
## - Age 1 16241.2 111597 1776.9
op
##
## Call:
## lm(formula = MaxHR ~ Age + ChestPain + RestBP + Chol + ExAng +
## Slope, data = na.omit(dt))
##
## Coefficients:
## (Intercept) Age ChestPainnonanginal
## 187.70592 -0.88515 7.39669
## ChestPainnontypical ChestPaintypical RestBP
## 9.97711 11.14766 0.11303
## Chol ExAng Slope
## 0.03665 -10.31114 -9.35208
summary(op)
##
## Call:
## lm(formula = MaxHR ~ Age + ChestPain + RestBP + Chol + ExAng +
## Slope, data = na.omit(dt))
##
## Residuals:
## Min 1Q Median 3Q Max
## -60.947 -12.047 2.099 11.722 44.007
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 187.70592 10.13348 18.523 < 2e-16 ***
## Age -0.88515 0.12638 -7.004 1.76e-11 ***
## ChestPainnonanginal 7.39669 2.73949 2.700 0.00734 **
## ChestPainnontypical 9.97711 3.31704 3.008 0.00286 **
## ChestPaintypical 11.14766 4.25312 2.621 0.00923 **
## RestBP 0.11303 0.06335 1.784 0.07543 .
## Chol 0.03665 0.02094 1.750 0.08118 .
## ExAng -10.31114 2.57474 -4.005 7.91e-05 ***
## Slope -9.35208 1.81799 -5.144 4.98e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 18.2 on 288 degrees of freedom
## Multiple R-squared: 0.3879, Adjusted R-squared: 0.3709
## F-statistic: 22.82 on 8 and 288 DF, p-value: < 2.2e-16