DS Lab #1

s184678 Marcin Kyć

2021-03-31

Data wrangling

As you can see not all formats of our variables are adjusted. We need to prepare the appropriate formats of our variables according to their measurement scales and future usage.

mieszkania$district<-as.factor(mieszkania$district)
mieszkania$building_type<-as.factor(mieszkania$building_type)
mieszkania$rooms<-factor(mieszkania$rooms,ordered=TRUE)
attach(mieszkania)
mieszkania$price_PLN<-as.numeric(mieszkania$price_PLN)
mieszkania$price_EUR<-as.numeric(mieszkania$price_EUR)

Frequency table

##    limits Freq
## 1 (17,27]   43
## 2 (27,37]   27
## 3 (37,47]   37
## 4 (47,57]   29
## 5 (57,67]   30
## 6 (67,77]   17
## 7 (77,87]   13

TAI

Apartments in Wroclaw - prices in kPLN
limits Freq
(17,27] 43
(27,37] 27
(37,47] 37
(47,57] 29
(57,67] 30
(67,77] 17
(77,87] 13
##        # classes  Goodness of fit Tabular accuracy 
##       10.0000000        0.9780872        0.8508467

Basic plots

In this section we should present our data using basic (pre-installed with R) graphics. Choose the most appropriate plots according to the scale of chosen variables. Investigate the heterogeneity of the distribution presenting data by groups (i.e. by district, building type etc.). Do not forget about main titles, labels and legend. Read more about graphical parameters here.

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

ggplot2 plots

## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

## Warning: `data_frame()` was deprecated in tibble 1.1.0.
## Please use `tibble()` instead.

Using facets

Faceting generates small multiples each showing a different subset of the data. Small multiples are a powerful tool for exploratory data analysis: you can rapidly compare patterns in different parts of the data and see whether they are the same or different. Read more about facets here.

Descriptive statistics #1

Before automatically reporting the full summary table of descriptive statistics, this time your goal is to measure the central tendency of the distribution of prices. Compare mean, median and mode together with positional measures - quantiles - by districts and building types or no. of rooms per apartment.

## [1] 760035
## [1] 755719.5
## [1] 186099.8
## [1] 34633125960
## [1] 282686.5
## [1] 359769
## [1] 1277691
##        0%        5%       25%       50%       75%       95%      100% 
##  359769.0  477175.4  619073.8  755719.5  901760.2 1054250.8 1277691.0

Summary tables with ‘kable’

Using kable and kableextra packages we can easily create summary tables with graphics and/or statistics.

rooms boxplot histogram line1 line2 points1 points2 poly
1
2
3
4

Ok, now we will finally summarize basic central tendency measures for prices by districts/building types using kable packages. You can customize your final report. See some hints here.

PLN prices per building types
Biskupin (N = 65) Krzyki (N = 79) Srodmiescie (N = 56)
PLN prices per building types
Min 519652.00 359769.00 448196.00
Max 1277691.00 1090444.00 1062054.00
Q1 676751.00 600180.50 592287.75
Median 817736.00 716726.00 727477.50
Q3 926474.00 876306.50 870752.50
Mean 818614.06 726507.20 739339.70
Sd 175597.94 195015.45 171428.11
IQR 249723.00 276126.00 278464.75
Sx 124861.50 138063.00 139232.38
Var % 0.21 0.27 0.23
IQR Var % 0.31 0.39 0.38
Skewness 0.34 0.07 0.11
Kurtosis -0.29 -0.98 -1.13
PLN prices per m^2
Mean PLN price per m^2 19537.32 17314.91 18724.71
Median PLN price per m^2 17739.17 15435.97 17320.75
EUR prices per m^2
Mean EUR price per m^2 4522.53 4008.08 4334.42
Median EUR price per m^2 4106.29 3573.14 4009.43
PLN prices per building types
kamienica (N = 61) niski blok (N = 63) wiezowiec (N = 76)
PLN prices per building types
Min 415834.00 496390.00 359769.00
Max 1230848.00 1277691.00 1090444.00
Q1 647756.00 692925.50 555798.25
Median 800693.00 807895.00 678704.00
Q3 896186.00 939852.50 870752.50
Mean 770332.52 815576.63 705728.87
Sd 184388.21 176390.35 182503.32
IQR 248430.00 246927.00 314954.25
Sx 124215.00 123463.50 157477.12
Var % 0.24 0.22 0.26
IQR Var % 0.31 0.31 0.46
Skewness 0.00 0.22 0.21
Kurtosis -0.61 -0.45 -0.97
PLN prices per m^2
Mean PLN price per m^2 17898.89 18250.88 19009.88
Median PLN price per m^2 16175.94 16546.07 17164.40
EUR prices per m^2
Mean EUR price per m^2 4143.26 4224.74 4400.44
Median EUR price per m^2 3744.44 3830.10 3973.24