Correlation between \(X_1\) and \(Y\), no effect of \(X_2\)
Correlation between \(X_1\) and \(Y\), removing the effect of \(X_2\)
Correlation between \(X_1\) and \(Y\), removing the effect of \(X_2\)
ICU
data from the Stat2Data package ID Survive Age AgeGroup Sex
ID 1.000000000 0.09008759 -0.13379591 -0.09294666 0.004507259
Survive 0.090087587 1.00000000 -0.18945786 -0.19137028 -0.020602141
Age -0.133795910 -0.18945786 1.00000000 0.89932798 0.096077315
AgeGroup -0.092946657 -0.19137028 0.89932798 1.00000000 0.106451213
Sex 0.004507259 -0.02060214 0.09607732 0.10645121 1.000000000
Infection -0.129037797 -0.18234920 0.15355452 0.10210375 0.022540704
SysBP 0.007579045 0.20467231 0.04259431 0.04455849 0.049428168
Pulse 0.027350603 -0.03176090 0.03736843 0.02249490 0.039529993
Emergency 0.199467075 -0.24358013 -0.18695714 -0.19765780 0.119971717
Infection SysBP Pulse Emergency
ID -0.1290378 0.007579045 0.02735060 0.1994671
Survive -0.1823492 0.204672308 -0.03176090 -0.2435801
Age 0.1535545 0.042594310 0.03736843 -0.1869571
AgeGroup 0.1021037 0.044558494 0.02249490 -0.1976578
Sex 0.0225407 0.049428168 0.03952999 0.1199717
Infection 1.0000000 -0.228538626 0.31051173 0.1666485
SysBP -0.2285386 1.000000000 -0.05658246 -0.1841112
Pulse 0.3105117 -0.056582465 1.00000000 0.1752685
Emergency 0.1666485 -0.184111172 0.17526851 1.0000000
SysBP
from “everthing”
Call:
lm(formula = SysBP ~ . - ID - AgeGroup, data = ICU)
Residuals:
Min 1Q Median 3Q Max
-78.827 -19.835 -2.923 19.312 129.997
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 121.72860 13.42593 9.067 < 2e-16 ***
Survive 12.94692 6.00852 2.155 0.03242 *
Age 0.12509 0.12023 1.040 0.29944
Sex 4.20390 4.68840 0.897 0.37102
Infection -13.48289 4.92376 -2.738 0.00675 **
Pulse 0.03095 0.08903 0.348 0.72848
Emergency -8.16479 5.58844 -1.461 0.14564
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 31.68 on 193 degrees of freedom
Multiple R-squared: 0.1036, Adjusted R-squared: 0.07572
F-statistic: 3.717 on 6 and 193 DF, p-value: 0.001606
Emergency
predicts SysBP
alone
Call:
lm(formula = SysBP ~ Emergency, data = ICU)
Residuals:
Min 1Q Median 3Q Max
-92.646 -18.646 -0.502 17.426 127.354
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 142.358 4.460 31.918 < 2e-16 ***
Emergency -13.712 5.202 -2.636 0.00906 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 32.47 on 198 degrees of freedom
Multiple R-squared: 0.0339, Adjusted R-squared: 0.02902
F-statistic: 6.947 on 1 and 198 DF, p-value: 0.009061
Age
and AgeGroup
are correlated 0.899Age
and Pulse
are predictorsggplot(data = ICU,
aes(x = Pulse, y = Age)) +
geom_point(alpha = 0.3,
color = "blue",
size = 4) +
annotate("pointrange",
x = mean(ICU$Pulse, na.rm = TRUE),
y = mean(ICU$Age, na.rm = TRUE),
ymin = mean(ICU$Age, na.rm = TRUE),
ymax = mean(ICU$Age, na.rm = TRUE),
color = "red",
size = 2) +
stat_ellipse(linetype = "dashed")
hatvalues()
.hat
value: augment()
from broom packagehatvalues()
1 2 3 4 5 6 7
0.04136616 0.04193692 0.02038323 0.02868237 0.03909928 0.02054581 0.04833027
8 9 10 11 12 13 14
0.02676640 0.02572493 0.02918766 0.02802245 0.03910343 0.03386752 0.04735363
15 16 17 18 19 20 21
0.03205395 0.02595774 0.03209545 0.02134725 0.02185566 0.04258039 0.03541913
22 23 24 25 26 27 28
0.06151462 0.02853602 0.02468023 0.02064414 0.02803684 0.04139703 0.03119456
29 30 31 32 33 34 35
0.02144683 0.06060417 0.01887221 0.03292118 0.02384578 0.04691193 0.03465486
36 37 38 39 40 41 42
0.04347021 0.04875004 0.01691440 0.02291959 0.02774395 0.04082458 0.03992122
43 44 45 46 47 48 49
0.03859821 0.02506167 0.02505285 0.03525264 0.08745421 0.04394462 0.02320841
50 51 52 53 54 55 56
0.06811084 0.02658598 0.03343375 0.03451670 0.04765859 0.03440951 0.04627143
57 58 59 60 61 62 63
0.05858381 0.03742786 0.03961405 0.02717904 0.01852133 0.02332432 0.05111651
64 65 66 67 68 69 70
0.04346598 0.02468261 0.03152511 0.02466933 0.04996516 0.04636771 0.02213098
71 72 73 74 75 76 77
0.03373205 0.04023063 0.02478997 0.03386846 0.02579042 0.04942887 0.03371832
78 79 80 81 82 83 84
0.02076133 0.04039878 0.08388916 0.02664010 0.02037631 0.04253115 0.03320655
85 86 87 88 89 90 91
0.03446771 0.03413661 0.03105504 0.02060281 0.02100419 0.03725994 0.01970532
92 93 94 95 96 97 98
0.03137055 0.06045898 0.02893790 0.04554696 0.03883473 0.04452235 0.02419923
99 100 101 102 103 104 105
0.04103317 0.04157161 0.04263943 0.02834146 0.03718586 0.05326585 0.04575464
106 107 108 109 110 111 112
0.04134128 0.04924349 0.02317801 0.03378472 0.02522227 0.04353502 0.04001761
113 114 115 116 117 118 119
0.03365728 0.02431396 0.03067899 0.02419923 0.02889805 0.02072236 0.04452363
120 121 122 123 124 125 126
0.02657169 0.03704621 0.03349834 0.05330341 0.03367753 0.03904766 0.04777942
127 128 129 130 131 132 133
0.02935877 0.03577744 0.03885206 0.02773097 0.07196314 0.05090712 0.02046498
134 135 136 137 138 139 140
0.03231415 0.02599930 0.03545566 0.04728562 0.03446484 0.03948813 0.02513356
141 142 143 144 145 146 147
0.03918547 0.02311702 0.02587308 0.02725079 0.01829482 0.02781909 0.05032186
148 149 150 151 152 153 154
0.04081059 0.03249827 0.03569586 0.04139041 0.02789797 0.04382672 0.05040804
155 156 157 158 159 160 161
0.03172093 0.01894094 0.03222629 0.03516660 0.07547144 0.07788693 0.03140165
162 163 164 165 166 167 168
0.01823211 0.03893800 0.03294626 0.02311711 0.03260965 0.04524500 0.03446130
169 170 171 172 173 174 175
0.02021935 0.03541123 0.03357409 0.01683831 0.02664340 0.03274660 0.02132949
176 177 178 179 180 181 182
0.02242424 0.02664338 0.02779856 0.05677280 0.03169522 0.05465986 0.03619239
183 184 185 186 187 188 189
0.03233791 0.03169522 0.02125515 0.05362754 0.02740321 0.03917655 0.02877631
190 191 192 193 194 195 196
0.04178583 0.02413103 0.02456579 0.04330927 0.02560642 0.02355296 0.04929066
197 198 199 200
0.02820125 0.02644314 0.01896565 0.01786346
augment()
# A tibble: 200 × 15
SysBP ID Survive Age AgeGroup Sex Infection Pulse Emergency .fitted
<int> <int> <int> <int> <int> <int> <int> <int> <int> <dbl>
1 80 4 0 87 3 1 1 96 1 118.
2 142 8 1 27 1 1 1 88 1 123.
3 112 12 1 59 2 0 0 80 1 136.
4 100 14 1 77 3 0 0 70 0 146.
5 128 27 0 76 3 1 1 90 1 117.
6 142 28 1 54 2 0 1 103 1 123.
7 110 32 1 87 3 1 1 154 1 133.
8 110 38 1 69 2 0 1 132 1 126.
9 104 40 1 63 2 0 0 66 0 145.
10 144 41 1 30 1 1 0 110 1 138.
# ℹ 190 more rows
# ℹ 5 more variables: .resid <dbl>, .hat <dbl>, .sigma <dbl>, .cooksd <dbl>,
# .std.resid <dbl>
ggplot(data = m1_aug,
aes(x = c(1:nrow(m1_aug)),
y = .hat)) +
geom_point() +
geom_hline(yintercept = 3*(6+1)/200,
color = "red",
linetype = "dashed") +
geom_hline(yintercept = 2*(6+1)/200,
color = "blue") +
geom_text(aes(label=ifelse((.hat > 2*(6+1)/200),
as.character(ID),
'')),
hjust = 0, nudge_x = 2)
Residual = \(e_i = Y_i - \hat{Y}_i\)
Problems
ggplot(data = dat_out,
aes(x = x, y = y)) +
geom_point(size = 2) +
geom_smooth(data = dat_out, method = "lm", se = FALSE, color = "black") +
geom_smooth(data = dat_del, method = "lm", se = FALSE, color = "red", linetype = "dashed") +
annotate("rect", xmin = 13.5, xmax = 14.5, ymin = 46, ymax = 54, fill = "red", alpha = 0.2) +
ylim(0, 60)
“Studentized” = standardized
Internally studentized residual = \(\frac{e_i}{SD_{e_i}}\)
Problems
rstudent()
function from the car package ID Survive Age AgeGroup Sex Infection SysBP Pulse Emergency esresid
1 4 0 87 3 1 1 80 96 1 -1.2312289
2 8 1 27 1 1 1 142 88 1 0.6009965
3 12 1 59 2 0 0 112 80 1 -0.7763291
4 14 1 77 3 0 0 100 70 0 -1.4932232
5 27 0 76 3 1 1 128 90 1 0.3669971
6 28 1 54 2 0 1 142 103 1 0.6059387
ggplot(data = m1_stresid,
aes(x = c(1:nrow(m1_stresid)),
y = esresid)) +
geom_point() +
geom_hline(yintercept = 2,
color = "blue",
linetype = "dashed") +
geom_hline(yintercept = -2,
color = "blue",
linetype = "dashed") +
geom_text(aes(label=ifelse((esresid > 2),
as.character(ID),
'')),
hjust = 0, nudge_x = 2) +
geom_text(aes(label=ifelse((esresid < -2),
as.character(ID),
'')),
hjust = 0, nudge_x = 2)
ID
= 921?Leverage
Discrepancy