We use the diamonds dataset shipped with
ggplot2 — 53,940 diamonds.
library(ggplot2)
nrow(diamonds)
## [1] 53940
summary(diamonds$price)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 326 950 2401 3933 5324 18823
A linear regression of price on carat, cut, and color:
fit <- lm(price ~ carat + cut + color, data = diamonds)
round(summary(fit)$r.squared, 3)
## [1] 0.871
predict() on the fitted model, updated
reactively.Thank you!