dsfmlkflksdfkenglfnglemlkefmgñlegmdsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñledsfmlkflksdfkenglfnglemlkefmgñle
#Variables
col1_nor=(c(46,45,35,42,62,54,47,50,47,53,49,45,42,48,45,67,34,47,56,43,38,59,62,61,54,57,46,44,32,32,50,44,64,62,34,65,37,47,52,47,53,48,54,52,41,46,37,44,43,59))
col2_nor=(c(51,44,59,56,51,42,44,48,42,37,54,46,43,41,65,37,50,48,51,54,48,51,52,37,65,41,55,52,54,52,49,65,46,38,45,46,48,46,40,58,50,58,56,51,43,45,56,34,41,49))
col1_nnor=(c(55,55,51,54,54,54,54,55,52,55,54,55,55,56,54,55,55,54,56,54,55,54,56,51,51,55,52,56,55,51,53,56,53,52,56,54,55,55,51,53,54,55,54,54,53,54,54,55,55,55))
col2_nnor=(c(55,55,51,54,52,55,54,51,54,51,54,52,54,55,54,53,55,54,51,51,55,54,55,54,53,55,54,53,55,52,54,53,55,56,54,56,55,54,55,54,55,54,53,51,51,51,55,54,52,54))
#Normalidad (Formal)
#Criterio de decision.
#p-value>0.05 los datos son normales
#p-value <0.05 los datos son NO normales
shapiro.test(col1_nor)
##
## Shapiro-Wilk normality test
##
## data: col1_nor
## W = 0.97303, p-value = 0.306
shapiro.test(col2_nor)
##
## Shapiro-Wilk normality test
##
## data: col2_nor
## W = 0.97845, p-value = 0.4887
shapiro.test(col1_nnor)
##
## Shapiro-Wilk normality test
##
## data: col1_nnor
## W = 0.86694, p-value = 4.598e-05
shapiro.test(col2_nnor)
##
## Shapiro-Wilk normality test
##
## data: col2_nnor
## W = 0.8655, p-value = 4.179e-05
#Correlacion para datos normales
cor(col1_nor,col2_nor) #Hace la correlacion de Pearson por default
## [1] -0.2595552
#Correlaci?n para datos NO normales
cor(col1_nnor,col2_nnor,method = 'spearman')# es la misma instrucci?n pero se especifica el m?todo
## [1] 0.04881636
#Otra forma de hacer la correlacion en R es usando la paqueteria de PerformanceAnalytics y seguir con el codigo
#Datos normales
library(PerformanceAnalytics) #Cargamos la paqueteria
## Warning: package 'PerformanceAnalytics' was built under R version 4.4.3
## Cargando paquete requerido: xts
## Warning: package 'xts' was built under R version 4.4.3
## Cargando paquete requerido: zoo
##
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Adjuntando el paquete: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
#Hacemos un data.frame de los datos
dat1=data.frame(col1_nor, col2_nor)
chart.Correlation(dat1)#Corremos la funci?n correlacionar y nos arroja tambien grafico.
#Datos No normales
library(PerformanceAnalytics) #Cargamos la paqueteria
#Hacemos un data.frame (Tabla) de los datos
dat2=data.frame(col1_nnor, col2_nnor)
chart.Correlation(dat2,method = 'spearman')#Corremos la funcion correlacionar y nos arroja tambien grafico.
## Warning in cor.test.default(as.numeric(x), as.numeric(y), method = method):
## Cannot compute exact p-value with ties
chart.Correlation(dat2,method = 'kendall')
#Matriz de correlaciones
datos <- data.frame(col1_nor,col2_nor,col1_nnor,col2_nnor)
head(datos)
## col1_nor col2_nor col1_nnor col2_nnor
## 1 46 51 55 55
## 2 45 44 55 55
## 3 35 59 51 51
## 4 42 56 54 54
## 5 62 51 54 52
## 6 54 42 54 55
pairs(x = datos, lower.panel = NULL)
cor(x = datos, method = "pearson")
## col1_nor col2_nor col1_nnor col2_nnor
## col1_nor 1.00000000 -0.25955517 -0.07078695 0.11999743
## col2_nor -0.25955517 1.00000000 -0.06273984 -0.11748176
## col1_nnor -0.07078695 -0.06273984 1.00000000 0.04317691
## col2_nnor 0.11999743 -0.11748176 0.04317691 1.00000000
#presentacion de datos 1
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.3
## corrplot 0.95 loaded
par(mfrow = c(1,1))
corrplot(corr = cor(x = datos, method = "pearson"), method = "number",
tl.cex = 0.7,number.cex = 1, cl.pos = "n")
#presentacion de datos 2
library(psych)
## Warning: package 'psych' was built under R version 4.4.3
pairs.panels(x = datos, ellipses = FALSE, lm = TRUE, method = "pearson")
#presentacion de datos 3
library(GGally)
## Warning: package 'GGally' was built under R version 4.4.3
## Cargando paquete requerido: ggplot2
## Warning: package 'ggplot2' was built under R version 4.4.3
##
## Adjuntando el paquete: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
ggpairs(iris, lower = list(continuous = "smooth"),
diag = list(continuous = "bar"), axisLabels = "none")
## Warning in check_and_set_ggpairs_defaults("diag", diag, continuous =
## "densityDiag", : Changing diag$continuous from 'bar' to 'barDiag'
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.