Progetto “Analisi esplorativa del mercato Immobiliare del Texsas” per conto della TEXAS REALTY INSIGHTS

1. ANALISI DELLE VARIABILI

summary(dati$city)
##    Length     Class      Mode 
##       240 character character
# variabile qualitativa nominale - 4 valori caratteriali
attach(dati) 
summary(year) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2010    2011    2012    2012    2013    2014
# variabile quantitativa discreta ordinale - le vendite sono state fatte in un range dal 2010 al 2014 
summary(month) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    3.75    6.50    6.50    9.25   12.00
# variabile quantitativa discreta ordinale - non significativa con i dati di SUMMARY 
summary(sales) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    79.0   127.0   175.5   192.3   247.0   423.0
# variabile quantitativa discreta - le vendite hanno una media più alta della mediana, segno che ci saranno più mesi con vendite alte rispetto alla mediana 
summary(volume) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   8.166  17.660  27.062  31.005  40.893  83.547
# variabile quantitativa continua - da 8M a 83M con range IQR tra 17M e 40M 
summary(median_price) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   73800  117300  134500  132665  150050  180000
# variabile quantitativa continua - da 73K a 180K con IQR da 117K a 150K, qui la mediana sorpassa la media 
summary(listings) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##     743    1026    1618    1738    2056    3296
# variabile quantitativa discreta - gli annunci attivi presentano un ampio range, quasi 5 volte il minimo 
summary(months_inventory)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   3.400   7.800   8.950   9.193  10.950  14.900
# variabile quantitativa continua - il tempo massimo di vendita degli immobili è di 14,9 mesi
n <- dim(dati)[1]

GESTIONE DEL TEMPO

dati$year_factor <- as.factor(dati$year)
dati$month_factor <- as.factor(dati$month)

2 CALCOLO DEGLI INDICI (POSIZIONE, VARIABILITA’ E FORMA)

## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
## ℹ Please use `reframe()` instead.
## ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## ℹ The deprecated feature was likely used in the dplyr package.
##   Please report the issue at <https://github.com/tidyverse/dplyr/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## [1] "Indici di Posizione, Variabilità e Forma:"
##                     Media Mediana Deviazione_Standard  Varianza Minimo Massimo
## year                 2012    2012            1.417169  2.008368   2010    2014
## month                 6.5     6.5            3.459267  11.96653      1      12
## sales            192.2917   175.5            79.65111    6344.3     79     423
## volume           31.00519 27.0625            16.65145  277.2707  8.166  83.547
## median_price     132665.4  134500            22662.15 513572983  73800  180000
## listings         1738.021  1618.5            752.7078    566569    743    3296
## months_inventory   9.1925    8.95            2.303669  5.306889    3.4    14.9
##                   Range   Skewness   Kurtosis
## year                  4          0       -1.3
## month                11          0  -1.216783
## sales               344   0.718104 -0.3131764
## volume           75.381   0.884742   0.176987
## median_price     106200 -0.3645529 -0.6229618
## listings           2553  0.6494982   -0.79179
## months_inventory   11.5 0.04097527 -0.1744475
## [1] "\nDistribuzioni di Frequenza:"
##   city
## 1   60
## 2   60
## 3   60
## 4   60

3 VARIABILI CON MAGGIOR VARIABILITA’ E ASIMMETRIA

## [1] "Coefficienti di Variazione (CV):"
##                           CV
## volume           53.70535868
## month            53.21949013
## listings         43.30832759
## sales            41.42202965
## months_inventory 25.06030593
## median_price     17.08218257
## year              0.07043584
## 
## La variabile con la più alta variabilità (in termini di CV) è: volume
## [1] "\nValori Assoluti di Skewness:"
##                     Skewness abs_skewness
## volume            0.88474203   0.88474203
## sales             0.71810402   0.71810402
## listings          0.64949823   0.64949823
## median_price     -0.36455288   0.36455288
## months_inventory  0.04097527   0.04097527
## year              0.00000000   0.00000000
## month             0.00000000   0.00000000
## 
## La variabile con la distribuzione più asimmetrica (in base al valore assoluto della skewness) è: volume (Skewness = 0.884742)

