En la siguiente tarea, realizaremos una serie de gráficos de dispersión y calcularemos los coeficientes de correlación entre el índice de coste vida y el resto variables que forman nuestra base de datos, con el fin de determinar el tipo de comportamiento y relación que guardan entre ellas.Estas relaciones se utilizarán en el objetivo 1 y 4 para apoyar las conclusiones obtenidas en dichos puntos. Para ellos se utilizarán dos bases de datos (Df_nuevas_discretizadas y datos_sinfaltantes), que contienen las variables mencionadas en el HITO 1 y el HITO 2, así como en el objetivo 1; con la diferencia de que en la base de datos de nombre Df_nuevas_discretizadas se incluyen 3 varibales nuevas (Economías, Bienestar, Energéticas).
En los gráficos de dispersión, cada punto representa una observación y su posición en el gráfico indica su valor en ambas variables. Si los puntos están muy dispersos en el gráfico, esto indica que las variables tienen una baja correlación o que hay mucha variabilidad en los datos. Si los puntos están más juntos y siguen una cierta tendencia, esto indica que las variables tienen una correlación más fuerte. También es posible agregar una línea de tendencia a un gráfico de dispersión para visualizar mejor la relación entre las dos variables. Esto permite visualizar si hay una relación lineal entre las variables y la dirección de la relación (positiva o negativa).
Comenzaremos cargando las librerías necesarias para nuestro análisis. Se incluirá una opción para suprimir las advertencias que aparecen al ejecutarse el código por las distintas versiones de R sobre las que trabajan.
Mencionar que se utilizarán gráficos estáticos y gráficos dinámicos aunque estos representen la misma información con el fín de visualiar mejor las relaciones entre variables.
Las librerías utilizadas durante el análisis son las siguientes:
Library(dplyr): permite realizar operaciones comunes de manipulación de datos, como filtrar filas, seleccionar columnas, agregar datos, ordenar datos y realizar cálculos agrupados.
Library(echarts4r): permite crear gráficos interactivos y visualizaciones de datos utilizando la biblioteca de gráficos ECharts de JavaScript; lo que facilita la exploración y presentación de datos.
Library(PerformanceAnalytics): ofrece una amplia gama de funciones para el cálculo de medidas de rendimiento, entre otros. También incluye funciones para trazar gráficos y visualizar datos.
Library(corrplot): esta biblioteca es útil para analizar la relación y la fuerza de la correlación entre múltiples variables. Proporciona diversas funciones para visualizar matrices de correlación utilizando diferentes métodos, como gráficos de color, gráficos de círculo, gráficos de mosaico y más.
load("base_objetivo1.Rdata")
head(datos_sin_faltantes)
head(Df_nuevas_discretizadas)
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(echarts4r)))
suppressWarnings(suppressMessages(library(tidyverse)))
#library(lubridate)
#library(prophet)
suppressWarnings(suppressMessages(library(PerformanceAnalytics)))
suppressWarnings(suppressMessages(library(corrplot)))
Comenzaremos estudiando la relación entre la variable Índice de Coste de Vida y el resto de variables que se encuentran en el mismo grupo con el nombre Coste de Vida. Se espera que los resultados que se obtengan sean positivos y fuertemente relacionados, ya que algunas de estas variables se suelen utilizar en el calculo del índice de coste de vida. Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables:
Índice de Alquiler
Índice de Coste de Vida más alquiler
Índice de comestibles
Índice de precios en Restaurantes
Índice de poder Adquisitivo local
#Coeficiente de correlación:
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Alquiler, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Alquiler, name = "Paises") %>%
e_lm(Indice_de_Alquiler ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice de Alquiler") %>%
e_title(
text = "Indice Coste de Vida vs. Indice de Alquiler",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
####################### Segundo Gráfico ###########################################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Alquiler = cut(Indice_de_Alquiler, n_bins)
) %>% #se han agrupado valores para facilitar la visualización creando rangos
count(Indice_de_Costo_de_Vida, Indice_de_Alquiler) %>%
e_charts(Indice_de_Alquiler) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice de Alquiler/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Alquiler")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Costo_de_Vida_mas_Alquiler, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Costo_de_Vida_mas_Alquiler, name = "Paises") %>%
e_lm(Indice_de_Costo_de_Vida_mas_Alquiler ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice de Alquiler mas coste de vida") %>%
e_title(
text = "Indice Coste de Vida vs. Indice de Alquiler mas coste de vida",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
####################### Segundo Gráfico ###########################################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Costo_de_Vida_mas_Alquiler = cut(Indice_de_Costo_de_Vida_mas_Alquiler, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Costo_de_Vida_mas_Alquiler) %>%
e_charts(Indice_de_Costo_de_Vida_mas_Alquiler) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice de Alquiler mas coste vida/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Costo_de_Vida_mas_Alquiler")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Comestibles, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Comestibles, name = "Paises") %>%
e_lm(Indice_de_Comestibles ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Comestibles") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Comestibles",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
####################### Segundo Gráfico ###########################################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Comestibles = cut(Indice_de_Comestibles, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Comestibles) %>%
e_charts(Indice_de_Comestibles) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Comestibles/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Comestibles")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Precios_en_Restaurantes, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Precios_en_Restaurantes, name = "Paises") %>%
e_lm(Indice_de_Precios_en_Restaurantes ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Precios_en_Restaurantes") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Precios_en_Restaurantes",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
####################### Segundo Gráfico ###########################################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Precios_en_Restaurantes = cut(Indice_de_Precios_en_Restaurantes, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Precios_en_Restaurantes) %>%
e_charts(Indice_de_Precios_en_Restaurantes) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Precios_en_Restaurantes/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Precios_en_Restaurantes")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Poder_Adquisitivo_Local, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Poder_Adquisitivo_Local, name = "Paises") %>%
e_lm(Indice_de_Poder_Adquisitivo_Local ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Poder_Adquisitivo_Local") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Poder_Adquisitivo_Local",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
####################### Segundo Gráfico ###########################################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Poder_Adquisitivo_Local = cut(Indice_de_Poder_Adquisitivo_Local, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Poder_Adquisitivo_Local) %>%
e_charts(Indice_de_Poder_Adquisitivo_Local) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Poder_Adquisitivo_Local/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Poder_Adquisitivo_Local")
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
pairs(~ Indice_de_Costo_de_Vida + Indice_de_Alquiler + Indice_de_Costo_de_Vida_mas_Alquiler + Indice_de_Comestibles + Indice_de_Precios_en_Restaurantes + Indice_de_Poder_Adquisitivo_Local , data = datos_sin_faltantes,
main = "Índice de Coste de Vida vs Grupo Coste de Vida")
#Matriz de Correlación Dinámica
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Costo_de_Vida, Indice_de_Alquiler, Indice_de_Costo_de_Vida_mas_Alquiler,Indice_de_Comestibles, Indice_de_Precios_en_Restaurantes, Indice_de_Poder_Adquisitivo_Local) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlación Índice Coste de vida vs Grupo Coste de Vida")
datos <- data.frame(datos_sin_faltantes$Indice_de_Alquiler, datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Costo_de_Vida_mas_Alquiler, datos_sin_faltantes$Indice_de_Comestibles, datos_sin_faltantes$Indice_de_Precios_en_Restaurantes, datos_sin_faltantes$Indice_de_Poder_Adquisitivo_Local)
# Calcular la matriz de correlación Estática
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(datos_sin_faltantes[, c("Indice_de_Alquiler", "Indice_de_Costo_de_Vida", "Indice_de_Costo_de_Vida_mas_Alquiler", "Indice_de_Comestibles", "Indice_de_Precios_en_Restaurantes", "Indice_de_Poder_Adquisitivo_Local")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
Como se puede observar por los distintos gráficos de correlación y
dispersión, la variable índice coste de vida y el resto de variables del
grupo Coste de Vida guardan una fuerte relación positiva. Resultado que
se esperaba ya que algunas de estas variables son usadas para el cálculo
de índices de coste de vida. La importancia que guardan estas variables
con índice de coste de vida y la agrupación subjetiva que se ha hecho al
llamar al conjunto de dichas variables Coste de vida, se comprobará en
objetivos posteriores con la aplicación de algoritmos de Clustering y
PCA.
A continuación estudiaremos la relación entre la variable Índice de Coste de Vida y el resto de variables que se encuentran en el grupo con el nombre Economía. Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables:
datos_sin_faltantes$Indice_de_Poder_Adquisitivo = as.numeric(datos_sin_faltantes$Indice_de_Poder_Adquisitivo)
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Poder_Adquisitivo, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Poder_Adquisitivo, name = "Paises") %>%
e_lm(Indice_de_Poder_Adquisitivo ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Poder_Adquisitivo") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Poder_Adquisitivo",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Poder_Adquisitivo = cut(Indice_de_Poder_Adquisitivo, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Poder_Adquisitivo) %>%
e_charts(Indice_de_Poder_Adquisitivo) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Poder_Adquisitivo/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Poder_Adquisitivo")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$PIB, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(PIB, name = "Paises") %>%
e_lm(PIB ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "PIB") %>%
e_title(
text = "Indice Coste de Vida vs. PIB",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
PIB = cut(PIB, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, PIB) %>%
e_charts(PIB) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. PIB/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "PIB")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Salario_Medio, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Salario_Medio, name = "Paises") %>%
e_lm(Salario_Medio ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Salario_Medio") %>%
e_title(
text = "Indice Coste de Vida vs. Salario_Medio",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Salario_Medio = cut(Salario_Medio, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Salario_Medio) %>%
e_charts(Salario_Medio) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Salario_Medio/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Salario_Medio")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Salario_Minimo, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Salario_Minimo, name = "Paises") %>%
e_lm(Salario_Minimo ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Salario_Minimo") %>%
e_title(
text = "Indice Coste de Vida vs. Salario_Minimo",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Salario_Minimo = cut(Salario_Minimo, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Salario_Minimo) %>%
e_charts(Salario_Minimo) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Salario_Minimo/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Salario_Minimo")
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
pairs(~ Indice_de_Costo_de_Vida + Indice_de_Poder_Adquisitivo + PIB + Salario_Medio + Salario_Minimo, data=datos_sin_faltantes,
main = " Índice de Coste de Vida vs de grupo Economía")
#Matriz de Correlación Dinámica
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Costo_de_Vida, Indice_de_Poder_Adquisitivo, PIB, Salario_Medio, Salario_Minimo) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlación Índice Coste de vida vs Grupo Economía")
# Crear una matriz de datos con las variables
datos <- data.frame(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Poder_Adquisitivo,
datos_sin_faltantes$PIB,
datos_sin_faltantes$Salario_Medio,
datos_sin_faltantes$Salario_Minimo)
# Calcular la matriz de correlación Estática
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(datos_sin_faltantes[, c("Indice_de_Costo_de_Vida", "Indice_de_Poder_Adquisitivo", "PIB", "Salario_Medio", "Salario_Minimo")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
Como se puede observar por los distintos gráficos de correlación y
dispersión, la variable índice coste de vida y el resto de variables del
grupo Economía guardan una fuerte relación positiva también. Resultado
que se esperaba ya que la relación entre la economía y el índice de
costo de vida es estrecha y compleja. Es importante destacar que la
relación entre la economía y el índice de costo de vida puede variar
según el contexto económico y las condiciones específicas de cada
país.
Se sabe que, la inflación, que es el aumento generalizado y sostenido en el nivel de precios, tiene un impacto directo en el índice de costo de vida. Si los precios de los bienes y servicios aumentan, el ICV reflejará ese incremento y mostrará un aumento en el costo de vida.Los salarios y la tasa de empleo también influyen en el índice de costo de vida. Si los salarios aumentan más rápidamente que la inflación, es probable que el costo de vida se eleve. Por otro lado, si el desempleo es alto y los salarios se estancan o disminuyen, es probable que el índice de costo de vida refleje una menor presión inflacionaria.
La importancia que guardan estas variables con índice de coste de vida y la agrupación subjetiva que se ha hecho al llamar al conjunto de dichas variables Coste de vida, se comprobará en objetivos posteriores con la aplicación de algoritmos de Clustering y PCA.
A continuación estudiaremos la relación entre la variable Índice de Coste de Vida y el resto de variables que se encuentran en el grupo con el nombre BIENESTAR.Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables:
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_Felicidad, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_Felicidad, name = "Paises") %>%
e_lm(Indice_Felicidad ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_Felicidad") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_Felicidad",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_Felicidad = cut(Indice_Felicidad, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_Felicidad) %>%
e_charts(Indice_Felicidad) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_Felicidad/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_Felicidad")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Criminalidad, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Criminalidad, name = "Paises") %>%
e_lm(Indice_de_Criminalidad ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Criminalidad") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Criminalidad",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Criminalidad = cut(Indice_de_Criminalidad, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Criminalidad) %>%
e_charts(Indice_de_Criminalidad) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Criminalidad/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Criminalidad")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Seguridad, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Seguridad, name = "Paises") %>%
e_lm(Indice_de_Seguridad ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Seguridad") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Seguridad",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Seguridad = cut(Indice_de_Seguridad, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Seguridad) %>%
e_charts(Indice_de_Seguridad) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Seguridad/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Seguridad")
datos_sin_faltantes$Indice_de_Calidad_de_Vida = as.numeric(datos_sin_faltantes$Indice_de_Calidad_de_Vida)
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Calidad_de_Vida, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Calidad_de_Vida, name = "Paises") %>%
e_lm(Indice_de_Calidad_de_Vida ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Calidad_de_Vida") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Calidad_de_Vida",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Calidad_de_Vida = cut(Indice_de_Calidad_de_Vida, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Calidad_de_Vida) %>%
e_charts(Indice_de_Calidad_de_Vida) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Calidad_de_Vida/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Calidad_de_Vida")
datos_sin_faltantes$Indice_de_Sanidad = as.numeric(datos_sin_faltantes$Indice_de_Sanidad)
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Sanidad, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Sanidad, name = "Paises") %>%
e_lm(Indice_de_Sanidad ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Sanidad") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Sanidad",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Sanidad = cut(Indice_de_Sanidad, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Sanidad) %>%
e_charts(Indice_de_Sanidad) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Sanidad/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Sanidad")
datos_sin_faltantes$Indice_de_Clima = as.numeric(datos_sin_faltantes$Indice_de_Clima)
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Clima, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Clima, name = "Paises") %>%
e_lm(Indice_de_Clima ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Clima") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Clima",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Clima = cut(Indice_de_Clima, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Clima) %>%
e_charts(Indice_de_Clima) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Clima/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Clima")
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
pairs(~ Indice_de_Costo_de_Vida+Indice_Felicidad+Indice_de_Criminalidad+Indice_de_Seguridad+Indice_de_Calidad_de_Vida+Indice_de_Sanidad+Indice_de_Clima , data = datos_sin_faltantes,
main = "Índice de Coste de Vida vs de grupo Bienestar")
#Matriz de Correlación Dinámica
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Costo_de_Vida, Indice_Felicidad, Indice_de_Criminalidad,Indice_de_Seguridad, Indice_de_Calidad_de_Vida, Indice_de_Sanidad,Indice_de_Clima) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlación Índice Coste de vida vs Grupo Bienestar")
# Crear una matriz de datos con las variables
datos <- data.frame(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_Felicidad, datos_sin_faltantes$Indice_de_Criminalidad, datos_sin_faltantes$Indice_de_Seguridad, datos_sin_faltantes$Indice_de_Calidad_de_Vida, datos_sin_faltantes$Indice_de_Sanidad, datos_sin_faltantes$Indice_de_Clima)
# Calcular la matriz de correlación Estática
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(datos_sin_faltantes[, c("Indice_de_Costo_de_Vida", "Indice_Felicidad", "Indice_de_Criminalidad","Indice_de_Seguridad", "Indice_de_Calidad_de_Vida", "Indice_de_Sanidad","Indice_de_Clima")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
El costo de vida se refiere al gasto necesario para cubrir las
necesidades básicas y mantener un nivel de vida determinado, mientras
que el bienestar se refiere al grado de satisfacción y calidad de vida
de las personas. Por lo que se espera que la mayoría de las variables
guarden una relación estrecha y positiva.
Como podemos observar, efectivamente la mayoría de variables están relacionadas positivamente con índice de coste de vida, salvo índice de clima e índice de criminalidad. Esta última tiene una correlación negativa, opuesta a índice de seguridad (expresan la misma información en realidad). Es decir, cuanto mayor es el nivel de coste de vida, menor es el índice de criminalidad. Si bien no hay una relación directa entre el índice de costo de vida y el índice de seguridad, ambos pueden ser considerados como aspectos importantes de la calidad de vida en una región determinada. Por ejemplo, una alta seguridad puede mejorar la calidad de vida al proporcionar tranquilidad y reducir el estrés relacionado con la seguridad personal. Al mismo tiempo, un alto costo de vida puede afectar negativamente la calidad de vida al limitar el acceso a bienes y servicios básicos.
En resumen, aunque el índice de costo de vida y el índice de seguridad miden aspectos diferentes, ambos pueden tener un impacto significativo en la calidad de vida de las personas y se consideran factores importantes a la hora de evaluar la idoneidad de un lugar para vivir o visitar.
En cuanto al índice de clima, vemos como apenas tiene relación con la variable que estamos estudiando, su gráfico de dispersión es una nube de puntos sin una tendencia lineal y su coeficiente es cercano a uno.
A continuación estudiaremos la relación entre la variable Índice de Coste de Vida y el resto de variables que se encuentran en el grupo con el nombre ENERGETICO.Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables:
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Consumo_GWh, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Consumo_GWh, name = "Paises") %>%
e_lm(Consumo_GWh ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Consumo_GWh") %>%
e_title(
text = "Indice Coste de Vida vs. Consumo_GWh",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Consumo_GWh = cut(Consumo_GWh, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Consumo_GWh) %>%
e_charts(Consumo_GWh) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Consumo_GWh/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Consumo_GWh")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$CO2_per_capita, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(CO2_per_capita, name = "Paises") %>%
e_lm(CO2_per_capita ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "CO2_per_capita") %>%
e_title(
text = "Indice Coste de Vida vs. CO2_per_capita",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
CO2_per_capita = cut(CO2_per_capita, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, CO2_per_capita) %>%
e_charts(CO2_per_capita) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. CO2_per_capita/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "CO2_per_capita")
datos_sin_faltantes$Indice_de_Contaminacion = as.numeric(datos_sin_faltantes$Indice_de_Contaminacion)
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Indice_de_Contaminacion, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Indice_de_Contaminacion, name = "Paises") %>%
e_lm(Indice_de_Contaminacion ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Indice_de_Contaminacion") %>%
e_title(
text = "Indice Coste de Vida vs. Indice_de_Contaminacion",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Indice_de_Contaminacion = cut(Indice_de_Contaminacion, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Indice_de_Contaminacion) %>%
e_charts(Indice_de_Contaminacion) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Indice_de_Contaminacion/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Indice_de_Contaminacion")
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
pairs(~ Indice_de_Costo_de_Vida + Consumo_GWh+CO2_per_capita+Indice_de_Contaminacion , data = datos_sin_faltantes,
main = "Índice de Coste de Vida vs Grupo Energético")
#Matriz de Correlación Dinámica
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Costo_de_Vida , Consumo_GWh, CO2_per_capita, Indice_de_Contaminacion) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlación Índice Coste de vida vs Grupo Energético")
# Crear una matriz de datos con las variables
datos <- data.frame(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Consumo_GWh, datos_sin_faltantes$CO2_per_capita, datos_sin_faltantes$Indice_de_Contaminacion)
# Calcular la matriz de correlación Estática
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(datos_sin_faltantes[, c("Indice_de_Costo_de_Vida" , "Consumo_GWh", "CO2_per_capita", "Indice_de_Contaminacion")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
En este caso, vemos menos correlación entre la variable índice de coste
de vida y el grupo de variables que hacen referencia a la energía. Las
mayores correlaciones están entre índice de coste de vida y consumo de
Gwh e índice de coste de vida e índice de contaminación. Este último
caso, tiene una correlación bastante negativa. Esto indica que a mayor
índice de coste de vida, menor índice de contaminación. En cuanto al
consumo electrico, vemos como tienen una relación bastante positiva,
intuyendo que a mayor índice de coste de vida, mayor consumo
eléctrico.
Es un resultado se esperaban obtener algo más positivo, ya que el costo de vida y la energía están estrechamente relacionados, ya que el costo de la energía puede influir en los gastos domésticos, el transporte, la inflación y las oportunidades económicas. Las políticas energéticas y los cambios en los precios de la energía pueden tener un impacto significativo en el costo de vida de las personas y en su capacidad para mantener un nivel de vida deseado.
El índice de coste de vida y el co2 per capita no tienen apenas relación, algo totalmente esperado. El coste de vida y las emisiones de CO2 per cápita no están directamente relacionados. Sin embargo, el coste de vida puede influir en la cantidad de emisiones de CO2 per cápita. Por ejemplo, en países con un alto coste de vida, las personas tienden a tener un mayor poder adquisitivo y, por lo tanto, pueden permitirse un estilo de vida más lujoso que puede incluir viajes en avión o en coche con más frecuencia. Esto puede aumentar la cantidad de emisiones de CO2 per cápita.Pero esto es algo que no se va a trabajar en nuestro proyecto, porque no forma parte de nuestros objetivos principales.
En el objetivo 4, estas relaciones se van a trabajar y a analizar tanto mediante discretización de las variables para medir la disminución que han tenido en el consumo como en la representación gráfica de los países.
A continuación estudiaremos la relación entre la variable Índice de Coste de Vida y el resto de variables que se encuentran en el grupo con el nombre GASTO PÚBLICO.Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables:
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Gasto_Publico, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Gasto_Publico, name = "Paises") %>%
e_lm(Gasto_Publico ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Gasto_Publico") %>%
e_title(
text = "Indice Coste de Vida vs. Gasto_Publico",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Gasto_Publico = cut(Gasto_Publico, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Gasto_Publico) %>%
e_charts(Gasto_Publico) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Gasto_Publico/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Gasto_Publico")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Gasto_Salud, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Gasto_Salud, name = "Paises") %>%
e_lm(Gasto_Salud ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Gasto_Salud") %>%
e_title(
text = "Indice Coste de Vida vs. Gasto_Salud",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Gasto_Salud = cut(Gasto_Salud, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Gasto_Salud) %>%
e_charts(Gasto_Salud) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Gasto_Salud/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Gasto_Salud")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Gasto_Educacion, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Gasto_Educacion, name = "Paises") %>%
e_lm(Gasto_Educacion ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Gasto_Educacion") %>%
e_title(
text = "Indice Coste de Vida vs. Gasto_Educacion",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Gasto_Educacion = cut(Gasto_Educacion, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Gasto_Educacion) %>%
e_charts(Gasto_Educacion) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Gasto_Educacion/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Gasto_Educacion")
coef_cor <- cor(datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Gasto_Defensa, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
datos_sin_faltantes %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Gasto_Defensa, name = "Paises") %>%
e_lm(Gasto_Defensa ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Gasto_Defensa") %>%
e_title(
text = "Indice Coste de Vida vs. Gasto_Defensa",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
datos_sin_faltantes %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Gasto_Defensa = cut(Gasto_Defensa, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Gasto_Defensa) %>%
e_charts(Gasto_Defensa) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Gasto_Defensa/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Gasto_Defensa")
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
pairs(~ Indice_de_Costo_de_Vida+Gasto_Publico+Gasto_Salud+Gasto_Educacion+Gasto_Defensa , data = datos_sin_faltantes,
main = "Índice de Coste de Vida vs Grupo Gasto Público")
#Matriz de Correlación Dinámica
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Costo_de_Vida, Gasto_Publico, Gasto_Salud, Gasto_Educacion,Gasto_Defensa) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlación Índice Coste de vida vs Grupo Gasto Público")
# Crear una matriz de datos con las variables
datos <- data.frame(datos_sin_faltantes$Gasto_Publico, datos_sin_faltantes$Indice_de_Costo_de_Vida, datos_sin_faltantes$Gasto_Salud, datos_sin_faltantes$Gasto_Educacion, datos_sin_faltantes$Gasto_Defensa)
# Calcular la matriz de correlación Estática
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(datos_sin_faltantes[, c("Indice_de_Costo_de_Vida", "Gasto_Publico", "Gasto_Salud", "Gasto_Educacion","Gasto_Defensa")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
Como podemos observar, la única correlación que se muestra positivamente significativa es la del índice de costed de vida y el gasto en sanidad. Son unos resultados que no esperabamos conseguir, ya que se esperaba que el gasto público estuviera relacionado con el índice de coste de vida, pero hemos comprado que no es así. Es importante tener en cuenta que la relación entre el costo de vida y el gasto público puede ser altamente contextual y depende de la eficiencia y la efectividad de cómo se asignan y utilizan los recursos públicos. Además, la relación puede variar entre países, regiones e incluso ciudades dentro de un mismo país debido a las diferencias en la estructura económica, las políticas gubernamentales y otros factores locales.
La correlación positiva obtenida puede deberse a que el nivel de gasto público en servicios públicos y programas de bienestar social, como salud, educación, transporte y vivienda, puede influir en el costo de vida. Si un país o una región invierte una cantidad significativa de su presupuesto en estos servicios y programas, es posible que los ciudadanos tengan acceso a servicios de alta calidad a precios asequibles, lo que podría reducir el costo de vida. Por otro lado, si hay una falta de inversión en servicios públicos, es posible que los ciudadanos tengan que gastar más en servicios privados, lo que podría aumentar el costo de vida.
El gasto público puede influir en el costo de vida de varias maneras, como por ejemplo, a través de la inversión en infraestructura y servicios públicos que pueden mejorar la calidad de vida de las personas y reducir los costos asociados con la vida cotidiana. Por otro lado, un aumento en los impuestos para financiar el gasto público puede aumentar los costos para los consumidores y reducir su poder adquisitivo.
A continuación estudiaremos la relación entre la variable Índice de Coste de Vida y algunas variables que se encuentran en el dataFrame con el nombre Df_nuevas_discretizas Por lo tanto, se estudiará la relación entre el Índice de Coste de Vida y las siguientes variables: - Economía - Bienestar - Energía
Df_nuevas_discretizadas$Economia= as.numeric(Df_nuevas_discretizadas$Economia)
coef_cor <- cor(Df_nuevas_discretizadas$Indice_de_Costo_de_Vida, Df_nuevas_discretizadas$Economia, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
Df_nuevas_discretizadas %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Economia, name = "Paises") %>%
e_lm(Economia ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Economia") %>%
e_title(
text = "Indice Coste de Vida vs. Economia",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
Df_nuevas_discretizadas %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Economia = cut(Economia, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Economia) %>%
e_charts(Economia) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Economia/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Economia")
Df_nuevas_discretizadas$Bienestar= as.numeric(Df_nuevas_discretizadas$Bienestar)
coef_cor <- cor(Df_nuevas_discretizadas$Indice_de_Costo_de_Vida, Df_nuevas_discretizadas$Bienestar, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
Df_nuevas_discretizadas %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Bienestar, name = "Paises") %>%
e_lm(Bienestar ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Bienestar") %>%
e_title(
text = "Indice Coste de Vida vs. Bienestar",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
Df_nuevas_discretizadas %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Bienestar = cut(Bienestar, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Bienestar) %>%
e_charts(Bienestar) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Bienestar/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Bienestar")
Df_nuevas_discretizadas$Energetico= as.numeric(Df_nuevas_discretizadas$Energetico)
coef_cor <- cor(Df_nuevas_discretizadas$Indice_de_Costo_de_Vida, Df_nuevas_discretizadas$Energetico, method = "pearson")
coef_cor_text <- paste("Coef.Correlación =", round(coef_cor, 4))
Df_nuevas_discretizadas %>%
e_charts(x = Indice_de_Costo_de_Vida) %>%
e_scatter(Energetico, name = "Paises") %>%
e_lm(Energetico ~ Indice_de_Costo_de_Vida, name = "Linear model") %>%
e_axis_labels(x = "Indice Coste de Vida", y = "Energetico") %>%
e_title(
text = "Indice Coste de Vida vs. Energetico",
subtext = coef_cor_text
) %>%
e_x_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 3),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_y_axis(
nameLocation = "center",
splitArea = list(show = FALSE),
axisLabel = list(margin = 0),
axisPointer = list(
show = TRUE,
lineStyle = list(
color = "#999999",
width = 0.75,
type = "dotted"
)
)
) %>%
e_legend(
orient = "horizontal",
bottom = "bottom" # Ajusta la posición vertical de la leyenda
)
#######################
n_bins <- 100
Df_nuevas_discretizadas %>%
mutate(
Indice_de_Costo_de_Vida = cut(Indice_de_Costo_de_Vida, n_bins),
Energetico = cut(Energetico, n_bins)
) %>%
count(Indice_de_Costo_de_Vida, Energetico) %>%
e_charts(Energetico) %>%
e_heatmap(Indice_de_Costo_de_Vida, n) %>%
e_visual_map(n) %>%
e_title(text = paste("Indice Coste de Vida vs. Energetico/Coef.Correlación =", round(coef_cor, 4))) %>%
e_axis_labels("Indice_de_Costo_de_Vida ", "Energetico")
pairs(~ Economia + Energetico + Bienestar + Indice_de_Costo_de_Vida,
data = Df_nuevas_discretizadas,
main = "Gráfico de Matriz de Dispersión con varias variables")
cor_data <- Df_nuevas_discretizadas %>%
select(Economia, Energetico, Bienestar, Indice_de_Costo_de_Vida) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlation")
# Crear una matriz de datos con las variables
datos <- data.frame(Df_nuevas_discretizadas$Economia, Df_nuevas_discretizadas$Bienestar, Df_nuevas_discretizadas$Energetico,Df_nuevas_discretizadas$Indice_de_Costo_de_Vida)
# Calcular la matriz de correlación
matriz_cor <- cor(datos)
# Crear un mapa de calor de la matriz de correlación
corrplot(matriz_cor, method="circle",tl.col = "black", tl.srt = 45, tl.cex = 0.7)
# Crear un gráfico de correlación con histogramas y puntos
chart.Correlation(Df_nuevas_discretizadas[, c("Economia", "Energetico", "Bienestar","Indice_de_Costo_de_Vida")],
histogram = TRUE,
method = "pearson",
pch = 19,
col = "blue",
type = "upper",
main = "Gráfico de correlación con histogramas y puntos")
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
## Warning in par(usr): argument 1 does not name a graphical parameter
# Crear una matriz de datos con las variables
datos <- data.frame(Df_nuevas_discretizadas$Economia, Df_nuevas_discretizadas$Energetico, Df_nuevas_discretizadas$Bienestar,
Df_nuevas_discretizadas$Indice_de_Costo_de_Vida)
# Calcular la matriz de
matriz_cor <- cor(datos)
La relación con menor coeficiente de correlación es la variable energética con índice de coste de vida, resultado esperado basándonos en todo lo obtenido anteriormente con la relación entre el coste de vida y el grupo energético.
Sin embargo la relación entre la variable economía y bienestar con coste de vida han salido muy correlacionadas positivamente, lo que concuerda con los resultados obtenidos previamente sobre las relaciones con las variables del grupo economía y bienestar y el indice de coste de vida.
Esto nos indica que las tres variables creadas en el objetivo primero han sido correctamente creadas y están en coherencia con los resultados obtenidos.
#Gráfico de matriz de dispersión:este tipo de gráfico muestra la dispersión entre varias variables en un solo gráfico. Cada celda de la matriz representa un par de variables y se muestra un gráfico de dispersión para cada par.
#####Correlaciones fichero datos sin faltantes
cor_data <- datos_sin_faltantes %>%
select(Indice_de_Alquiler, Indice_de_Criminalidad, Indice_de_Seguridad, Consumo_GWh, CO2_per_capita, Gasto_Educacion, Indice_de_Costo_de_Vida,Indice_de_Contaminacion, PIB, Indice_de_Clima, Indice_de_Sanidad, Indice_de_Poder_Adquisitivo, Indice_de_Calidad_de_Vida, Indice_de_Costo_de_Vida,Salario_Medio,Salario_Minimo, Indice_Felicidad , Gasto_Publico , Gasto_Salud , Gasto_Defensa , Indice_de_Costo_de_Vida, Indice_de_Alquiler, Indice_de_Criminalidad, Indice_de_Seguridad, Consumo_GWh, CO2_per_capita, Gasto_Educacion, Indice_de_Costo_de_Vida
) %>%
magrittr::set_colnames(colnames(.) %>% str_replace("_", " ") %>% str_to_title()) %>%
cor()
cor_data %>%
e_charts() %>%
e_correlations(
visual_map = TRUE,
order = "hclust",
inRange = list(color = c('#edafda', '#eeeeee', '#59c4e6')), # scale colors
itemStyle = list(
borderWidth = 2,
borderColor = "#fff"
)
) %>%
e_title("Correlation")
Como podemos observar, la mayoría de nuestras variables muestran una correlación positiva significante con el indice de coste de vida y unas pocos guardan correlación negativa.
Los resultados obtenidos con estos análisis bivariantes respaldan los resultados obtenidos en el objetivo 1 y 4, logrando una coherencia y cohesión en el trabajo.