rent + apartments

This commit is contained in:
2026-05-04 15:45:49 +02:00
parent 2e9a54b539
commit 53c28d05e8
+75 -57
View File
@@ -21,12 +21,12 @@ fig.height = 5
# Import data
The dataset contains apartment sales and rent offers from the 15 largest cities in Poland (Warsaw, Lodz, Krakow, Wroclaw, Poznan, Gdansk, Szczecin, Bydgoszcz, Lublin, Katowice, Bialystok, Czestochowa). The data comes from local websites with apartments for sale. To fully capture the neighborhood of each apartment better, each offer was extended by data from the Open Street Map with distances to points of interest (POI). The data is collected monthly and covers a timespan between August 2023 and June 2024
The dataset contains apartment sales and df offers from the 15 largest cities in Poland (Warsaw, Lodz, Krakow, Wroclaw, Poznan, Gdansk, Szczecin, Bydgoszcz, Lublin, Katowice, Bialystok, Czestochowa). The data comes from local websites with apartments for sale. To fully capture the neighborhood of each apartment better, each offer was extended by data from the Open Street Map with distances to points of interest (POI). The data is collected monthly and covers a timespan between August 2023 and June 2024
## Files
- apartments_pl_YYYY_MM.csv: sale price
- apartments_rent_pl_YYYY_MM.csv: monthly rent
- apartments_df_pl_YYYY_MM.csv: monthly df
## Data Fields
1. ```city``` - the name of the city where the property is located
@@ -47,49 +47,56 @@ The dataset contains apartment sales and rent offers from the 15 largest cities
```{r import data}
files <- list.files("rent", pattern = "\\.csv$", full.names = TRUE)
files <- sort(files)
files_rent <- list.files("rent", pattern = "\\.csv$", full.names = TRUE)
files_apartments <- list.files("apartments", pattern = "\\.csv$", full.names = TRUE)
df_list <- lapply(seq_along(files), function(i) {
d <- read.csv(files[i])
d$month_id <- i
rent_list <- lapply(seq_along(files_rent), function(i) {
d <- read.csv(files_rent[i])
d$type = "rent"
d
})
rent <- do.call(rbind, df_list)
apartments_list <- lapply(seq_along(files_apartments), function(i) {
d <- read.csv(files_apartments[i])
d$type = "apartment"
d
})
df <- do.call(rbind, c(rent_list, apartments_list))
# price/m^2
rent$price_m2 <- rent$price / rent$squareMeters
rent$log_price <- log(rent$price_m2)
rent$floor_ratio <- rent$floor / rent$floorCount
rent$age <- 2024 - rent$buildYear
df$price_m2 <- df$price / df$squareMeters
df$log_price <- log(df$price)
df$log_price_m2 <- log(df$price_m2)
df$floor_ratio <- df$floor / df$floorCount
df$age <- 2024 - df$buildYear
has_cols <- grep("^has", names(rent), value = TRUE)
has_cols <- grep("^has", names(df), value = TRUE)
rent[has_cols] <- lapply(rent[has_cols], function(x) {
df[has_cols] <- lapply(df[has_cols], function(x) {
tolower(x) == "yes"
})
rent$poi_group <- cut(rent$poiCount,
breaks = c(-1, 2, 5, 10, Inf),
labels = c("0–2", "3–5", "6–10", "11+"))
rent_norm <- rent %>%
df <- df %>%
group_by(city) %>%
mutate(
latitude_n = as.numeric(scale(latitude)),
longitude_n = as.numeric(scale(longitude)),
price_n = (price - min(price)) / (max(price) - min(price))
longitude_n = as.numeric(scale(longitude))
) %>%
ungroup() %>%
group_by(type) %>%
mutate(
price_n = as.numeric(scale(price)),
price_m2_n = as.numeric(scale(price_m2)),
log_price_n = as.numeric(scale(log_price)),
log_price_m2_n = as.numeric(scale(log_price_m2))
) %>%
mutate() %>%
ungroup()
rent_wo_outliers <- rent %>%
group_by(city) %>%
filter(floor >= 7) %>%
ungroup()
cities <- unique(rent$city)
rent <- df[df$type == "rent",]
rent_warsaw <- rent[rent$city == "warszawa",]
apartments <- df[df$type == "apartment",]
apartments_warsaw <- apartments[apartments$city == "warszawa",]
```
# Wykresy
@@ -98,75 +105,86 @@ cities <- unique(rent$city)
ggplot(rent, aes(x = city, y = price_m2)) +
geom_violin(fill = "lightgray", alpha = 0.3) +
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
stat_summary(fun = mean,
geom = "point",
shape = 21,
size = 0.1,
fill = "red") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Rozkład ceny za m² w miastach",
labs(title = "Rozkład ceny wynajmu za m² w miastach",
x = "Miasto",
y = "Cena za m² (PLN)")
ggplot(apartments, aes(x = city, y = price_m2)) +
geom_violin(fill = "lightgray", alpha = 0.3) +
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Rozkład ceny kupna mieszkania za m² w miastach",
x = "Miasto",
y = "Cena za m² (PLN)")
ggplot(rent, aes(x=centreDistance, y=price_m2, col = buildYear)) +
geom_point(, alpha=0.1, size=0.5) +
geom_point(alpha=0.1, size=0.5) +
geom_smooth(method = "lm", se = TRUE, color = "red") +
facet_wrap(~ city) +
theme_minimal() +
labs(
title = "Cena za m² vs odległość od centrum",
title = "Cena za m² vs odległość od centrum (wynajem)",
x = "Odległość od centrum (km)",
y = "Cena za m² (PLN)")
ggplot(rent_norm, aes(x=longitude_n, y=latitude_n, col=price_m2)) +
ggplot(apartments, aes(x=centreDistance, y=price_m2, col = buildYear)) +
geom_point(alpha=0.1, size=0.5) +
geom_smooth(method = "lm", se = TRUE, color = "red") +
facet_wrap(~ city) +
theme_minimal() +
labs(
title = "Cena za m² vs odległość od centrum (kupno)",
x = "Odległość od centrum (km)",
y = "Cena za m² (PLN)")
ggplot(rent, aes(x=longitude_n, y=latitude_n, col=price_m2_n)) +
geom_point(alpha=0.01, size=0.2) +
facet_wrap(~ city) +
scale_color_viridis_c() +
theme_minimal()
ggplot(rent[rent$city=="warszawa", ], aes(x=longitude, y=latitude, col=log(price))) +
ggplot(apartments, aes(x=longitude_n, y=latitude_n, col=price_m2_n)) +
geom_point(alpha=0.01, size=0.2) +
facet_wrap(~ city) +
scale_color_viridis_c() +
theme_minimal()
ggplot(rent_warsaw, aes(x=longitude, y=latitude, col=log_price)) +
geom_point(alpha=0.1, size=0.2) +
scale_color_viridis_c() +
theme_minimal()
ggplot(rent[rent$city=="warszawa", ], aes(x=longitude, y=latitude, col=price_m2)) +
ggplot(apartments_warsaw, aes(x=longitude, y=latitude, col=log_price)) +
geom_point(alpha=0.1, size=0.2) +
scale_color_viridis_c() +
theme_minimal()
ggplot(rent, aes(x = poi_group, y = price_m2)) +
geom_boxplot(fill = "lightgray") +
stat_summary(fun = mean, geom = "point", shape = 21, size = 3, fill = "red") +
theme_minimal() +
labs(
title = "Cena za m² w zależności od dostępności POI",
x = "POI (grupy)",
y = "Cena za m² (PLN)"
)
```
# Czy ceny normalne?
```{r lillieford}
log_rent <- log(rent$price_m2)
prices_overall <- log_rent
log_df <- log(df$price_m2)
prices_overall <- log_df
lillie.test(log(rent_wo_outliers[rent_wo_outliers$city == "warszawa",]$price_m2))
lillie.test(log(df_wo_outliers[df_wo_outliers$city == "warszawa",]$price_m2))
df_plot <- data.frame(log_price = log_rent)
df_plot <- data.frame(log_price = log_df)
ggplot(df_plot, aes(x = log_price)) +
geom_histogram(aes(y = after_stat(density)),
bins = 50,
fill = "lightblue",
color = "white")
qqnorm(log_rent)
qqline(log_rent, col = "red")
qqnorm(log_df)
qqline(log_df, col = "red")
qqnorm(log(rent_wo_outliers$price_m2))
qqline(log(rent_wo_outliers$price_m2), col = "red")
qqnorm(log(df_wo_outliers$price_m2))
qqline(log(df_wo_outliers$price_m2), col = "red")
```
# Model liniowy
@@ -179,7 +197,7 @@ model <- lm(log_price ~ centreDistance +
hasElevator +
hasBalcony + hasSecurity +
condition,
data = rent)
data = df)
summary(model)
par(mfrow = c(2,2))
plot(model)