model_apartments <- lm(log_price_m2 ~ month_id + centreDistance +
squareMeters +
age +
floor_ratio +
city +
hasElevator +
hasBalcony +
hasSecurity +
hasParkingSpace +
hasStorageRoom +
poiCount +
condition,
data = apartments, na.action = na.exclude)
coef_apartments <- tidy(model_apartments, conf.int = TRUE) %>%
filter(term != "(Intercept)") %>%
arrange(estimate)
summary(model_apartments)
##
## Call:
## lm(formula = log_price_m2 ~ month_id + centreDistance + squareMeters +
## age + floor_ratio + city + hasElevator + hasBalcony + hasSecurity +
## hasParkingSpace + hasStorageRoom + poiCount + condition,
## data = apartments, na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.35577 -0.05333 -0.00386 0.04864 0.47458
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.017e+00 2.132e-03 1883.521 < 2e-16 ***
## month_id 7.267e-03 6.618e-05 109.802 < 2e-16 ***
## centreDistance -1.324e-02 1.034e-04 -128.049 < 2e-16 ***
## squareMeters -1.085e-03 1.026e-05 -105.742 < 2e-16 ***
## age -7.191e-04 9.067e-06 -79.315 < 2e-16 ***
## floor_ratio -9.421e-03 7.573e-04 -12.440 < 2e-16 ***
## cityBydgoszcz -5.179e-02 2.142e-03 -24.174 < 2e-16 ***
## cityCzestochowa -1.150e-01 3.415e-03 -33.685 < 2e-16 ***
## cityGdansk 2.139e-01 1.990e-03 107.466 < 2e-16 ***
## cityGdynia 1.648e-01 2.124e-03 77.614 < 2e-16 ***
## cityKatowice -4.303e-03 2.400e-03 -1.793 0.0729 .
## cityKrakow 2.442e-01 1.942e-03 125.771 < 2e-16 ***
## cityLodz -1.882e-02 2.049e-03 -9.186 < 2e-16 ***
## cityLublin 2.308e-02 2.213e-03 10.428 < 2e-16 ***
## cityPoznan 8.567e-02 2.200e-03 38.946 < 2e-16 ***
## cityRadom -1.270e-01 2.512e-03 -50.561 < 2e-16 ***
## cityRzeszow 3.160e-02 2.962e-03 10.669 < 2e-16 ***
## citySzczecin 1.129e-02 2.211e-03 5.107 3.28e-07 ***
## cityWarszawa 3.021e-01 1.939e-03 155.805 < 2e-16 ***
## cityWroclaw 1.569e-01 1.966e-03 79.817 < 2e-16 ***
## hasElevatorTRUE 2.527e-02 5.129e-04 49.278 < 2e-16 ***
## hasBalconyTRUE 7.911e-03 4.864e-04 16.266 < 2e-16 ***
## hasSecurityTRUE 2.017e-02 6.913e-04 29.172 < 2e-16 ***
## hasParkingSpaceTRUE 7.079e-03 5.110e-04 13.854 < 2e-16 ***
## hasStorageRoomTRUE -2.099e-02 4.868e-04 -43.120 < 2e-16 ***
## poiCount 8.315e-04 1.118e-05 74.390 < 2e-16 ***
## conditionlow -4.566e-02 7.274e-04 -62.766 < 2e-16 ***
## conditionpremium 2.797e-02 6.338e-04 44.125 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.07932 on 135101 degrees of freedom
## (60439 obserwacji zostało skasowanych z uwagi na braki w nich zawarte)
## Multiple R-squared: 0.7556, Adjusted R-squared: 0.7555
## F-statistic: 1.547e+04 on 27 and 135101 DF, p-value: < 2.2e-16
ggplot(coef_apartments, aes(x = reorder(term, estimate), y = estimate)) +
geom_col(fill = "purple") +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high),
width = 0.2) +
coord_flip() +
theme_minimal() +
labs(
title = "Wpływ zmiennych na log(cena/m²) – kupno",
x = "Zmienna",
y = "Współczynnik (β)"
)

par(mfrow = c(2,2))
plot(model_apartments)

numeric_df <- apartments %>%
select(price_m2, month_id,
centreDistance,
squareMeters,
age,
floor_ratio,
hasElevator,
hasBalcony,
hasSecurity,
hasParkingSpace,
hasStorageRoom,
poiCount)
corr <- cor(numeric_df, use = "complete.obs")
melted <- melt(corr)
ggplot(melted, aes(Var1, Var2, fill = value)) +
geom_tile() +
scale_fill_viridis_c(option = "plasma") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

