Skip to content
Snippets Groups Projects
Commit 0a615d90 authored by Oliver Müller's avatar Oliver Müller
Browse files

Clean up week 04

parent 5814269c
No related branches found
No related tags found
No related merge requests found
......@@ -137,11 +137,7 @@ ggplot(data = data) +
`SalePrice` and `LotArea`.
```{r}
ggplot(data = data) +
geom_point(mapping = aes(x = LotArea, y = SalePrice), alpha = 0.3) +
geom_smooth(mapping = aes(x = LotArea, y = SalePrice), method = "loess") +
scale_y_continuous(labels = comma) +
scale_x_log10(labels = comma)
# YOUR CODE GOES HERE
```
......@@ -161,10 +157,7 @@ ggplot(data = data) +
`SalePrice` and `OverallCond`.
```{r}
ggplot(data = data) +
geom_boxplot(mapping = aes(y = SalePrice, x = OverallCond)) +
geom_jitter(mapping = aes(y = SalePrice, x = OverallCond), color = "darkgreen", alpha = 0.1) +
scale_y_log10(labels = comma)
# YOUR CODE GOES HERE
```
......@@ -185,8 +178,7 @@ stargazer(fit_01, intercept.bottom = FALSE, single.row = TRUE, type = "text")
Create a simple linear regression model with `BedroomAbvGr` as the only explanatory variable.
```{r}
fit_02 <- lm(SalePrice ~ BedroomAbvGr, data = data)
stargazer(fit_02, intercept.bottom = FALSE, single.row = TRUE, type = "text")
# YOUR CODE GOES HERE
```
......@@ -195,8 +187,7 @@ stargazer(fit_02, intercept.bottom = FALSE, single.row = TRUE, type = "text")
Create a multiple linear regression model with `GrLivArea` and `BedroomAbvGr` as explanatory variables.
```{r}
fit_03 <- lm(SalePrice ~ GrLivArea + BedroomAbvGr, data = data)
stargazer(fit_03, intercept.bottom = FALSE, single.row = TRUE, type = "text")
# YOUR CODE GOES HERE
```
......@@ -301,22 +292,6 @@ plotmo(fit_08)
```
It's also possible to visually analyze interactions between explanatory variables, as we modeled them in model `fit_05`.
The `level` argument controls which confidence (grey) and prediction (red) intervals should be plotted. The prediction interval, for example, tells us that, according to our model, 95% of the houses with a specific `GrLivArea` have a `SalePrice` within the shaded area. Read more about the difference between confidence and prediction intervals here: <http://www.sthda.com/english/articles/40-regression-analysis/166-predict-in-r-model-predictions-and-confidence-intervals/>.
```{r}
plotmo(fit_05,
degree1 = c(),
#degree1 = c("GrLivArea"),
#degree2 = c(),
degree2 = c("GrLivArea", "LotArea"),
persp.ticktype="detailed",
level=.95,
theta=-35)
```
# Your Turn...
Improve the above models, e.g., by including more variables and interaction effects. Try to find a balance between model fit and interpretability. Note: We are doing explanatory modeling here, not prediction! Hence, we are not working with a train/test split of the data.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment