요즘 태어나서 최초로 껵고있는 코로나19로 인해 연구실에도 나가지 않고 집에서 평소에 부진했거나 더 깊이 들어가고 싶은 공부를 하는 중이다. 물론 지금 진행중인 논문을 위한 작업이기도 하다. 오늘도 자료를 찾다가 얻어 걸린 그림을 하나 소개할까 한다.
OLS의 결과 residual값이 크면 큰 원을, 작으면 작은 원으로 보려주면서 색상도 같이 빨강, 초록(검정) 등으로 변환해준다.
https://rpubs.com/iabrady/residual-analysis
d <- mtcars
fit <- lm(mpg ~ wt, data = d)
d$predicted <- predict(fit)
d$residuals <- residuals(fit)
ggplot(d, aes(x = wt, y = mpg)) +
geom_smooth(method = "lm", se = FALSE, color = "lightgrey") +
geom_segment(aes(xend = wt, yend = predicted), alpha = .2) +
geom_point(aes(color = abs(residuals), size = abs(residuals))) +
scale_color_continuous(low = "green", high = "red") +
guides(color = FALSE, size = FALSE) +
geom_point(aes(y = predicted), shape = 1) +
theme_bw()
![](https://t1.daumcdn.net/cfile/cafe/995859365E83DC3F21)
더 많은 자료들이 소개되어 있는 자료도 있다.
https://drsimonj.svbtle.com/visualising-residuals
![](https://t1.daumcdn.net/cfile/cafe/995715365E83DC3F21)