Questo documento presenta un’analisi della relazione tra l’Indice Fintech (scala 0-100), l’Indice di Sviluppo Finanziario (scala 0-1) e la crescita del PIL (%) per 19 paesi. L’obiettivo è verificare se esiste una correlazione significativa tra questi indicatori di sviluppo del settore finanziario e fintech con la crescita economica.
library(tidymodels)
library(ggplot2)
library(readr)
library(knitr)
library(dplyr)
library(corrplot)
library(GGally)
library(car)# Carica dataset (separatore ; e decimale ,)
fintech_data <- read_delim("/Users/leonardomichi/Desktop/antonio/regressione 2 dati.csv",
delim = ";",
locale = locale(decimal_mark = ","))
# Pulisci i nomi delle colonne
names(fintech_data) <- c("Country", "Fintech_Index_0_100",
"Financial_Development_INDEX", "GDP_Growth")
# Rimuovi spazi extra dai nomi dei paesi
fintech_data$Country <- trimws(fintech_data$Country)
# Visualizza struttura dei dati
str(fintech_data)## spc_tbl_ [19 × 4] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Country : chr [1:19] "Stati Uniti" "Singapore" "Svezia" "Finlandia" ...
## $ Fintech_Index_0_100 : num [1:19] 71.1 64.5 68.6 53.7 78 ...
## $ Financial_Development_INDEX: num [1:19] 0.908 0.697 0.724 0.642 0.659 0.948 0.891 0.674 0.672 0.745 ...
## $ GDP_Growth : num [1:19] 2.8 4.39 0.97 -0.15 3.68 1.3 1.1 1.1 4.98 -0.24 ...
## - attr(*, "spec")=
## .. cols(
## .. Country = col_character(),
## .. Fintech_Index_0_100 = col_double(),
## .. `Financial Development INDEX ` = col_double(),
## .. GDP_Growth = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
# Statistiche descrittive
summary_stats <- fintech_data %>%
select(Fintech_Index_0_100, Financial_Development_INDEX, GDP_Growth) %>%
summary()
print(summary_stats)## Fintech_Index_0_100 Financial_Development_INDEX GDP_Growth
## Min. :18.67 Min. :0.2790 Min. :-1.170
## 1st Qu.:53.52 1st Qu.:0.6505 1st Qu.: 0.475
## Median :60.71 Median :0.6970 Median : 1.170
## Mean :57.00 Mean :0.7214 Mean : 1.474
## 3rd Qu.:69.02 3rd Qu.:0.8250 3rd Qu.: 2.320
## Max. :78.00 Max. :0.9480 Max. : 4.980
# Tabella dei primi 10 paesi
kable(head(fintech_data, 10),
caption = "Prime 10 osservazioni del dataset",
digits = 2)| Country | Fintech_Index_0_100 | Financial_Development_INDEX | GDP_Growth |
|---|---|---|---|
| Stati Uniti | 71.07 | 0.91 | 2.80 |
| Singapore | 64.49 | 0.70 | 4.39 |
| Svezia | 68.63 | 0.72 | 0.97 |
| Finlandia | 53.68 | 0.64 | -0.15 |
| Danimarca | 78.00 | 0.66 | 3.68 |
| Svizzera | 62.64 | 0.95 | 1.30 |
| Regno Unito | 71.12 | 0.89 | 1.10 |
| Paesi Bassi | 69.41 | 0.67 | 1.10 |
| Cina | 18.71 | 0.67 | 4.98 |
| Germania | 60.71 | 0.74 | -0.24 |
Il dataset contiene 19 osservazioni (paesi) con tre variabili quantitative:
# Calcolo matrice di correlazione
cor_matrix <- fintech_data %>%
select(Fintech_Index_0_100, Financial_Development_INDEX, GDP_Growth) %>%
cor()
kable(round(cor_matrix, 4),
caption = "Matrice di Correlazione di Pearson")| Fintech_Index_0_100 | Financial_Development_INDEX | GDP_Growth | |
|---|---|---|---|
| Fintech_Index_0_100 | 1.0000 | 0.1105 | -0.0269 |
| Financial_Development_INDEX | 0.1105 | 1.0000 | 0.1593 |
| GDP_Growth | -0.0269 | 0.1593 | 1.0000 |
# Visualizzazione matrice di correlazione
corrplot(cor_matrix, method = "number", type = "upper",
tl.col = "black", tl.srt = 45,
title = "Matrice di Correlazione",
mar = c(0,0,2,0))Visualizzazione della matrice di correlazione
# Correlazioni individuali
cor_fintech_gdp <- cor(fintech_data$Fintech_Index_0_100,
fintech_data$GDP_Growth)
cor_findev_gdp <- cor(fintech_data$Financial_Development_INDEX,
fintech_data$GDP_Growth)
cor_fintech_findev <- cor(fintech_data$Fintech_Index_0_100,
fintech_data$Financial_Development_INDEX)
cat("Correlazione Fintech Index - GDP Growth:", round(cor_fintech_gdp, 4), "\n")## Correlazione Fintech Index - GDP Growth: -0.0269
## Correlazione Financial Development - GDP Growth: 0.1593
## Correlazione tra le due variabili esplicative: 0.1105
# Scatter plot matrix
ggpairs(fintech_data,
columns = c("Fintech_Index_0_100", "Financial_Development_INDEX", "GDP_Growth"),
title = "Relazioni tra le Variabili",
upper = list(continuous = wrap("cor", size = 5)),
lower = list(continuous = wrap("points", alpha = 0.6, size = 2)))Matrice di scatter plot tra tutte le variabili
# Plot 1: GDP Growth vs Fintech Index
ggplot(fintech_data, aes(x = Fintech_Index_0_100, y = GDP_Growth)) +
geom_point(aes(color = Country), size = 3, alpha = 0.8) +
geom_smooth(method = "lm", se = TRUE, color = "blue", alpha = 0.3) +
geom_text(aes(label = Country), hjust = -0.1, vjust = -0.1,
size = 2.5, alpha = 0.7) +
labs(
title = "Crescita PIL vs Indice Fintech",
subtitle = paste("Correlazione =", round(cor_fintech_gdp, 3)),
x = "Indice Fintech (0-100)",
y = "Crescita PIL (%)"
) +
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(size = 14, face = "bold"),
plot.subtitle = element_text(size = 12))Relazione tra Indice Fintech e Crescita del PIL
# Plot 2: GDP Growth vs Financial Development
ggplot(fintech_data, aes(x = Financial_Development_INDEX, y = GDP_Growth)) +
geom_point(aes(color = Country), size = 3, alpha = 0.8) +
geom_smooth(method = "lm", se = TRUE, color = "darkgreen", alpha = 0.3) +
geom_text(aes(label = Country), hjust = -0.1, vjust = -0.1,
size = 2.5, alpha = 0.7) +
labs(
title = "Crescita PIL vs Sviluppo Finanziario",
subtitle = paste("Correlazione =", round(cor_findev_gdp, 3)),
x = "Indice di Sviluppo Finanziario",
y = "Crescita PIL (%)"
) +
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(size = 14, face = "bold"),
plot.subtitle = element_text(size = 12))Relazione tra Sviluppo Finanziario e Crescita del PIL
Costruiamo un modello di regressione lineare multipla con la seguente specificazione:
\[GDP\_Growth = \beta_0 + \beta_1 \times Fintech\_Index + \beta_2 \times Financial\_Development + \epsilon\]
# Definizione e stima del modello
modello <- linear_reg() %>%
set_engine("lm")
fit <- modello %>%
fit(GDP_Growth ~ Fintech_Index_0_100 + Financial_Development_INDEX,
data = fintech_data)
# Coefficienti del modello
coefficienti <- fit %>% tidy()
kable(coefficienti,
caption = "Coefficienti del modello di regressione multipla",
digits = 4)| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 0.4845 | 2.2523 | 0.2151 | 0.8324 |
| Fintech_Index_0_100 | -0.0045 | 0.0246 | -0.1815 | 0.8583 |
| Financial_Development_INDEX | 1.7253 | 2.6049 | 0.6623 | 0.5172 |
##
## Call:
## stats::lm(formula = GDP_Growth ~ Fintech_Index_0_100 + Financial_Development_INDEX,
## data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.4769 -0.7832 -0.4568 0.8684 3.4198
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.484518 2.252281 0.215 0.832
## Fintech_Index_0_100 -0.004471 0.024639 -0.181 0.858
## Financial_Development_INDEX 1.725310 2.604949 0.662 0.517
##
## Residual standard error: 1.7 on 16 degrees of freedom
## Multiple R-squared: 0.02739, Adjusted R-squared: -0.09419
## F-statistic: 0.2253 on 2 and 16 DF, p-value: 0.8008
intercept <- coefficienti$estimate[1]
coef_fintech <- coefficienti$estimate[2]
coef_findev <- coefficienti$estimate[3]
pval_fintech <- coefficienti$p.value[2]
pval_findev <- coefficienti$p.value[3]Intercetta (0.4845): Rappresenta la crescita del PIL prevista quando entrambe le variabili esplicative sono pari a zero. P-value = 0.8324.
Fintech_Index_0_100 (-0.0045): Per ogni punto in più nell’Indice Fintech, la crescita del PIL varia di -0.0045 punti percentuali, mantenendo costante lo sviluppo finanziario.
Financial_Development_INDEX (1.7253): Per ogni punto in più (su scala 0-1) nell’Indice di Sviluppo Finanziario, la crescita del PIL varia di 1.7253 punti percentuali, mantenendo costante l’indice fintech.
# Predizioni
full_pred <- fit %>%
predict(fintech_data) %>%
bind_cols(fintech_data)
# Calcolo delle metriche
full_metrics <- full_pred %>%
metrics(truth = GDP_Growth, estimate = .pred)
kable(full_metrics,
caption = "Metriche di performance del modello",
digits = 4)| .metric | .estimator | .estimate |
|---|---|---|
| rmse | standard | 1.5602 |
| rsq | standard | 0.0274 |
| mae | standard | 1.2234 |
# R-squared
rsq_value <- full_pred %>%
rsq(truth = GDP_Growth, estimate = .pred)
# R-squared aggiustato
n <- nrow(fintech_data)
k <- 2 # numero di predittori
r2_adj <- 1 - (1 - rsq_value$.estimate) * (n - 1) / (n - k - 1)
cat("R-squared:", round(rsq_value$.estimate, 4), "\n")## R-squared: 0.0274
## Varianza spiegata: 2.74 %
## R-squared aggiustato: -0.0942
L’analisi dei residui è fondamentale per verificare le assunzioni del modello lineare:
# Calcolo residui
model_resid <- fintech_data %>%
mutate(
Predetto = predict(fit, fintech_data)$.pred,
Residuo = GDP_Growth - Predetto
)
# Statistiche sui residui
residui_summary <- summary(model_resid$Residuo)
print(residui_summary)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -2.4769 -0.7832 -0.4568 0.0000 0.8684 3.4198
ggplot(model_resid, aes(x = Predetto, y = Residuo)) +
geom_point(color = "darkgreen", alpha = 0.6, size = 3) +
geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
geom_smooth(method = "loess", se = TRUE, alpha = 0.2, color = "blue") +
labs(title = "Grafico dei Residui",
subtitle = "Verifica dell'omoschedasticità",
x = "Valori Predetti",
y = "Residui") +
theme_minimal() +
theme(plot.title = element_text(face = "bold"))Residui vs Valori Predetti - Verifica dell’omoschedasticità
Interpretazione: Un pattern casuale attorno allo zero indica omoschedasticità (varianza costante dei residui). Pattern sistematici suggeriscono violazioni delle assunzioni.
# Estrazione dati diagnostici
dati_diag <- augment(fit$fit)
# Q-Q plot
ggplot(dati_diag, aes(sample = .std.resid)) +
stat_qq(alpha = 0.6, color = "darkgreen", size = 3) +
stat_qq_line(color = "red", linewidth = 1) +
labs(title = "Normal Q-Q Plot",
subtitle = "Verifica della normalità dei residui",
x = "Quantili Teorici",
y = "Residui Standardizzati") +
theme_minimal() +
theme(plot.title = element_text(face = "bold"))Q-Q Plot - Verifica della normalità dei residui
Interpretazione: I punti dovrebbero giacere lungo la linea rossa per confermare la normalità dei residui.
ggplot(model_resid, aes(x = Fintech_Index_0_100, y = Residuo)) +
geom_point(color = "purple", alpha = 0.6, size = 3) +
geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
geom_smooth(method = "loess", se = TRUE, alpha = 0.2) +
labs(title = "Residui vs Indice Fintech",
x = "Indice Fintech (0-100)",
y = "Residui") +
theme_minimal() +
theme(plot.title = element_text(face = "bold"))Residui vs Indice Fintech
ggplot(model_resid, aes(x = Financial_Development_INDEX, y = Residuo)) +
geom_point(color = "orange", alpha = 0.6, size = 3) +
geom_hline(yintercept = 0, color = "red", linetype = "dashed") +
geom_smooth(method = "loess", se = TRUE, alpha = 0.2) +
labs(title = "Residui vs Sviluppo Finanziario",
x = "Indice di Sviluppo Finanziario",
y = "Residui") +
theme_minimal() +
theme(plot.title = element_text(face = "bold"))Residui vs Sviluppo Finanziario
# Identifica i paesi con i residui più grandi (in valore assoluto)
outliers <- model_resid %>%
arrange(desc(abs(Residuo))) %>%
select(Country, Fintech_Index_0_100, Financial_Development_INDEX,
GDP_Growth, Predetto, Residuo) %>%
head(5)
kable(outliers,
caption = "Top 5 paesi con i residui più grandi",
digits = 2)| Country | Fintech_Index_0_100 | Financial_Development_INDEX | GDP_Growth | Predetto | Residuo |
|---|---|---|---|---|---|
| Cina | 18.71 | 0.67 | 4.98 | 1.56 | 3.42 |
| Singapore | 64.49 | 0.70 | 4.39 | 1.40 | 2.99 |
| Austria | 55.69 | 0.62 | -1.17 | 1.31 | -2.48 |
| Danimarca | 78.00 | 0.66 | 3.68 | 1.27 | 2.41 |
| Giappone | 40.57 | 0.92 | 0.08 | 1.90 | -1.82 |
# Soglia per identificare outlier (2 deviazioni standard)
soglia <- 2 * sd(model_resid$Residuo)
ggplot(model_resid, aes(x = reorder(Country, Residuo), y = Residuo)) +
geom_bar(stat = "identity",
aes(fill = abs(Residuo) > soglia),
alpha = 0.7) +
geom_hline(yintercept = c(-soglia, 0, soglia),
color = c("red", "black", "red"),
linetype = c("dashed", "solid", "dashed")) +
scale_fill_manual(values = c("FALSE" = "lightblue", "TRUE" = "red"),
labels = c("Normale", "Outlier"),
name = "Classificazione") +
coord_flip() +
labs(title = "Residui per Paese",
subtitle = paste("Soglia outlier: ±", round(soglia, 2)),
x = "Paese",
y = "Residuo") +
theme_minimal() +
theme(plot.title = element_text(face = "bold"))Residui per Paese - Identificazione degli outlier
Interpretazione: I paesi evidenziati in rosso sono considerati outlier (residui > 2 deviazioni standard). Questi paesi hanno una crescita del PIL significativamente diversa da quella prevista dal modello.
# Test di normalità dei residui
shapiro_test <- shapiro.test(model_resid$Residuo)
cat("Test di Shapiro-Wilk per normalità dei residui:\n")## Test di Shapiro-Wilk per normalità dei residui:
## W = 0.9264
## p-value = 0.1488
if(shapiro_test$p.value > 0.05) {
cat("Conclusione: I residui seguono una distribuzione normale (p > 0.05)\n")
} else {
cat("Conclusione: I residui non seguono una distribuzione normale (p < 0.05)\n")
}## Conclusione: I residui seguono una distribuzione normale (p > 0.05)
Il VIF misura la multicollinearità tra le variabili esplicative. Valori VIF > 5 indicano problemi di multicollinearità.
# VIF per multicollinearità
vif_values <- vif(fit$fit)
vif_df <- data.frame(
Variabile = names(vif_values),
VIF = vif_values
)
kable(vif_df,
caption = "Variance Inflation Factor (VIF)",
digits = 4,
row.names = FALSE)| Variabile | VIF |
|---|---|
| Fintech_Index_0_100 | 1.0124 |
| Financial_Development_INDEX | 1.0124 |
##
## Interpretazione:
##
## - VIF < 5: Nessun problema di multicollinearità
##
## - VIF 5-10: Multicollinearità moderata
##
## - VIF > 10: Multicollinearità severa
Confrontiamo tre modelli per valutare il contributo di ciascuna variabile:
# Modello 1: Solo Fintech Index
fit1 <- lm(GDP_Growth ~ Fintech_Index_0_100, data = fintech_data)
summary1 <- summary(fit1)
# Modello 2: Solo Financial Development
fit2 <- lm(GDP_Growth ~ Financial_Development_INDEX, data = fintech_data)
summary2 <- summary(fit2)
# Modello 3: già stimato (fit$fit)
summary3 <- summary(fit$fit)
# Tabella comparativa
comparison_table <- data.frame(
Modello = c("Modello 1 (Solo Fintech)",
"Modello 2 (Solo Fin. Dev.)",
"Modello 3 (Completo)"),
R_squared = c(summary1$r.squared, summary2$r.squared, summary3$r.squared),
R_squared_adj = c(summary1$adj.r.squared, summary2$adj.r.squared, summary3$adj.r.squared),
RMSE = c(sqrt(mean(summary1$residuals^2)),
sqrt(mean(summary2$residuals^2)),
sqrt(mean(summary3$residuals^2))),
AIC = c(AIC(fit1), AIC(fit2), AIC(fit$fit)),
BIC = c(BIC(fit1), BIC(fit2), BIC(fit$fit))
)
kable(comparison_table,
caption = "Confronto tra modelli alternativi",
digits = 4)| Modello | R_squared | R_squared_adj | RMSE | AIC | BIC |
|---|---|---|---|---|---|
| Modello 1 (Solo Fintech) | 0.0007 | -0.0581 | 1.5814 | 77.3366 | 80.1699 |
| Modello 2 (Solo Fin. Dev.) | 0.0254 | -0.0319 | 1.5618 | 76.8618 | 79.6951 |
| Modello 3 (Completo) | 0.0274 | -0.0942 | 1.5602 | 78.8227 | 82.6005 |
# Test F per confronto Modello 1 vs Modello 3
anova_test <- anova(fit1, fit$fit)
kable(anova_test,
caption = "Test ANOVA: Modello 1 vs Modello 3",
digits = 4)| Res.Df | RSS | Df | Sum of Sq | F | Pr(>F) |
|---|---|---|---|---|---|
| 17 | 47.5185 | NA | NA | NA | NA |
| 16 | 46.2505 | 1 | 1.268 | 0.4387 | 0.5172 |
Interpretazione: Il test ANOVA confronta il modello semplice (solo Fintech) con il modello completo. Un p-value < 0.05 indicherebbe che l’aggiunta della variabile Financial Development migliora significativamente il modello.
I risultati suggeriscono che:
Lo sviluppo del settore fintech e lo sviluppo finanziario, presi insieme, non sono predittori affidabili della crescita economica nel breve periodo per questo campione di paesi.
Il basso R² indica che altri fattori hanno un impatto molto più significativo sulla crescita del PIL:
La relazione tra fintech e crescita potrebbe essere:
I paesi outlier (Cina, Singapore, Austria) suggeriscono che fattori specifici del contesto nazionale giocano un ruolo determinante.
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-apple-darwin20
## Running under: macOS 15.7.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Rome
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] car_3.1-3 carData_3.0-5 GGally_2.4.0 corrplot_0.95
## [5] knitr_1.50 readr_2.1.5 yardstick_1.3.2 workflowsets_1.1.1
## [9] workflows_1.3.0 tune_2.0.0 tidyr_1.3.1 tailor_0.1.0
## [13] rsample_1.3.1 recipes_1.3.1 purrr_1.1.0 parsnip_1.3.3
## [17] modeldata_1.5.1 infer_1.0.9 ggplot2_4.0.0 dplyr_1.1.4
## [21] dials_1.4.2 scales_1.4.0 broom_1.0.10 tidymodels_1.4.1
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 timeDate_4041.110 farver_2.1.2
## [4] S7_0.2.0 fastmap_1.2.0 digest_0.6.37
## [7] rpart_4.1.23 timechange_0.3.0 lifecycle_1.0.4
## [10] survival_3.6-4 magrittr_2.0.4 compiler_4.4.1
## [13] rlang_1.1.6 sass_0.4.10 tools_4.4.1
## [16] yaml_2.3.10 data.table_1.17.8 labeling_0.4.3
## [19] bit_4.6.0 DiceDesign_1.10 RColorBrewer_1.1-3
## [22] abind_1.4-8 withr_3.0.2 nnet_7.3-19
## [25] grid_4.4.1 sparsevctrs_0.3.4 future_1.67.0
## [28] globals_0.18.0 MASS_7.3-60.2 cli_3.6.5
## [31] crayon_1.5.3 rmarkdown_2.29 generics_0.1.4
## [34] rstudioapi_0.17.1 future.apply_1.20.0 tzdb_0.5.0
## [37] cachem_1.1.0 splines_4.4.1 parallel_4.4.1
## [40] vctrs_0.6.5 hardhat_1.4.2 Matrix_1.7-0
## [43] jsonlite_2.0.0 hms_1.1.3 bit64_4.6.0-1
## [46] Formula_1.2-5 listenv_0.9.1 gower_1.0.2
## [49] jquerylib_0.1.4 glue_1.8.0 parallelly_1.45.1
## [52] ggstats_0.11.0 codetools_0.2-20 lubridate_1.9.4
## [55] gtable_0.3.6 GPfit_1.0-9 tibble_3.3.0
## [58] pillar_1.11.1 furrr_0.3.1 htmltools_0.5.8.1
## [61] ipred_0.9-15 lava_1.8.1 R6_2.6.1
## [64] lhs_1.2.0 vroom_1.6.6 evaluate_1.0.5
## [67] lattice_0.22-6 backports_1.5.0 bslib_0.9.0
## [70] class_7.3-22 Rcpp_1.1.0 nlme_3.1-164
## [73] prodlim_2025.04.28 mgcv_1.9-1 xfun_0.53
## [76] pkgconfig_2.0.3
Documento generato con R Markdown - 2025-10-29