-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hauspreis-stratifizieren.Rmd
50 lines (39 loc) · 1.12 KB
/
Hauspreis-stratifizieren.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
```{r}
d <-
d %>%
mutate(size_group = case_when(
livingArea < quantile(livingArea, prob = .25) ~ 1,
livingArea < quantile(livingArea, prob = .5) ~ 2,
livingArea < quantile(livingArea, prob = .75) ~ 3,
TRUE ~ 4
))
```
```{r results='hide'}
m2a <- stan_glm(price ~ bedrooms + size_group, data = d)
```
```{r}
d_m2a <-
tibble(
size_group = 1:4,
intercept = coef(m2a)[1] + size_group * coef(m2a)[3],
slope = coef(m2a)[2]
)
```
```{r fig.asp = 0.4, fig.width=7}
size_group_labs <-
c(`1` = "sehr kleine Häuser (q1)",
`2` = "eher kleine Häuser (q2)",
`3` = "eher große Häuser (q3)",
`4` = "sehr große Häuser (q4)")
d %>%
ggplot(aes(x = bedrooms, y = price)) +
geom_jitter(alpha = .3) +
geom_abline(data = d_m2a,
aes(intercept = intercept,
slope = slope),
color = "blue",
size = 2) +
facet_wrap(~ size_group, nrow = 1, labeller = as_labeller(size_group_labs)) +
labs(title = "Hauspreis als Funktion von Zimmerzahl und Quadratmeter",
caption = "Facetten zeigen Quartile der Variable 'Quadratmeter'")
```