model_rent <- lm(log_price_m2 ~ month_id + centreDistance +
squareMeters +
age +
floor_ratio +
city +
hasElevator +
hasBalcony +
hasSecurity +
hasParkingSpace +
hasStorageRoom +
poiCount +
condition,
data = rent, na.action = na.exclude)
coef_rent <- tidy(model_rent, conf.int = TRUE) %>%
filter(term != "(Intercept)") %>%
arrange(estimate)
summary(model_rent)
##
## Call:
## lm(formula = log_price_m2 ~ month_id + centreDistance + squareMeters +
## age + floor_ratio + city + hasElevator + hasBalcony + hasSecurity +
## hasParkingSpace + hasStorageRoom + poiCount + condition,
## data = rent, na.action = na.exclude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.55400 -0.06394 -0.00385 0.05956 0.41200
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.685e+00 5.908e-03 285.257 < 2e-16 ***
## month_id -5.041e-04 1.917e-04 -2.630 0.00855 **
## centreDistance -1.435e-02 2.177e-04 -65.903 < 2e-16 ***
## squareMeters -7.686e-04 1.985e-05 -38.729 < 2e-16 ***
## age -9.862e-04 1.863e-05 -52.924 < 2e-16 ***
## floor_ratio 1.343e-02 1.558e-03 8.622 < 2e-16 ***
## cityBydgoszcz 6.391e-02 6.528e-03 9.790 < 2e-16 ***
## cityCzestochowa 1.172e-02 1.054e-02 1.112 0.26628
## cityGdansk 2.255e-01 5.777e-03 39.041 < 2e-16 ***
## cityGdynia 1.668e-01 6.258e-03 26.663 < 2e-16 ***
## cityKatowice 9.361e-02 5.925e-03 15.801 < 2e-16 ***
## cityKrakow 2.132e-01 5.494e-03 38.813 < 2e-16 ***
## cityLodz 6.050e-02 5.682e-03 10.649 < 2e-16 ***
## cityLublin 8.319e-02 6.555e-03 12.691 < 2e-16 ***
## cityPoznan 1.208e-01 5.743e-03 21.037 < 2e-16 ***
## cityRadom -8.441e-03 1.079e-02 -0.783 0.43388
## cityRzeszow 8.809e-02 6.939e-03 12.695 < 2e-16 ***
## citySzczecin 1.118e-01 6.090e-03 18.356 < 2e-16 ***
## cityWarszawa 3.324e-01 5.499e-03 60.446 < 2e-16 ***
## cityWroclaw 1.972e-01 5.581e-03 35.324 < 2e-16 ***
## hasElevatorTRUE 2.012e-02 1.134e-03 17.736 < 2e-16 ***
## hasBalconyTRUE -1.670e-03 1.004e-03 -1.663 0.09638 .
## hasSecurityTRUE 5.100e-03 1.226e-03 4.159 3.20e-05 ***
## hasParkingSpaceTRUE -3.787e-03 9.585e-04 -3.950 7.81e-05 ***
## hasStorageRoomTRUE -5.829e-03 1.247e-03 -4.675 2.94e-06 ***
## poiCount 4.513e-04 2.156e-05 20.934 < 2e-16 ***
## conditionlow -4.857e-02 7.972e-03 -6.093 1.12e-09 ***
## conditionpremium 1.519e-02 9.983e-04 15.217 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.09289 on 45442 degrees of freedom
## (25377 obserwacji zostało skasowanych z uwagi na braki w nich zawarte)
## Multiple R-squared: 0.5246, Adjusted R-squared: 0.5243
## F-statistic: 1857 on 27 and 45442 DF, p-value: < 2.2e-16
ggplot(coef_rent, aes(x = reorder(term, estimate), y = estimate)) +
geom_col(fill = "seagreen") +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high),
width = 0.2) +
coord_flip() +
theme_minimal() +
labs(
title = "Wpływ zmiennych na log(cena/m²) – wynajem",
x = "Zmienna",
y = "Współczynnik (β)"
)

par(mfrow = c(2,2))
plot(model_rent)

numeric_df <- rent %>%
select(price_m2, month_id,
centreDistance,
squareMeters,
age,
floor_ratio,
hasElevator,
hasBalcony,
hasSecurity,
hasParkingSpace,
hasStorageRoom,
poiCount)
corr <- cor(numeric_df, use = "complete.obs")
melted <- melt(corr)
ggplot(melted, aes(Var1, Var2, fill = value)) +
geom_tile() +
scale_fill_viridis_c() +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