4 CREAZIONI DI CLASSI PER UNA VARIBILE QUANTITATIVA

##           ni          fi  Ni        Fi
## (75,100]  21 0.087500000  21 0.0875000
## (100,125] 38 0.158333333  59 0.2458333
## (125,150] 34 0.141666667  93 0.3875000
## (150,175] 27 0.112500000 120 0.5000000
## (175,200] 29 0.120833333 149 0.6208333
## (200,225] 17 0.070833333 166 0.6916667
## (225,250] 15 0.062500000 181 0.7541667
## (250,275] 15 0.062500000 196 0.8166667
## (275,300] 19 0.079166667 215 0.8958333
## (300,325]  7 0.029166667 222 0.9250000
## (325,350]  6 0.025000000 228 0.9500000
## (350,375]  7 0.029166667 235 0.9791667
## (375,400]  2 0.008333333 237 0.9875000
## (400,425]  3 0.012500000 240 1.0000000

## L'indice di eterogeneità di Gini è: 0.898299
mp_cl <- c(cut(median_price/1000, seq(70,180,5)))

distr_freq_mp <- as.data.frame(  cbind(
  ni = table(mp_cl),
  fi = table(mp_cl)/n,
  Ni = cumsum(table(mp_cl)),
  Fi = cumsum(table(mp_cl)/n)))

# crea il grafico a barre
ggplot(data=dati)+
  geom_bar(aes(x=mp_cl),
           stat="count",
           col="lightblue",
           fill="blue")+
  labs(title="Distribuzione di Prezzo Medio in Classi (valore in migliaia di Dollari)",
       x="Classe Prezzo Medio * 1000",
       y="Frequenza")+
  theme_light()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

5 CALCOLO DELLE PROBABILILTA’

## La probabilità che una riga a caso riporti la città 'Beaumont' è: 0.250000
## La probabilità che una riga a caso riporti il mese di Luglio è: 0.083333
## La probabilità che una riga a caso riporti il mese di Dicembre 2012 è: 0.016667

6 CREAZIONE DI NUOVE VARIABILI

7 ANALISI CONDIZIONATA

## [1] "Summary di 'sales' per città:"
## # A tibble: 4 × 4
##   city                  media_sales sd_sales n_obs
##   <chr>                       <dbl>    <dbl> <int>
## 1 Beaumont                     177.     41.5    60
## 2 Bryan-College Station        206.     85.0    60
## 3 Tyler                        270.     62.0    60
## 4 Wichita Falls                116.     22.2    60

## [1] "Summary di 'sales' per anno:"
## # A tibble: 5 × 4
##    year media_sales sd_sales n_obs
##   <int>       <dbl>    <dbl> <int>
## 1  2010        169.     60.5    48
## 2  2011        164.     63.9    48
## 3  2012        186.     70.9    48
## 4  2013        212.     84.0    48
## 5  2014        231.     95.5    48

## [1] "Summary di 'sales' per mese:"
## # A tibble: 12 × 4
##    month media_sales sd_sales n_obs
##    <int>       <dbl>    <dbl> <int>
##  1     1        127.     43.4    20
##  2     2        141.     51.1    20
##  3     3        189.     59.2    20
##  4     4        212.     65.4    20
##  5     5        239.     83.1    20
##  6     6        244.     95.0    20
##  7     7        236.     96.3    20
##  8     8        231.     79.2    20
##  9     9        182.     72.5    20
## 10    10        180.     75.0    20
## 11    11        157.     55.5    20
## 12    12        169.     60.7    20

8 CREAZIONE DI VISUALIZZAZIONE CON GGPLOT2 (e grafici personalizzati)

## `summarise()` has grouped output by 'city', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.
## Warning: The dot-dot notation (`..y..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(y)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.

## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.

## `summarise()` has grouped output by 'city', 'month'. You can override using the
## `.groups` argument.

## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.

## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.
## Warning: Removed 8 rows containing missing values or values outside the scale range
## (`geom_line()`).
## Warning: Removed 8 rows containing missing values or values outside the scale range
## (`geom_point()`).

9 CONCLUSIONI