library(knitr)
texas <- read.csv("C:/Users/ce168diedifi/Desktop/Profession.AI/Corso Statistica Descrittiva/Progetto/realestate_texas.csv", sep=",", header=TRUE, encoding="UTF-8")
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory |
|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 |
city
VARIABILE QUALITATIVA SU SCALA NOMINALE
year QUANTITATIVA CONTINUA DA TRATTARE COME QUALITATIVA ORDINALE IN QUESTO CASO
month QUALITATIVA NOMINALE (CICLICA) MA CODIFICATA IN NUMERI
sales QUANTITATIVA DISCRETA
median_price QUANTITATIVA CONTINUA
listings
QUANTITATIVA DISCRETA
volume QUANTITATIVA CONTINUA
month_inventory
QUANTITATIVA CONTINUA
Le quantitative continue sono tutte su scala di rapporti
year
Le variabili temporali sono molto utili per rappresentare i dati con un
grafico di tipo serie storica basata sul numero totale di venite (sales)
o il volume
Con questa variabile si potrebbe calcolare la distribuzione di frequenza per capire l’andamento annuale del numero totale di vendite (sales) e il valore totale delle vendite (volume).
month
Anche qui un grafico di tipo serie storica è utile.
Penso che un altro tipo di analisi utile potrebbe essere una distribuzione di frequenza con suddivisione in classi ( a gruppi di 3 mesi ) per capire quali il trend delle vendite nei mesi/trimestri dell’anno.
# FUNZIONI
geometric.mean <- function(dataset) {
return(exp(mean(log(dataset))))
}
armonic.mean <- function(dataset){
return(1/(sum(1/dataset)/length(dataset)))
}
coefficient.of.variation <- function(dataset){
return( round(sd(dataset)/mean(dataset)*100,2) )
}
gini.index <- function(dataset){
#
ni = table(texas$sales)
fi = ni/length(texas$sales)
fi2 = fi^2
J = length(ni)
#
gini = 1-sum(fi2)
gini.norm = gini/((J-1)/J)
return(round(gini.norm,2))
}
asimmetria.di.fisher <- function(dataset){
mu <- mean(dataset)
sigma <- sd(dataset)
n <- length(dataset)
m3 <- sum((dataset-mu)^3)/n
return( round(m3/(sigma^3),2) )
}
curtosi <- function(dataset){
mu <- mean(dataset)
sigma <- sd(dataset)
n <- length(dataset)
m4 <- sum((dataset-mu)^4)/n
res <- ( m4/(sigma^4) ) -3
return(round(res))
}
for (col_name in names(texas)) {
if ( col_name == "sales" | col_name == "volume" ) {
current_dataset <- texas[[col_name]]
INDICI.DI.POSIZIONE <- data.frame(
"Media Aritmetica" = round(mean(current_dataset),2)
, "Mediana" = round(median(sort(current_dataset),2))
, "Minimo" = quantile(current_dataset)[1]
, "Massimo" = quantile(current_dataset)[5]
, "Percentile (25%)" = quantile(current_dataset)[2]
, "Percentile (50%)" = quantile(current_dataset)[3]
, "Percentile (75%)" = quantile(current_dataset)[4]
, check.names = FALSE
)
INDICI.DI.VARIABILITA <- data.frame(
"Intervallo di variazione" = max(current_dataset)-min(current_dataset)
, "Differenza Interquartile" = IQR(current_dataset)
, "Varianza" = round(var(current_dataset),2)
, "Deviaizone Standard" = round(sd(current_dataset),2)
, "Coefficiente di variazione" = coefficient.of.variation(current_dataset)
, "Gini" = gini.index(current_dataset)
, check.names = FALSE
)
INDICI.DI.FORMA <- data.frame(
"Asimmetria di Fisher" = asimmetria.di.fisher(texas$sales)
, "Curtosi" = curtosi(texas$sales)
, check.names = FALSE
)
print(kable(INDICI.DI.POSIZIONE))
print(kable(INDICI.DI.VARIABILITA))
print(kable(INDICI.DI.FORMA))
}
}
| Media Aritmetica | Mediana | Minimo | Massimo | Percentile (25%) | Percentile (50%) | Percentile (75%) | |
|---|---|---|---|---|---|---|---|
| 0% | 192.29 | 176 | 79 | 423 | 127 | 175.5 | 247 |
| Intervallo di variazione | Differenza Interquartile | Varianza | Deviaizone Standard | Coefficiente di variazione | Gini |
|---|---|---|---|---|---|
| 344 | 120 | 6344.3 | 79.65 | 41.42 | 1 |
| Asimmetria di Fisher | Curtosi |
|---|---|
| 0.71 | 0 |
| Media Aritmetica | Mediana | Minimo | Massimo | Percentile (25%) | Percentile (50%) | Percentile (75%) | |
|---|---|---|---|---|---|---|---|
| 0% | 31.01 | 27 | 8.166 | 83.547 | 17.6595 | 27.0625 | 40.893 |
| Intervallo di variazione | Differenza Interquartile | Varianza | Deviaizone Standard | Coefficiente di variazione | Gini |
|---|---|---|---|---|---|
| 75.381 | 23.2335 | 277.27 | 16.65 | 53.71 | 1 |
| Asimmetria di Fisher | Curtosi |
|---|---|
| 0.71 | 0 |
# ---
df_year <- cut(sort(texas$year),seq(min(texas$year),max(texas$year),1))
len <- length(df_year)
distr_freq_year <- as.data.frame(
cbind(
ni=table(df_year),
fi=table(df_year)/len,
Ni=cumsum(table(df_year)),
Fi=cumsum(table(df_year))/len
)
)
kable(distr_freq_year)
| ni | fi | Ni | Fi | |
|---|---|---|---|---|
| (2010,2011] | 48 | 0.2 | 48 | 0.2 |
| (2011,2012] | 48 | 0.2 | 96 | 0.4 |
| (2012,2013] | 48 | 0.2 | 144 | 0.6 |
| (2013,2014] | 48 | 0.2 | 192 | 0.8 |
df_month <- cut(sort(texas$month),seq(1,12,1))
len <- length(df_month)
distr_freq_month <- as.data.frame(
cbind(
ni=table(df_month),
fi= round( table(df_month)/len, 2 ),
Ni=cumsum(table(df_month)),
Fi= round( cumsum(table(df_month))/len, 2 )
)
)
kable(distr_freq_month)
| ni | fi | Ni | Fi | |
|---|---|---|---|---|
| (1,2] | 20 | 0.08 | 20 | 0.08 |
| (2,3] | 20 | 0.08 | 40 | 0.17 |
| (3,4] | 20 | 0.08 | 60 | 0.25 |
| (4,5] | 20 | 0.08 | 80 | 0.33 |
| (5,6] | 20 | 0.08 | 100 | 0.42 |
| (6,7] | 20 | 0.08 | 120 | 0.50 |
| (7,8] | 20 | 0.08 | 140 | 0.58 |
| (8,9] | 20 | 0.08 | 160 | 0.67 |
| (9,10] | 20 | 0.08 | 180 | 0.75 |
| (10,11] | 20 | 0.08 | 200 | 0.83 |
| (11,12] | 20 | 0.08 | 220 | 0.92 |
gli indici di posizione dicono che:
la differenza tra media aritmetica e mediana suggerisce che la distribuzione dei dati potrebbe essere asimmetrica. La media ponderata molto più bassa rispetto alla media aritmetica potrebbe indicare che alcuni valori con pesi più bassi sono alti, e quelli con pesi più elevati sono piccoli. La presenza di un massimo elevato rispetto al minimo evidenzia una distribuzione con una significativa dispersione.
gli indici di variabilità dicono che:
L’intervallo di variazione e la differenza interquartile indicano che i tuoi dati sono piuttosto dispersi. La varianza e la deviazione standard confermano la presenza di una dispersione relativamente alta. Il coefficiente di variazione suggerisce che la variabilità rispetto alla media è significativa. L’indice di Gini evidenzia una fortissima concentrazione, indicando che pochi valori nel dataset sono responsabili di gran parte del volume totale, suggerendo una distribuzione altamente sbilanciata.
gli indici di forma:
Fisher misura la simmetria della distribuzione rispetto alla media. Qui abbiamo una asimmetria positiva, indica che i dati tendono a essere più concentrati verso i valori inferiori.
variabilità <- data.frame(
"sales" = coefficient.of.variation(texas$sales)
, "volume" = coefficient.of.variation(texas$volume)
, "median_price" = coefficient.of.variation(texas$median_price)
, "listings" = coefficient.of.variation(texas$listings)
, "months_inventory" = coefficient.of.variation(texas$months_inventory)
, check.names = FALSE
)
kable(variabilità)
| sales | volume | median_price | listings | months_inventory |
|---|---|---|---|---|
| 41.42 | 53.71 | 17.08 | 43.31 | 25.06 |
fisher <- data.frame(
"sales" = asimmetria.di.fisher(texas$sales)
, "volume" = asimmetria.di.fisher(texas$volume)
, "median_price" = asimmetria.di.fisher(texas$median_price)
, "listings" = asimmetria.di.fisher(texas$listings)
, "months_inventory" = asimmetria.di.fisher(texas$months_inventory)
, check.names = FALSE
)
kable(fisher)
| sales | volume | median_price | listings | months_inventory |
|---|---|---|---|---|
| 0.71 | 0.88 | -0.36 | 0.65 | 0.04 |
PER LA VARIABILE CON LA PIÙ ALTA VARIABILITÀ: si usa il coefficiente di variazione che serve proprio a verificare la variabilità di una variabile. E’ espressa in % che è utile per confrontare unità di misura diverse.
PER LA VARIABILE CON LA DISTRIBUZIONE PIÙ ASIMMETRICA: si usa l’indice di asimmetria di fisher perché fornisce una misura standardizzata e comparabile della distribuzione dei dati
CONSIDERAZIONI STATISTICHE
sales volume median_price listings months_inventory 0.7136206 0.8792182 -0.3622768 0.6454431 0.04071944
l’indice di fisher sul numero totale di vendite è > 0 quindi buono le vendite stanno andando bene. guardando però l’indice di fisher per il prezzo medio di vendita questo è < 0 significa che mediamente i prezzi degli immobili sono troppo bassi
serie <- cut(texas$volume,seq(1,100,10))
len <- length(serie)
distr_freq <- as.data.frame(
cbind(
ni=table(serie),
fi= round( table(serie)/len, 2 ),
Ni=cumsum(table(serie)),
Fi= round( cumsum(table(serie))/len, 2 )
)
)
kable(distr_freq)
| ni | fi | Ni | Fi | |
|---|---|---|---|---|
| (1,11] | 12 | 0.05 | 12 | 0.05 |
| (11,21] | 71 | 0.30 | 83 | 0.35 |
| (21,31] | 56 | 0.23 | 139 | 0.58 |
| (31,41] | 43 | 0.18 | 182 | 0.76 |
| (41,51] | 24 | 0.10 | 206 | 0.86 |
| (51,61] | 17 | 0.07 | 223 | 0.93 |
| (61,71] | 12 | 0.05 | 235 | 0.98 |
| (71,81] | 4 | 0.02 | 239 | 1.00 |
| (81,91] | 1 | 0.00 | 240 | 1.00 |
library(ggplot2)
distr_freq$serie <- levels(serie)
# plot
ggplot(distr_freq, aes(x = serie, y = ni)) +
geom_bar(stat = "identity", fill = "skyblue") +
labs(
title = "Distribuzione di Frequenza",
x = "Intervalli di Volume",
y = "Frequenza Assoluta"
) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Questo grafico a barre conferma la asimmetria positiva. La distribuzione è asimmetrica positiva e leggermente leptocurtica.
gini <- gini.index(serie)
gini
## [1] 1
Un indice di Gini pari a 0.998379 indica una quasi totale disuguaglianza nella distribuzione. Questo valore è molto vicino a 1, significa che il numero totale di vendite immobiliari in Texas tendono di più vs uno o + range.
Infatti osservando il grafico a barre vediamo che le vendite maggiori avvengono con immobili del valore tra i 10 e i 40 milioni di dollari.
anche nei punti precedenti è emerso che nei dati c’è un asimmetria e la variabile con la pià alta variabilità e asimmetria è proprio il volume.
probabilità <- function(dataset, val) {
nr.casi.favorevoli <- length(dataset[dataset == val])
nr.casi.possibili <- length(dataset)
return( round( nr.casi.favorevoli / nr.casi.possibili, 2 ) )
}
probabilità(texas$city,"Beaumont")
## [1] 0.25
La probabilità è pati allo 0.25 quindi 1/4 del dataset. Infatti leggendo il dataset su excel e producendo una pivot il risultato è corretto, ogni valore distinto di city compare 60 volte
probabilità(texas$month,7)
## [1] 0.08
La probabilità è pati allo 0.83 quindi 1/12 del dataset. Infatti leggendo il dataset su excel e producendo una pivot il risultato è corretto, ogni valore distinto di month compare 20 volte
nr.casi.favorevoli <- length(texas$year[texas$year == 2012 & texas$month == 12])
nr.casi.possibili <- length(texas$year)
probabilita.doppia <- nr.casi.favorevoli / nr.casi.possibili
round( probabilita.doppia, 2 )
## [1] 0.02
La probabilità è pati allo 0.01666667 Infatti leggendo il dataset su excel e producendo una pivot il risultato è corretto. La combinazione 2012 e 12 compare 4 volte su 240 valori totali.
texas$average_price <- round((texas$volume/texas$sales)*1000,3)
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price |
|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 |
# % di efficacia delle vendite sul numero totale di annunci attivi
texas$effectiveness <- round( ( texas$sales / texas$listings ) * 100, 2 )
min(texas$effectiveness) # 5%
## [1] 5.01
max(texas$effectiveness) # 38%
## [1] 38.71
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
# DISTRIBUZIONE DI FREQUENZA
serie <- cut(texas$effectiveness,seq(1,100,10))
len <- length(serie)
distr_freq <- as.data.frame(
cbind(
ni=table(serie),
fi= round( table(serie)/len, 2 ),
Ni=cumsum(table(serie)),
Fi= round( cumsum(table(serie))/len, 2 )
)
)
kable(distr_freq)
| ni | fi | Ni | Fi | |
|---|---|---|---|---|
| (1,11] | 120 | 0.50 | 120 | 0.50 |
| (11,21] | 108 | 0.45 | 228 | 0.95 |
| (21,31] | 10 | 0.04 | 238 | 0.99 |
| (31,41] | 2 | 0.01 | 240 | 1.00 |
| (41,51] | 0 | 0.00 | 240 | 1.00 |
| (51,61] | 0 | 0.00 | 240 | 1.00 |
| (61,71] | 0 | 0.00 | 240 | 1.00 |
| (71,81] | 0 | 0.00 | 240 | 1.00 |
| (81,91] | 0 | 0.00 | 240 | 1.00 |
Osservando una distribuzione di frequenza sulla colonna “effectiveness” si nota come l’efficacia delle vendite supera a fatica il 20%. L’efficiacia sulle vendite è sicuramente un punto da migliorare.
#install.packages("dplyr")
library(dplyr)
##
## Caricamento pacchetto: 'dplyr'
## I seguenti oggetti sono mascherati da 'package:stats':
##
## filter, lag
## I seguenti oggetti sono mascherati da 'package:base':
##
## intersect, setdiff, setequal, union
texas %>%
group_by(city) %>%
summarise(mean_volume = mean(volume, na.rm = TRUE)) %>%
arrange(desc(mean_volume))
## # A tibble: 4 × 2
## city mean_volume
## <chr> <dbl>
## 1 Tyler 45.8
## 2 Bryan-College Station 38.2
## 3 Beaumont 26.1
## 4 Wichita Falls 13.9
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
texas %>%
group_by(city, year) %>%
summarise(mean_volume = mean(volume, na.rm = TRUE)) %>%
arrange(city, desc(year))
## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.
## # A tibble: 20 × 3
## # Groups: city [4]
## city year mean_volume
## <chr> <int> <dbl>
## 1 Beaumont 2014 32.1
## 2 Beaumont 2013 30.3
## 3 Beaumont 2012 24.5
## 4 Beaumont 2011 21.1
## 5 Beaumont 2010 22.7
## 6 Bryan-College Station 2014 52.8
## 7 Bryan-College Station 2013 45.1
## 8 Bryan-College Station 2012 35.4
## 9 Bryan-College Station 2011 28.9
## 10 Bryan-College Station 2010 28.7
## 11 Tyler 2014 59.6
## 12 Tyler 2013 50.3
## 13 Tyler 2012 44.0
## 14 Tyler 2011 38.6
## 15 Tyler 2010 36.3
## 16 Wichita Falls 2014 14.5
## 17 Wichita Falls 2013 14.9
## 18 Wichita Falls 2012 13.2
## 19 Wichita Falls 2011 12.1
## 20 Wichita Falls 2010 15.0
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
texas %>%
group_by(city, year, month) %>%
summarise(mean_volume = mean(volume, na.rm = TRUE)) %>%
arrange(city, desc(year), desc(month))
## `summarise()` has grouped output by 'city', 'year'. You can override using the
## `.groups` argument.
## # A tibble: 240 × 4
## # Groups: city, year [20]
## city year month mean_volume
## <chr> <int> <int> <dbl>
## 1 Beaumont 2014 12 31.7
## 2 Beaumont 2014 11 24.9
## 3 Beaumont 2014 10 40.9
## 4 Beaumont 2014 9 35.3
## 5 Beaumont 2014 8 41.2
## 6 Beaumont 2014 7 34.9
## 7 Beaumont 2014 6 38.2
## 8 Beaumont 2014 5 36.7
## 9 Beaumont 2014 4 30.2
## 10 Beaumont 2014 3 26.3
## # ℹ 230 more rows
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
texas %>%
group_by(city) %>%
summarise(
mean_volume = mean(volume, na.rm = TRUE), sd_volume = sd(volume, na.rm = TRUE)
) %>%
arrange(desc(mean_volume))
## # A tibble: 4 × 3
## city mean_volume sd_volume
## <chr> <dbl> <dbl>
## 1 Tyler 45.8 13.1
## 2 Bryan-College Station 38.2 17.2
## 3 Beaumont 26.1 6.97
## 4 Wichita Falls 13.9 3.24
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
texas %>%
group_by(city, year) %>%
summarise(mean_volume = mean(volume, na.rm = TRUE), sd_volume = sd(volume, na.rm = TRUE), .groups = "drop") %>%
arrange(city, desc(year), desc(mean_volume))
## # A tibble: 20 × 4
## city year mean_volume sd_volume
## <chr> <int> <dbl> <dbl>
## 1 Beaumont 2014 32.1 7.05
## 2 Beaumont 2013 30.3 6.44
## 3 Beaumont 2012 24.5 4.92
## 4 Beaumont 2011 21.1 4.30
## 5 Beaumont 2010 22.7 4.95
## 6 Bryan-College Station 2014 52.8 18.0
## 7 Bryan-College Station 2013 45.1 19.5
## 8 Bryan-College Station 2012 35.4 13.5
## 9 Bryan-College Station 2011 28.9 10.3
## 10 Bryan-College Station 2010 28.7 10.8
## 11 Tyler 2014 59.6 12.8
## 12 Tyler 2013 50.3 10.3
## 13 Tyler 2012 44.0 10.2
## 14 Tyler 2011 38.6 9.41
## 15 Tyler 2010 36.3 8.39
## 16 Wichita Falls 2014 14.5 3.13
## 17 Wichita Falls 2013 14.9 3.11
## 18 Wichita Falls 2012 13.2 2.66
## 19 Wichita Falls 2011 12.1 2.52
## 20 Wichita Falls 2010 15.0 4.07
kable(head(texas))
| city | year | month | sales | volume | median_price | listings | months_inventory | average_price | effectiveness |
|---|---|---|---|---|---|---|---|---|---|
| Beaumont | 2010 | 1 | 83 | 14.162 | 163800 | 1533 | 9.5 | 170.627 | 5.41 |
| Beaumont | 2010 | 2 | 108 | 17.690 | 138200 | 1586 | 10.0 | 163.796 | 6.81 |
| Beaumont | 2010 | 3 | 182 | 28.701 | 122400 | 1689 | 10.6 | 157.698 | 10.78 |
| Beaumont | 2010 | 4 | 200 | 26.819 | 123200 | 1708 | 10.6 | 134.095 | 11.71 |
| Beaumont | 2010 | 5 | 202 | 28.833 | 123100 | 1771 | 10.9 | 142.738 | 11.41 |
| Beaumont | 2010 | 6 | 189 | 27.219 | 122800 | 1803 | 11.1 | 144.016 | 10.48 |
#install.packages("tidyr")
library(ggplot2)
library(dplyr)
summary_city <- texas %>%
group_by(city) %>%
summarise(
mean_volume = mean(volume, na.rm = TRUE),
sd_volume = sd(volume, na.rm = TRUE)
)
ggplot(summary_city, aes(x = city, y = mean_volume)) +
geom_point(size = 3, color = "skyblue") +
geom_errorbar(aes(ymin = mean_volume - sd_volume, ymax = mean_volume + sd_volume),
width = 0.2, color = "orange") +
labs(title = "Media del Volume con Barre di Errore (Deviazione Standard) per Città",
x = "Città",
y = "Media del Volume") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
questo grafico con barre di errore ci dice le due città Beaumont e Wichita Fails hanno dei dati sono poco variabili attorno alla media. Questo suggerisce che in media il volume delle vendite per queste due città è molto regolare. Le altre due città invece, con le barre di errore più alte indicano che il volume delle vendite è irregolare.
library(ggplot2)
ggplot(texas, aes(x = city, y = median_price)) +
geom_boxplot(fill = "lightblue", color = "black") +
labs(title = "Distribuzione del Prezzo Mediano per Città", x = "Città", y = "Prezzo Mediano") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
La dimensione delle scatole (IQR) conferma nuovamente l’asimmetria positiva dei dati evidente per tutte le città ma per la seconda meno. Significa che il prezzo medio di vendita per tutte le città è troppo basso.
Per la seconda città il baffo alto è chiaramente più lungo, che significa che ci sono dei prezzi medi molto alti con alcuni outliners. Significa che qui i prezzi medi andrebbero equlibtati perchè troppo alti.
La prima e terza città hanno dei baffi quasi equivalenti, la prima con outliners e la’latra senza, ma essendoci una asimmetria positiva anche qui i prezzi medi andrebbero equlibrati perchè troppo bassi.
la quarta città a mio parere è la più strana c’è una asimmetria positiva, baffo basso più lungo e degli outliners molto lontani dal baffo superiore. Qui i dati sembrano molto dispesi e anche qui andrebbero equilibrati perchè troppo bassi con qualche picco di valore medio troppo alto.
library(ggplot2)
library(dplyr)
summary_sales <- texas %>%
group_by(city, month) %>%
summarise(total_sales = sum(sales, na.rm = TRUE))
## `summarise()` has grouped output by 'city'. You can override using the
## `.groups` argument.
ggplot(summary_sales, aes(x = factor(month), y = total_sales, fill = city)) +
geom_bar(stat = "identity", position = "dodge") + labs(title = "Totale delle Vendite per Mese e Città", x = "Mese", y = "Totale Vendite") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 0, hjust = 1))
Questo grafico fa intendere che la città col più alto margine di crescita è “Wichita Fails” e quella con le vendite più alte è “Tyler”
library(ggplot2)
library(dplyr)
texas <- texas %>%
mutate(date = as.Date(paste(year, month, "01", sep = "-")))
ggplot(texas, aes(x = date, y = volume, color = city, group = city)) +
geom_line(size = 1.2) +
geom_point(size = 2) +
labs(title = "Andamento delle Vendite per Città", x = "Data", y = "Volume delle Vendite") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 0, hjust = 1))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Anche su una serie temporale l’andamento delle vendite è confermato rispetto al grafico a barre. tutte le città a differenza di “Wichita Fails” hanno avuto un incremento delle vendite nel tempo con però una variabilità molto irregolare.
la tendenza emersa da questa analisi è che il numero delle vendite e il valore delle vendite tende a sbilanciarsi vs una paricolare tipologia di immobili.
La città di Wichila Falls è quella col numero di vendite nel corso degli anni più o meno stabile, mentre tutte le altre hanno avuto un buon incremento dal 2010 al 2014.
La raccomandazioni sono: 1. verificare meglio i prezzi degli immobili 2. migliorare la % di efficacia delle vendite 3. La città col margine più alto di crescita è “Wichita Falls”