DS Lab #1

Karol Flisikowski

2021-04-07

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 Rel_Freq Cum_Freq
## 1    (3.5e+05,4.5e+05]    9    0.045        9
## 2    (4.5e+05,5.5e+05]   21    0.105       30
## 3    (5.5e+05,6.5e+05]   33    0.165       63
## 4    (6.5e+05,7.5e+05]   36    0.180       99
## 5    (7.5e+05,8.5e+05]   31    0.155      130
## 6    (8.5e+05,9.5e+05]   36    0.180      166
## 7   (9.5e+05,1.05e+06]   21    0.105      187
## 8  (1.05e+06,1.15e+06]   10    0.050      197
## 9  (1.15e+06,1.25e+06]    2    0.010      199
## 10 (1.25e+06,1.35e+06]    1    0.005      200

TAI

##        # 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.

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`.

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.

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
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.

Room vs Price
1 (N = 44) 2 (N = 50) 3 (N = 58) 4 (N = 48)
MIN 3.597690e+05 5.902860e+05 6.327700e+05 7.366690e+05
MAX 6.571460e+05 8.886340e+05 9.658290e+05 1.277691e+06
MEDIAN 5.205070e+05 6.772600e+05 8.463035e+05 9.643385e+05
MEAN 5.155180e+05 6.835677e+05 8.337060e+05 9.748100e+05
STANDARD DEVIATION 6.695103e+04 6.507266e+04 8.694390e+04 1.138192e+05
VAR 4.482441e+09 4.234451e+09 7.559242e+09 1.295481e+10
SX 3.767000e+04 4.148563e+04 6.569750e+04 7.080263e+04
SKEWNESS -2.102363e-01 8.291196e-01 -4.265731e-01 3.417219e-01
KURTOSIS 2.740594e+00 3.622123e+00 2.242285e+00 3.181540e+00