bombom
This commit is contained in:
+105
-85
@@ -9,14 +9,16 @@ output:
|
|||||||
|
|
||||||
```{r setup, include=FALSE}
|
```{r setup, include=FALSE}
|
||||||
knitr::opts_chunk$set(echo = TRUE)
|
knitr::opts_chunk$set(echo = TRUE)
|
||||||
|
library(ggplot2)
|
||||||
|
library(patchwork)
|
||||||
library(dplyr)
|
library(dplyr)
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
library(nortest)
|
library(nortest)
|
||||||
library(tidyr)
|
library(tidyr)
|
||||||
library(purrr)
|
library(purrr)
|
||||||
library(broom)
|
library(broom)
|
||||||
fig.width = 8
|
fig.width = 10
|
||||||
fig.height = 5
|
fig.height = 10
|
||||||
```
|
```
|
||||||
|
|
||||||
# O danych
|
# O danych
|
||||||
@@ -25,25 +27,20 @@ Zestaw danych zawiera oferty sprzedaży (na przestrzeni dwunastu miesięcy) oraz
|
|||||||
|
|
||||||
Dane są zbierane miesięcznie i obejmują okres od sierpnia 2023 roku do czerwca 2024 roku.
|
Dane są zbierane miesięcznie i obejmują okres od sierpnia 2023 roku do czerwca 2024 roku.
|
||||||
|
|
||||||
## Files
|
|
||||||
|
|
||||||
- apartments_pl_YYYY_MM.csv: sale price
|
|
||||||
- apartments_df_pl_YYYY_MM.csv: monthly df
|
|
||||||
|
|
||||||
## Parametry danych
|
## Parametry danych
|
||||||
1. ```city``` - nazwa miasta, w którym znajduje się mieszkanie
|
1. ```city``` - nazwa miasta, w którym znajduje się mieszkanie
|
||||||
1. ```squareMeters``` - powierzchnia mieszkania w metrach kwadratowych
|
1. ```squareMeters``` - powierzchnia mieszkania w metrach kwadratowych
|
||||||
1. ```rooms``` - liczba pomieszczeń w mieszkaniu
|
1. ```rooms``` - liczba pomieszczeń w mieszkaniu
|
||||||
1. ```floor``` floorCount - the floor where the apartment is located and the total number of floors in the building
|
1. ```floor``` floorCount - the floor where the apartment is located and the total number of floors in the building
|
||||||
1. ```buildYear``` - the year when the building was built
|
1. ```buildYear``` - rok wybudowania
|
||||||
1. ```latitude```, ```longitude``` - geo coordinate of the property
|
1. ```latitude```, ```longitude``` - wysokość oraz szerokość geograficzna
|
||||||
1. ```centreDistance``` - distance from the city centre in km
|
1. ```centreDistance``` - odległość od centrum mierzona w kilometrach
|
||||||
1. ```poiCount``` - number of points of interest in 500m range from the apartment (schools, clinics, post offices, kindergartens, restaurants, colleges, pharmacies)
|
1. ```poiCount``` - number of points of interest in 500m range from the apartment (schools, clinics, post offices, kindergartens, restaurants, colleges, pharmacies)
|
||||||
1. ```[poiName]Distance``` - distance to the nearest point of interest (schools, clinics, post offices, kindergartens, restaurants, colleges, pharmacies)
|
1. ```[poiName]Distance``` - distance to the nearest point of interest (schools, clinics, post offices, kindergartens, restaurants, colleges, pharmacies)
|
||||||
1. ```ownership``` - the type of property ownership
|
|
||||||
1. ```condition``` - the condition of the apartment
|
1. ```condition``` - the condition of the apartment
|
||||||
1. ```has[features]``` - whether the property has key features such as assigned parking space, balcony, elevator, security, storage room
|
1. ```has[features]``` - whether the property has key features such as assigned parking space, balcony, elevator, security, storage room
|
||||||
1. ```price``` - offer price in Polish Zloty
|
1. ```price``` - cena oferty w złotówkach
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -102,21 +99,17 @@ apartments_warsaw <- apartments[apartments$city == "warszawa",]
|
|||||||
|
|
||||||
# Wykresy
|
# Wykresy
|
||||||
|
|
||||||
```{r violin rent}
|
```{r violiny}
|
||||||
ggplot(rent, aes(x = city, y = price_m2)) +
|
ggplot(rent, aes(x = city, y = price_m2)) +
|
||||||
geom_violin(fill = "blue", alpha = 0.3) +
|
geom_violin(fill = "green", alpha = 0.3) +
|
||||||
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
|
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
|
||||||
theme_minimal() +
|
theme_minimal() +
|
||||||
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
|
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
|
||||||
labs(title = "Zależność ceny za m² od miasta (wynajem)",
|
labs(title = "Zależność ceny za m² od miasta (wynajem)",
|
||||||
x = "Miasto",
|
x = "Miasto",
|
||||||
y = "Cena za m² (PLN)")
|
y = "Cena za m² (PLN)")
|
||||||
```
|
|
||||||
|
|
||||||
```{r viloin apart}
|
|
||||||
|
|
||||||
ggplot(apartments, aes(x = city, y = price_m2)) +
|
ggplot(apartments, aes(x = city, y = price_m2)) +
|
||||||
geom_violin(fill = "lightgray", alpha = 0.3) +
|
geom_violin(fill = "purple", alpha = 0.3) +
|
||||||
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
|
geom_boxplot(width = 0.1, outlier.alpha = 0.01) +
|
||||||
theme_minimal() +
|
theme_minimal() +
|
||||||
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
|
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
|
||||||
@@ -125,54 +118,118 @@ ggplot(apartments, aes(x = city, y = price_m2)) +
|
|||||||
y = "Cena za m² (PLN)")
|
y = "Cena za m² (PLN)")
|
||||||
|
|
||||||
```
|
```
|
||||||
|
```{r heatmapy}
|
||||||
|
ggplot(rent, aes(x=longitude_n, y=latitude_n, col=price_m2_n)) +
|
||||||
|
geom_point(alpha=0.03, size=0.4) +
|
||||||
|
facet_wrap(~ city) +
|
||||||
|
scale_color_viridis_c(name = "Koszt wynajmu za m² (PLN)\n(ciemne znaczy droższe)", direction=-1) +
|
||||||
|
theme_minimal()+
|
||||||
|
labs(
|
||||||
|
title = "Dokładne położenie na mapie a koszt wynajmu",
|
||||||
|
x = "szerokość geograficzna",
|
||||||
|
y = "wysokość geograficzna")
|
||||||
|
ggplot(apartments, aes(x=longitude_n, y=latitude_n, col=price_m2_n)) +
|
||||||
|
geom_point(alpha=0.01, size=0.4) +
|
||||||
|
facet_wrap(~ city) +
|
||||||
|
scale_color_viridis_c(option="plasma", name = "Koszt kupna za m² (PLN)\n(ciemne znaczy droższe)", direction=-1) +
|
||||||
|
theme_minimal()+
|
||||||
|
labs(
|
||||||
|
title = "Dokładne położenie na mapie a koszt zakupu",
|
||||||
|
x = "szerokość geograficzna",
|
||||||
|
y = "wysokość geograficzna")
|
||||||
|
```
|
||||||
|
|
||||||
```{r prosta regresja ceny od odległości od centrum}
|
```{r heatmapy Warszawa}
|
||||||
|
ggplot(rent_warsaw, aes(x=longitude, y=latitude, col=log_price)) +
|
||||||
|
geom_point(alpha=0.2, size=0.4) +
|
||||||
|
scale_color_viridis_c(name = "Koszt wynajmu za m² (PLN)\n(ciemne znaczy droższe)", direction=-1) +
|
||||||
|
theme_minimal()+
|
||||||
|
labs(
|
||||||
|
title = "Dokładne położenie na mapie a koszt wynajmu",
|
||||||
|
x = "szerokość geograficzna",
|
||||||
|
y = "wysokość geograficzna")
|
||||||
|
|
||||||
|
ggplot(apartments_warsaw, aes(x=longitude, y=latitude, col=log_price)) +
|
||||||
|
geom_point(alpha=0.1, size=0.4) +
|
||||||
|
scale_color_viridis_c(option="plasma", name = "Koszt kupna za m² (PLN)\n(ciemne znaczy droższe)", direction=-1) +
|
||||||
|
theme_minimal()+
|
||||||
|
labs(
|
||||||
|
title = "Dokładne położenie na mapie a koszt zakupu",
|
||||||
|
x = "szerokość geograficzna",
|
||||||
|
y = "wysokość geograficzna")
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#Porównanie dystrybuanty empirycznej z dystrybuantą rozkładu normalnego
|
||||||
|
#o nieobciążonych estymatorach
|
||||||
|
```{r dystrybuanty}
|
||||||
|
x<-log(rent$price_m2)
|
||||||
|
t<-log(apartments$price_m2)
|
||||||
|
z <- seq(min(x,t), max(x,t), length.out = 300000)
|
||||||
|
dystrybuanta_empiryczna_wynajem<-ecdf(x)
|
||||||
|
dystrybuanta_empiryczna_kupno<-ecdf(t)
|
||||||
|
dystrybuanta_teoretyczna_wynajem<-pnorm(z, mean=mean(x), sd=sd(x))
|
||||||
|
dystrybuanta_teoretyczna_kupno<-pnorm(z, mean=mean(t), sd=sd(t))
|
||||||
|
ggplot() +
|
||||||
|
geom_step(
|
||||||
|
aes(x = z, y = dystrybuanta_empiryczna_wynajem(z), color = "Empiryczna wyn"),
|
||||||
|
linewidth = 1,
|
||||||
|
linetype = "solid"
|
||||||
|
) +
|
||||||
|
geom_line(
|
||||||
|
aes(x = z, y = dystrybuanta_teoretyczna_wynajem, color = "Teoretyczna wyn"),
|
||||||
|
linewidth = 1,
|
||||||
|
linetype = "dashed"
|
||||||
|
) +
|
||||||
|
geom_step(
|
||||||
|
aes(x=z, y=dystrybuanta_empiryczna_kupno(z), color = "Empiryczna kupna"),
|
||||||
|
linewidth = 1,
|
||||||
|
linetype="solid"
|
||||||
|
) +
|
||||||
|
geom_line(
|
||||||
|
aes(x=z, y=dystrybuanta_teoretyczna_kupno, color = "Teoretyczna kupna"),
|
||||||
|
linewidth = 1,
|
||||||
|
linetype="dashed"
|
||||||
|
) +
|
||||||
|
scale_color_manual(
|
||||||
|
values = c("Empiryczna wyn" = "green" , "Teoretyczna wyn" = "blue" , "Empiryczna kupna" = "purple", "Teoretyczna kupna" = "red" ),
|
||||||
|
labels = c("Empiryczna kupna", "Empiryczna wyn", "Teoretyczna kupna", "Teoretyczna wyn")
|
||||||
|
) +
|
||||||
|
labs(
|
||||||
|
title = "Dystrybuanty empiryczne i teoretyczne",
|
||||||
|
x = "Wartość",
|
||||||
|
y = "Prawdopodobieństwo skumulowane",
|
||||||
|
color = "Typ dystrybuanty"
|
||||||
|
) +
|
||||||
|
theme_minimal() +
|
||||||
|
theme(plot.title = element_text(hjust = 0.5))
|
||||||
|
```
|
||||||
|
|
||||||
|
```{r prosta regresja ceny od odległości od centrum dla wynajmu}
|
||||||
|
|
||||||
ggplot(rent, aes(x=centreDistance, y=price_m2)) +
|
ggplot(rent, aes(x=centreDistance, y=price_m2)) +
|
||||||
geom_point(color = "blue",alpha=0.03, size=0.3) +
|
geom_point(color = "green",alpha=0.1, size=0.3) +
|
||||||
geom_smooth(method = "lm", se = TRUE, color = "orange") +
|
geom_smooth(method = "lm", se = TRUE, color = "orange") +
|
||||||
facet_wrap(~ city) +
|
facet_wrap(~ city) +
|
||||||
theme_minimal() +
|
theme_minimal() +
|
||||||
labs(
|
labs(
|
||||||
title = "Cena za m² vs odległość od centrum (wynajem)",
|
title = "Zależność ceny za m² od odległości od centrum (wynajem)",
|
||||||
x = "Odległość od centrum (km)",
|
x = "Odległość od centrum (km)",
|
||||||
y = "Cena za m² (PLN)")
|
y = "Cena za m² (PLN)")
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
ggplot(apartments, aes(x=centreDistance, y=price_m2, col = buildYear)) +
|
```{r prosta regresja ceny od odległości od centrum dla kupna}
|
||||||
geom_point(alpha=0.1, size=0.5) +
|
ggplot(apartments, aes(x=centreDistance, y=price_m2)) +
|
||||||
geom_smooth(method = "lm", se = TRUE, color = "red") +
|
geom_point(color = "purple", alpha=0.1, size=0.3) +
|
||||||
|
geom_smooth(method = "lm", se = TRUE, color = "orange") +
|
||||||
facet_wrap(~ city) +
|
facet_wrap(~ city) +
|
||||||
theme_minimal() +
|
theme_minimal() +
|
||||||
labs(
|
labs(
|
||||||
title = "Cena za m² vs odległość od centrum (kupno)",
|
title = "Zależność ceny za m² od odległości od centrum (kupno)",
|
||||||
x = "Odległość od centrum (km)",
|
x = "Odległość od centrum (km)",
|
||||||
y = "Cena za m² (PLN)")
|
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(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(apartments_warsaw, aes(x=longitude, y=latitude, col=log_price)) +
|
|
||||||
geom_point(alpha=0.1, size=0.2) +
|
|
||||||
scale_color_viridis_c() +
|
|
||||||
theme_minimal()
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
# Czy ceny normalne?
|
# Czy ceny normalne?
|
||||||
@@ -223,41 +280,4 @@ model_apartments <- lm(log_price_m2_n ~ centreDistance +
|
|||||||
summary(model_apartments)
|
summary(model_apartments)
|
||||||
par(mfrow = c(2,2))
|
par(mfrow = c(2,2))
|
||||||
plot(model_apartments)
|
plot(model_apartments)
|
||||||
```
|
|
||||||
|
|
||||||
#porównanie dystrybuanty empirycznej z teoretyczną
|
|
||||||
```{r dyst empi vs dyst teor}
|
|
||||||
install.packages("ggplot2")
|
|
||||||
library(ggplot2)
|
|
||||||
x<-log(rent$price_m2)
|
|
||||||
z <- seq(min(x), max(x), length.out = 20000)
|
|
||||||
dystrybuanta_empiryczna<-ecdf(x)
|
|
||||||
dystrybuanta_teoretyczna<-pnorm(z, mean=mean(x), sd=sd(x))
|
|
||||||
ggplot() +
|
|
||||||
# Dystrybuanta empiryczna
|
|
||||||
geom_step(
|
|
||||||
aes(x = z, y = dystrybuanta_empiryczna(z), color = "Empiryczna"),
|
|
||||||
linewidth = 1,
|
|
||||||
linetype = "solid"
|
|
||||||
) +
|
|
||||||
# Dystrybuanta teoretyczna
|
|
||||||
geom_line(
|
|
||||||
aes(x = z, y = dystrybuanta_teoretyczna, color = "Teoretyczna"),
|
|
||||||
linewidth = 1,
|
|
||||||
linetype = "dashed"
|
|
||||||
) +
|
|
||||||
# Dodanie legendy i dostosowanie kolorów
|
|
||||||
scale_color_manual(
|
|
||||||
values = c("Empiryczna" = "blue", "Teoretyczna" = "red"),
|
|
||||||
labels = c("Empiryczna", "Teoretyczna")
|
|
||||||
) +
|
|
||||||
# Etykiety i tytuł
|
|
||||||
labs(
|
|
||||||
title = "Porównanie dystrybuanty empirycznej i teoretycznej",
|
|
||||||
x = "Wartość",
|
|
||||||
y = "Prawdopodobieństwo skumulowane",
|
|
||||||
color = "Typ dystrybuanty" # Tytuł legendy
|
|
||||||
) +
|
|
||||||
theme_minimal() +
|
|
||||||
theme(plot.title = element_text(hjust = 0.5))
|
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user