library(DescTools)
## Warning: package 'DescTools' was built under R version 4.1.3
library(tidyr)
library(pastecs)
library(PerformanceAnalytics)
## Warning: package 'zoo' was built under R version 4.1.3
library(nortest)
library(normtest)
library(correlation)
library(boot)
library(corrplot)
library(qgraph)
rm(list = ls(all = TRUE)) # clear workspace
cat("\f") # Borra la consola
#dev.off() # Borra las plots
setwd("C:/CURSO REG JMG") #Ajuste del directorio de trabajo
data ("airquality") # Conjunto de datos
Datos<-airquality
Datos<-Datos %>% drop_na() #Eliminar celdas con NA
attach(Datos)
¿Qué es la correlación? Es una medida estadística que expresa hasta qué punto dos variables están relacionadas linealmente. Es una herramienta común para describir relaciones simples sin hacer afirmaciones sobre causa y efecto.
¿Cómo se mide la correlación? El coeficiente de correlación de la muestra, r, cuantifica la intensidad de la relación. Las correlaciones también se someten a pruebas para establecer su significancia estadística.
Supuestos que fundamentan al coeficiente de correlación La distribución conjunta de las variables (X, Y) debe ser normal bivariada. Debe existir una relación de tipo lineal entre las variables (X, Y). Para cada valor de X, hay una subpoblación de valores de Y normalmente distribuidas. Las subpoblaciones de X tienen varianza constante.
##Boxplot de los datos
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
boxplot(Datos [1:4], col=terrain.colors(4) ) # Boxplot de todas las variables
Variable<-Ozone # Cual es su variable de interes?
hist(Variable, prob = FALSE, # Histograma de una variables
col = "white",
main = "")
# Nuevo gráfico
par(new = TRUE)
# Box plot
boxplot(Variable, horizontal = TRUE, axes = FALSE,
col = rgb(0, 0.8, 1, alpha = 0.5))
# Caja
box()
require("lattice") # Histograma multiple
histogram(~Temp|as.factor(Month),data=Datos, col="#FF7F50", type = "percent") # temperatura como factor
chart.Correlation(Datos[,1:4], # elegir las variables
method="pearson", # Puede usar otro tipo de correlacion
histogram=TRUE,
pch=16)
# Analizando la correlación entre ozono y temperatura
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Pruebas de normalidad #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plot(Ozone, Temp) # Viendo la relación entre ozono y temperatura
lillie.test(Ozone) # Prueba de normalidad de ozono
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: Ozone
## D = 0.15078, p-value = 1.613e-06
lillie.test(Temp) # Prueba de normalidad de temperatura
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: Temp
## D = 0.091227, p-value = 0.02385
cor(x=Ozone, y=Temp, method = "pearson") # No aplica porque las variables no poseen normalidad
## [1] 0.6985414
cor(x=Ozone, y=Temp, method = "spearman") # Si aplica, Veamos cuál es la correlación
## [1] 0.7729319
# los intervalos de confianza De la correlación
Pearson <- cor_test(Datos, "Ozone", "Temp", method = "pearson"); Pearson
## Parameter1 | Parameter2 | r | 95% CI | t(109) | p
## ------------------------------------------------------------------
## Ozone | Temp | 0.70 | [0.59, 0.78] | 10.19 | < .001***
##
## Observations: 111
spearman <- cor_test(Datos, "Ozone", "Temp", method = "spearman"); spearman
## Parameter1 | Parameter2 | rho | 95% CI | S | p
## --------------------------------------------------------------------
## Ozone | Temp | 0.77 | [0.68, 0.84] | 51753.35 | < .001***
##
## Observations: 111
#la correlación de todas las variables
correlation(Datos, method = "spearman")
## # Correlation Matrix (spearman-method)
##
## Parameter1 | Parameter2 | rho | 95% CI | S | p
## -----------------------------------------------------------------------
## Ozone | Solar.R | 0.35 | [ 0.17, 0.51] | 1.49e+05 | 0.002**
## Ozone | Wind | -0.61 | [-0.71, -0.47] | 3.66e+05 | < .001***
## Ozone | Temp | 0.77 | [ 0.68, 0.84] | 51753.35 | < .001***
## Ozone | Month | 0.12 | [-0.08, 0.30] | 2.01e+05 | > .999
## Ozone | Day | -0.04 | [-0.23, 0.16] | 2.36e+05 | > .999
## Solar.R | Wind | -0.06 | [-0.25, 0.13] | 2.42e+05 | > .999
## Solar.R | Temp | 0.21 | [ 0.02, 0.39] | 1.80e+05 | 0.273
## Solar.R | Month | -0.15 | [-0.33, 0.04] | 2.62e+05 | > .999
## Solar.R | Day | -0.07 | [-0.25, 0.13] | 2.43e+05 | > .999
## Wind | Temp | -0.50 | [-0.63, -0.34] | 3.42e+05 | < .001***
## Wind | Month | -0.14 | [-0.33, 0.05] | 2.61e+05 | > .999
## Wind | Day | 0.05 | [-0.14, 0.24] | 2.16e+05 | > .999
## Temp | Month | 0.29 | [ 0.10, 0.46] | 1.62e+05 | 0.023*
## Temp | Day | -0.13 | [-0.31, 0.07] | 2.57e+05 | > .999
## Month | Day | -0.01 | [-0.20, 0.18] | 2.31e+05 | > .999
##
## p-value adjustment method: Holm (1979)
## Observations: 111
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Transformación Box Cox #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Para normalizar la variable Ozono
lillie.test(Ozone) # Prueba de normalidad de ozono
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: Ozone
## D = 0.15078, p-value = 1.613e-06
hist(Ozone, col = 4)
Lamba<-car::powerTransform(Ozone, family="bcPower") #Buscamos Lamba
# str(Lamba)
Lamba$ start
## [1] 0.1939681
Datos$Ozone_Box<-Ozone^Lamba$ start
View(Datos)
attach(Datos)
shapiro.test(Ozone_Box) # Prueba de normalidad si no es un dataframe
##
## Shapiro-Wilk normality test
##
## data: Ozone_Box
## W = 0.9861, p-value = 0.3078
hist(Ozone_Box, col = 3)
# Para normalizar la variable Temperatura
lillie.test(Temp) # Prueba de normalidad de Temp
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: Temp
## D = 0.091227, p-value = 0.02385
hist(Temp, col = 4)
Lamba<-car::powerTransform(Temp, family="bcPower") #Buscamos Lamba
# str(Lamba)
Lamba$ start
## [1] 1.71955
Datos$Temp_Box<-Temp^Lamba$ start
View(Datos)
attach(Datos)
shapiro.test(Temp_Box) # Prueba de normalidad si no es un dataframe
##
## Shapiro-Wilk normality test
##
## data: Temp_Box
## W = 0.98373, p-value = 0.1966
hist(Temp_Box, col = 3)
# Como las dos variables ya están normalizadas ahora sí ya podemos aplicar
# el corriente de correlación de pearson
Pearson <- cor_test(Datos, "Ozone_Box", "Temp_Box", method = "pearson"); Pearson # Sin normalidad
## Parameter1 | Parameter2 | r | 95% CI | t(109) | p
## ------------------------------------------------------------------
## Ozone_Box | Temp_Box | 0.76 | [0.67, 0.83] | 12.19 | < .001***
##
## Observations: 111
Pearson <- cor_test(Datos, "Ozone", "Temp", method = "pearson"); Pearson # Sin normalidad
## Parameter1 | Parameter2 | r | 95% CI | t(109) | p
## ------------------------------------------------------------------
## Ozone | Temp | 0.70 | [0.59, 0.78] | 10.19 | < .001***
##
## Observations: 111
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Bootstrap de correlación #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Datos$x<-Ozone_Box
Datos$y<-Temp_Box
Mi_corr<-cor.test(Ozone_Box, Temp_Box) # Ya esta nornalizada, por eso usamos Pearso
Mi_corr$ estimate #Aqui vemos el valor de r
## cor
## 0.7594418
set.seed(1)
Boots_r <- boot(Datos,
statistic = function(Datos, i) {
cor(Datos[i, "x"], Datos[i, "y"], method='spearman')
},
R = 1000
)
Boots_r
##
## ORDINARY NONPARAMETRIC BOOTSTRAP
##
##
## Call:
## boot(data = Datos, statistic = function(Datos, i) {
## cor(Datos[i, "x"], Datos[i, "y"], method = "spearman")
## }, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 0.7729319 -0.00389629 0.04193582
boot.ci(Boots_r, type = c("norm", "basic", "perc", "bca")) #bootstrapped CI.
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = Boots_r, type = c("norm", "basic", "perc",
## "bca"))
##
## Intervals :
## Level Normal Basic
## 95% ( 0.6946, 0.8590 ) ( 0.7049, 0.8711 )
##
## Level Percentile BCa
## 95% ( 0.6747, 0.8409 ) ( 0.6737, 0.8403 )
## Calculations and Intervals on Original Scale
plot(density(Boots_r$t))
abline(v = Mi_corr$ estimate, lty = "dashed", col = "red") # Traemos el velor desde la corr
Boots_r$t # veamos todos los resutados del bootstrapped
## [,1]
## [1,] 0.7504443
## [2,] 0.7825407
## [3,] 0.6936637
## [4,] 0.7352739
## [5,] 0.7457317
## [6,] 0.7840804
## [7,] 0.7563571
## [8,] 0.7797615
## [9,] 0.7981870
## [10,] 0.7668597
## [11,] 0.7597518
## [12,] 0.7536712
## [13,] 0.7958243
## [14,] 0.8096847
## [15,] 0.8117490
## [16,] 0.7442360
## [17,] 0.7317992
## [18,] 0.7962787
## [19,] 0.7497422
## [20,] 0.7727595
## [21,] 0.7161866
## [22,] 0.7541352
## [23,] 0.7921842
## [24,] 0.7293340
## [25,] 0.7199527
## [26,] 0.7570115
## [27,] 0.7827157
## [28,] 0.7731406
## [29,] 0.7678811
## [30,] 0.7033064
## [31,] 0.7765701
## [32,] 0.8028958
## [33,] 0.7641299
## [34,] 0.8170222
## [35,] 0.7080595
## [36,] 0.7607327
## [37,] 0.8277482
## [38,] 0.8039743
## [39,] 0.7971573
## [40,] 0.7992766
## [41,] 0.7139693
## [42,] 0.7414802
## [43,] 0.7872427
## [44,] 0.7529914
## [45,] 0.8146750
## [46,] 0.7381367
## [47,] 0.8136124
## [48,] 0.7116272
## [49,] 0.7757068
## [50,] 0.7384781
## [51,] 0.8202385
## [52,] 0.7733346
## [53,] 0.7521256
## [54,] 0.7625206
## [55,] 0.7428254
## [56,] 0.7649883
## [57,] 0.7934615
## [58,] 0.7507808
## [59,] 0.7778823
## [60,] 0.8047978
## [61,] 0.7031305
## [62,] 0.8284056
## [63,] 0.8172304
## [64,] 0.8216820
## [65,] 0.7618516
## [66,] 0.7521220
## [67,] 0.7657429
## [68,] 0.8076007
## [69,] 0.7358502
## [70,] 0.8271263
## [71,] 0.7296241
## [72,] 0.7800890
## [73,] 0.7667621
## [74,] 0.6986336
## [75,] 0.6514824
## [76,] 0.7895725
## [77,] 0.7816423
## [78,] 0.7290915
## [79,] 0.7819006
## [80,] 0.7834234
## [81,] 0.8069805
## [82,] 0.8245636
## [83,] 0.7869774
## [84,] 0.7737169
## [85,] 0.7481086
## [86,] 0.7380294
## [87,] 0.7123535
## [88,] 0.7655311
## [89,] 0.7845331
## [90,] 0.7361369
## [91,] 0.6436829
## [92,] 0.7609757
## [93,] 0.7377320
## [94,] 0.8062005
## [95,] 0.7624233
## [96,] 0.8144336
## [97,] 0.7473036
## [98,] 0.7956363
## [99,] 0.7725580
## [100,] 0.8146094
## [101,] 0.7587925
## [102,] 0.8124619
## [103,] 0.7044645
## [104,] 0.8116471
## [105,] 0.7858906
## [106,] 0.7045222
## [107,] 0.7587327
## [108,] 0.8177428
## [109,] 0.8186894
## [110,] 0.7391313
## [111,] 0.7272518
## [112,] 0.8213637
## [113,] 0.7794572
## [114,] 0.7651476
## [115,] 0.8235866
## [116,] 0.7365236
## [117,] 0.8307472
## [118,] 0.7537594
## [119,] 0.7247890
## [120,] 0.7764398
## [121,] 0.7998664
## [122,] 0.8298155
## [123,] 0.7480571
## [124,] 0.7204805
## [125,] 0.7226845
## [126,] 0.7985440
## [127,] 0.8418586
## [128,] 0.6606137
## [129,] 0.8160382
## [130,] 0.7687680
## [131,] 0.7388208
## [132,] 0.7560644
## [133,] 0.7637930
## [134,] 0.7705623
## [135,] 0.8291550
## [136,] 0.7831212
## [137,] 0.7833273
## [138,] 0.7706348
## [139,] 0.8103725
## [140,] 0.8115284
## [141,] 0.7531920
## [142,] 0.7549129
## [143,] 0.7369482
## [144,] 0.7914844
## [145,] 0.7565929
## [146,] 0.8130914
## [147,] 0.7590076
## [148,] 0.8264174
## [149,] 0.7822365
## [150,] 0.5976209
## [151,] 0.7322056
## [152,] 0.8035840
## [153,] 0.7845556
## [154,] 0.7908215
## [155,] 0.7077621
## [156,] 0.8240251
## [157,] 0.8481958
## [158,] 0.8188019
## [159,] 0.7109694
## [160,] 0.8238716
## [161,] 0.7847185
## [162,] 0.7452501
## [163,] 0.7280291
## [164,] 0.7536881
## [165,] 0.8108296
## [166,] 0.7476095
## [167,] 0.6986699
## [168,] 0.7833445
## [169,] 0.7179648
## [170,] 0.7986699
## [171,] 0.7640795
## [172,] 0.8048578
## [173,] 0.8335492
## [174,] 0.7942709
## [175,] 0.8052977
## [176,] 0.8184222
## [177,] 0.7984091
## [178,] 0.7716773
## [179,] 0.7691026
## [180,] 0.7351641
## [181,] 0.7563384
## [182,] 0.7837902
## [183,] 0.7379676
## [184,] 0.7079301
## [185,] 0.8062511
## [186,] 0.7823523
## [187,] 0.6194004
## [188,] 0.7364788
## [189,] 0.7896190
## [190,] 0.7558631
## [191,] 0.8055986
## [192,] 0.7852870
## [193,] 0.8409713
## [194,] 0.6922658
## [195,] 0.8462076
## [196,] 0.7122378
## [197,] 0.7670763
## [198,] 0.8365028
## [199,] 0.7786752
## [200,] 0.7308653
## [201,] 0.7648389
## [202,] 0.7297606
## [203,] 0.7401403
## [204,] 0.6802126
## [205,] 0.8527528
## [206,] 0.7882087
## [207,] 0.8219031
## [208,] 0.6945144
## [209,] 0.7800232
## [210,] 0.8078301
## [211,] 0.7537649
## [212,] 0.6957656
## [213,] 0.7555185
## [214,] 0.7104252
## [215,] 0.6228359
## [216,] 0.7220510
## [217,] 0.7566249
## [218,] 0.6693541
## [219,] 0.7569310
## [220,] 0.8066995
## [221,] 0.7310744
## [222,] 0.7583179
## [223,] 0.7895094
## [224,] 0.7928944
## [225,] 0.7373057
## [226,] 0.7688070
## [227,] 0.7543336
## [228,] 0.7086056
## [229,] 0.7163937
## [230,] 0.7397186
## [231,] 0.8037680
## [232,] 0.7917740
## [233,] 0.6684132
## [234,] 0.8128970
## [235,] 0.6942458
## [236,] 0.8304946
## [237,] 0.7211470
## [238,] 0.7907934
## [239,] 0.7875471
## [240,] 0.7969001
## [241,] 0.6875090
## [242,] 0.6788944
## [243,] 0.7339340
## [244,] 0.7908392
## [245,] 0.7631679
## [246,] 0.8027555
## [247,] 0.7185654
## [248,] 0.8104158
## [249,] 0.8057027
## [250,] 0.7454804
## [251,] 0.7051756
## [252,] 0.7920921
## [253,] 0.7300813
## [254,] 0.7717555
## [255,] 0.7899655
## [256,] 0.6624299
## [257,] 0.7338266
## [258,] 0.8248670
## [259,] 0.7899717
## [260,] 0.7776740
## [261,] 0.8037627
## [262,] 0.7526824
## [263,] 0.6927231
## [264,] 0.8047297
## [265,] 0.8018079
## [266,] 0.7474998
## [267,] 0.7421803
## [268,] 0.7963208
## [269,] 0.7663157
## [270,] 0.6951989
## [271,] 0.8035209
## [272,] 0.8230196
## [273,] 0.8050023
## [274,] 0.8001815
## [275,] 0.7516770
## [276,] 0.7808083
## [277,] 0.8151885
## [278,] 0.7585385
## [279,] 0.8330770
## [280,] 0.7537860
## [281,] 0.7800218
## [282,] 0.7487472
## [283,] 0.7998036
## [284,] 0.7755717
## [285,] 0.7198911
## [286,] 0.6942316
## [287,] 0.7259453
## [288,] 0.7688714
## [289,] 0.7695955
## [290,] 0.8685161
## [291,] 0.7833062
## [292,] 0.7684965
## [293,] 0.7541138
## [294,] 0.6758153
## [295,] 0.8126940
## [296,] 0.8164365
## [297,] 0.7832363
## [298,] 0.7984359
## [299,] 0.8030385
## [300,] 0.6874805
## [301,] 0.8398551
## [302,] 0.7945134
## [303,] 0.7803735
## [304,] 0.7736979
## [305,] 0.7252739
## [306,] 0.6476420
## [307,] 0.7936986
## [308,] 0.8126097
## [309,] 0.7895555
## [310,] 0.8335703
## [311,] 0.7202178
## [312,] 0.7984038
## [313,] 0.7260974
## [314,] 0.7572504
## [315,] 0.7456472
## [316,] 0.7605083
## [317,] 0.8033837
## [318,] 0.8462624
## [319,] 0.8019652
## [320,] 0.7570473
## [321,] 0.7736197
## [322,] 0.7441808
## [323,] 0.8034983
## [324,] 0.7845772
## [325,] 0.7895113
## [326,] 0.7235672
## [327,] 0.8093035
## [328,] 0.7782869
## [329,] 0.7776528
## [330,] 0.7528555
## [331,] 0.7640800
## [332,] 0.7821191
## [333,] 0.8191388
## [334,] 0.7732161
## [335,] 0.7225317
## [336,] 0.7586461
## [337,] 0.7330903
## [338,] 0.8183675
## [339,] 0.7425095
## [340,] 0.8187667
## [341,] 0.7416164
## [342,] 0.7634792
## [343,] 0.8051996
## [344,] 0.7733665
## [345,] 0.7459212
## [346,] 0.7742245
## [347,] 0.7654092
## [348,] 0.7247891
## [349,] 0.8390842
## [350,] 0.8468425
## [351,] 0.7580197
## [352,] 0.7929623
## [353,] 0.7647560
## [354,] 0.7989969
## [355,] 0.7622016
## [356,] 0.7174496
## [357,] 0.7976861
## [358,] 0.8063773
## [359,] 0.7976497
## [360,] 0.7593184
## [361,] 0.8267111
## [362,] 0.8383339
## [363,] 0.8092883
## [364,] 0.7727098
## [365,] 0.7493431
## [366,] 0.8514968
## [367,] 0.7401824
## [368,] 0.7959581
## [369,] 0.7805639
## [370,] 0.6714214
## [371,] 0.8170186
## [372,] 0.8156412
## [373,] 0.7493934
## [374,] 0.6995779
## [375,] 0.7757985
## [376,] 0.7629428
## [377,] 0.8219827
## [378,] 0.6886512
## [379,] 0.7067398
## [380,] 0.7759824
## [381,] 0.8008064
## [382,] 0.7896261
## [383,] 0.8425553
## [384,] 0.7259623
## [385,] 0.7876092
## [386,] 0.7625330
## [387,] 0.7758447
## [388,] 0.8013041
## [389,] 0.8624654
## [390,] 0.7214117
## [391,] 0.8371018
## [392,] 0.7192025
## [393,] 0.7188587
## [394,] 0.8109724
## [395,] 0.8416099
## [396,] 0.7992978
## [397,] 0.7888047
## [398,] 0.7700773
## [399,] 0.7372170
## [400,] 0.7688462
## [401,] 0.8019131
## [402,] 0.7988217
## [403,] 0.7941993
## [404,] 0.7487063
## [405,] 0.7464199
## [406,] 0.7167001
## [407,] 0.8166334
## [408,] 0.7432586
## [409,] 0.8117695
## [410,] 0.7176925
## [411,] 0.7909379
## [412,] 0.7782717
## [413,] 0.7464791
## [414,] 0.7137018
## [415,] 0.7071115
## [416,] 0.8284794
## [417,] 0.8587147
## [418,] 0.7661606
## [419,] 0.8096756
## [420,] 0.7153386
## [421,] 0.7816414
## [422,] 0.7538805
## [423,] 0.7807874
## [424,] 0.8064231
## [425,] 0.8556893
## [426,] 0.7830777
## [427,] 0.7160370
## [428,] 0.6682117
## [429,] 0.7792912
## [430,] 0.8033018
## [431,] 0.7964298
## [432,] 0.7398188
## [433,] 0.7687210
## [434,] 0.7862191
## [435,] 0.8143826
## [436,] 0.7347005
## [437,] 0.7576069
## [438,] 0.7945946
## [439,] 0.8018406
## [440,] 0.7249048
## [441,] 0.7847866
## [442,] 0.7801972
## [443,] 0.7076938
## [444,] 0.7703959
## [445,] 0.7818558
## [446,] 0.7800213
## [447,] 0.7841655
## [448,] 0.7513959
## [449,] 0.8251719
## [450,] 0.7613223
## [451,] 0.7137651
## [452,] 0.6660559
## [453,] 0.8018420
## [454,] 0.7982977
## [455,] 0.7690792
## [456,] 0.7354152
## [457,] 0.7825618
## [458,] 0.7843583
## [459,] 0.8357261
## [460,] 0.7975477
## [461,] 0.7330343
## [462,] 0.7819311
## [463,] 0.6958712
## [464,] 0.7466915
## [465,] 0.8113695
## [466,] 0.7593167
## [467,] 0.7838888
## [468,] 0.7570242
## [469,] 0.7741044
## [470,] 0.7715559
## [471,] 0.7595195
## [472,] 0.7964439
## [473,] 0.7382857
## [474,] 0.7853410
## [475,] 0.6877004
## [476,] 0.6988162
## [477,] 0.7502670
## [478,] 0.7904666
## [479,] 0.8219774
## [480,] 0.8141578
## [481,] 0.7940673
## [482,] 0.7442244
## [483,] 0.6728200
## [484,] 0.8056598
## [485,] 0.7591714
## [486,] 0.7554769
## [487,] 0.7705509
## [488,] 0.7994068
## [489,] 0.7606032
## [490,] 0.7330374
## [491,] 0.8291334
## [492,] 0.8024012
## [493,] 0.7702114
## [494,] 0.8220161
## [495,] 0.8439924
## [496,] 0.8177713
## [497,] 0.7813975
## [498,] 0.7703662
## [499,] 0.7684475
## [500,] 0.7187256
## [501,] 0.7730649
## [502,] 0.7291294
## [503,] 0.8126540
## [504,] 0.7173467
## [505,] 0.7964098
## [506,] 0.7482305
## [507,] 0.7362263
## [508,] 0.7758429
## [509,] 0.7452700
## [510,] 0.6977789
## [511,] 0.7758990
## [512,] 0.7845665
## [513,] 0.8046450
## [514,] 0.7506197
## [515,] 0.7346970
## [516,] 0.7653341
## [517,] 0.7929239
## [518,] 0.7745340
## [519,] 0.7669023
## [520,] 0.6957767
## [521,] 0.8071881
## [522,] 0.7335009
## [523,] 0.7595172
## [524,] 0.7962666
## [525,] 0.7828124
## [526,] 0.7343587
## [527,] 0.7486721
## [528,] 0.7350132
## [529,] 0.7496612
## [530,] 0.7390327
## [531,] 0.7075037
## [532,] 0.7400987
## [533,] 0.7827728
## [534,] 0.8380846
## [535,] 0.7303049
## [536,] 0.7868922
## [537,] 0.7997370
## [538,] 0.7562958
## [539,] 0.8160453
## [540,] 0.7488048
## [541,] 0.6078694
## [542,] 0.8170169
## [543,] 0.7322220
## [544,] 0.7593951
## [545,] 0.8192066
## [546,] 0.7604051
## [547,] 0.7481113
## [548,] 0.8008771
## [549,] 0.7404567
## [550,] 0.7896740
## [551,] 0.7413702
## [552,] 0.7662351
## [553,] 0.8041669
## [554,] 0.7647975
## [555,] 0.7338923
## [556,] 0.7464226
## [557,] 0.7662267
## [558,] 0.7504209
## [559,] 0.8043889
## [560,] 0.7468746
## [561,] 0.7979849
## [562,] 0.8087749
## [563,] 0.7682303
## [564,] 0.7386587
## [565,] 0.7889468
## [566,] 0.7396760
## [567,] 0.7747345
## [568,] 0.8149938
## [569,] 0.7604249
## [570,] 0.7810590
## [571,] 0.7596636
## [572,] 0.7977519
## [573,] 0.7707818
## [574,] 0.7747155
## [575,] 0.6924483
## [576,] 0.8137045
## [577,] 0.7737202
## [578,] 0.7860648
## [579,] 0.7962085
## [580,] 0.6961545
## [581,] 0.7601565
## [582,] 0.7357934
## [583,] 0.7688503
## [584,] 0.7408010
## [585,] 0.7302518
## [586,] 0.7287986
## [587,] 0.8345674
## [588,] 0.7774768
## [589,] 0.7276275
## [590,] 0.7277654
## [591,] 0.7999225
## [592,] 0.8436653
## [593,] 0.7117152
## [594,] 0.8040848
## [595,] 0.7389168
## [596,] 0.7479724
## [597,] 0.7237173
## [598,] 0.8397176
## [599,] 0.8037225
## [600,] 0.7983241
## [601,] 0.7960147
## [602,] 0.8135492
## [603,] 0.8083468
## [604,] 0.7581830
## [605,] 0.7624443
## [606,] 0.7620555
## [607,] 0.7337473
## [608,] 0.7005311
## [609,] 0.8023180
## [610,] 0.8258986
## [611,] 0.7426456
## [612,] 0.7929873
## [613,] 0.7757843
## [614,] 0.7778721
## [615,] 0.7670997
## [616,] 0.7906982
## [617,] 0.7853793
## [618,] 0.8510670
## [619,] 0.7907889
## [620,] 0.7660179
## [621,] 0.7024981
## [622,] 0.6603410
## [623,] 0.7991147
## [624,] 0.7891184
## [625,] 0.8032600
## [626,] 0.6961621
## [627,] 0.8168544
## [628,] 0.7703858
## [629,] 0.7449243
## [630,] 0.8274593
## [631,] 0.7594417
## [632,] 0.7549419
## [633,] 0.7508112
## [634,] 0.7566418
## [635,] 0.8299263
## [636,] 0.7249267
## [637,] 0.7824272
## [638,] 0.7700263
## [639,] 0.7830972
## [640,] 0.6798766
## [641,] 0.7531753
## [642,] 0.7555513
## [643,] 0.8414782
## [644,] 0.8157913
## [645,] 0.7158792
## [646,] 0.7550453
## [647,] 0.8415832
## [648,] 0.7456497
## [649,] 0.7728465
## [650,] 0.6917783
## [651,] 0.6762405
## [652,] 0.7769389
## [653,] 0.8056482
## [654,] 0.7508803
## [655,] 0.7849138
## [656,] 0.7589054
## [657,] 0.8225805
## [658,] 0.7643676
## [659,] 0.7573946
## [660,] 0.7872029
## [661,] 0.6923857
## [662,] 0.7254570
## [663,] 0.8027656
## [664,] 0.7780651
## [665,] 0.8181070
## [666,] 0.8041927
## [667,] 0.7739025
## [668,] 0.7750670
## [669,] 0.7912549
## [670,] 0.7838754
## [671,] 0.7331865
## [672,] 0.7887761
## [673,] 0.7685926
## [674,] 0.7115136
## [675,] 0.8388722
## [676,] 0.7705329
## [677,] 0.7508535
## [678,] 0.7501600
## [679,] 0.7642937
## [680,] 0.7246702
## [681,] 0.7849026
## [682,] 0.7653643
## [683,] 0.7915928
## [684,] 0.7979974
## [685,] 0.8582843
## [686,] 0.6632881
## [687,] 0.8388115
## [688,] 0.7982346
## [689,] 0.7390075
## [690,] 0.7310268
## [691,] 0.8311623
## [692,] 0.7183842
## [693,] 0.8188349
## [694,] 0.8200287
## [695,] 0.7827278
## [696,] 0.7511852
## [697,] 0.7693632
## [698,] 0.8478486
## [699,] 0.8102120
## [700,] 0.7848155
## [701,] 0.7876079
## [702,] 0.7002339
## [703,] 0.8338877
## [704,] 0.7539843
## [705,] 0.7472699
## [706,] 0.7364006
## [707,] 0.8001027
## [708,] 0.8059584
## [709,] 0.7728276
## [710,] 0.7917346
## [711,] 0.8192178
## [712,] 0.7556311
## [713,] 0.6341440
## [714,] 0.7046806
## [715,] 0.8005657
## [716,] 0.7939409
## [717,] 0.7043061
## [718,] 0.7967925
## [719,] 0.7849558
## [720,] 0.7368747
## [721,] 0.6853585
## [722,] 0.7887038
## [723,] 0.7277899
## [724,] 0.6462884
## [725,] 0.7627380
## [726,] 0.8070595
## [727,] 0.7549838
## [728,] 0.7881740
## [729,] 0.7352406
## [730,] 0.7622944
## [731,] 0.8105390
## [732,] 0.7318608
## [733,] 0.7463958
## [734,] 0.6839870
## [735,] 0.7656572
## [736,] 0.8190897
## [737,] 0.7569682
## [738,] 0.7636416
## [739,] 0.7973052
## [740,] 0.7660217
## [741,] 0.7959121
## [742,] 0.7111165
## [743,] 0.7696002
## [744,] 0.7837536
## [745,] 0.8104419
## [746,] 0.7812831
## [747,] 0.7946912
## [748,] 0.7312007
## [749,] 0.7558822
## [750,] 0.7900255
## [751,] 0.7794932
## [752,] 0.7840707
## [753,] 0.7024126
## [754,] 0.7259580
## [755,] 0.7155564
## [756,] 0.7036278
## [757,] 0.7567558
## [758,] 0.7873145
## [759,] 0.7319864
## [760,] 0.7769191
## [761,] 0.7425193
## [762,] 0.7975393
## [763,] 0.7486648
## [764,] 0.7590594
## [765,] 0.8114664
## [766,] 0.8047748
## [767,] 0.7627614
## [768,] 0.7966470
## [769,] 0.7025398
## [770,] 0.8309705
## [771,] 0.8127467
## [772,] 0.7966622
## [773,] 0.8023483
## [774,] 0.7514151
## [775,] 0.7698688
## [776,] 0.7819430
## [777,] 0.8043219
## [778,] 0.7534199
## [779,] 0.7761343
## [780,] 0.7839162
## [781,] 0.8043954
## [782,] 0.8143395
## [783,] 0.7836668
## [784,] 0.7587452
## [785,] 0.7381931
## [786,] 0.7974848
## [787,] 0.7938323
## [788,] 0.7591288
## [789,] 0.7716959
## [790,] 0.7267543
## [791,] 0.7264394
## [792,] 0.7625484
## [793,] 0.7793600
## [794,] 0.8012350
## [795,] 0.7474099
## [796,] 0.7844522
## [797,] 0.7963042
## [798,] 0.6787868
## [799,] 0.8190935
## [800,] 0.7388241
## [801,] 0.7128642
## [802,] 0.8094448
## [803,] 0.8273935
## [804,] 0.7604597
## [805,] 0.8187373
## [806,] 0.7934486
## [807,] 0.7897326
## [808,] 0.7991690
## [809,] 0.7248894
## [810,] 0.7877372
## [811,] 0.7479461
## [812,] 0.7793133
## [813,] 0.7380858
## [814,] 0.8354034
## [815,] 0.7656413
## [816,] 0.7340784
## [817,] 0.7717127
## [818,] 0.8215236
## [819,] 0.7658795
## [820,] 0.8104377
## [821,] 0.8230628
## [822,] 0.7583523
## [823,] 0.7580441
## [824,] 0.7866344
## [825,] 0.7904925
## [826,] 0.7146936
## [827,] 0.8037913
## [828,] 0.8122526
## [829,] 0.8134371
## [830,] 0.8102231
## [831,] 0.8103950
## [832,] 0.7688940
## [833,] 0.7977675
## [834,] 0.7438145
## [835,] 0.7079750
## [836,] 0.8361084
## [837,] 0.7714664
## [838,] 0.7723865
## [839,] 0.7996582
## [840,] 0.8004639
## [841,] 0.7892107
## [842,] 0.8507331
## [843,] 0.8108442
## [844,] 0.7250581
## [845,] 0.7303858
## [846,] 0.6479292
## [847,] 0.7656500
## [848,] 0.7380369
## [849,] 0.7776095
## [850,] 0.7196578
## [851,] 0.7601226
## [852,] 0.8074679
## [853,] 0.7607350
## [854,] 0.6950244
## [855,] 0.7709076
## [856,] 0.8143277
## [857,] 0.7719020
## [858,] 0.6956912
## [859,] 0.7466039
## [860,] 0.8285914
## [861,] 0.7476279
## [862,] 0.7483349
## [863,] 0.7666397
## [864,] 0.7898873
## [865,] 0.7170940
## [866,] 0.7855637
## [867,] 0.7405154
## [868,] 0.7683197
## [869,] 0.8044616
## [870,] 0.6748977
## [871,] 0.8191757
## [872,] 0.7624882
## [873,] 0.7341071
## [874,] 0.7673428
## [875,] 0.7910063
## [876,] 0.7925454
## [877,] 0.6586554
## [878,] 0.7670690
## [879,] 0.6965690
## [880,] 0.7494534
## [881,] 0.7309593
## [882,] 0.7932460
## [883,] 0.7804388
## [884,] 0.8079145
## [885,] 0.7815069
## [886,] 0.7819009
## [887,] 0.7493172
## [888,] 0.7160065
## [889,] 0.6747313
## [890,] 0.7400255
## [891,] 0.8211610
## [892,] 0.7807173
## [893,] 0.8116285
## [894,] 0.7870051
## [895,] 0.8103354
## [896,] 0.8297033
## [897,] 0.7908742
## [898,] 0.7357885
## [899,] 0.7707551
## [900,] 0.8374146
## [901,] 0.7706299
## [902,] 0.8634520
## [903,] 0.7536864
## [904,] 0.8184911
## [905,] 0.7441827
## [906,] 0.7292565
## [907,] 0.6725730
## [908,] 0.7494242
## [909,] 0.7861376
## [910,] 0.8394112
## [911,] 0.8021834
## [912,] 0.7804688
## [913,] 0.7692567
## [914,] 0.7587963
## [915,] 0.8112389
## [916,] 0.7438334
## [917,] 0.7353263
## [918,] 0.7805511
## [919,] 0.7665794
## [920,] 0.6497585
## [921,] 0.8175309
## [922,] 0.8199754
## [923,] 0.7881377
## [924,] 0.7585238
## [925,] 0.8096554
## [926,] 0.7486866
## [927,] 0.8318543
## [928,] 0.7453745
## [929,] 0.7654602
## [930,] 0.7864444
## [931,] 0.7619705
## [932,] 0.7824512
## [933,] 0.7950875
## [934,] 0.7661413
## [935,] 0.7376850
## [936,] 0.7917514
## [937,] 0.7947865
## [938,] 0.7727472
## [939,] 0.8284176
## [940,] 0.8731886
## [941,] 0.7365821
## [942,] 0.7870439
## [943,] 0.7658247
## [944,] 0.7376975
## [945,] 0.7440765
## [946,] 0.6873182
## [947,] 0.7547387
## [948,] 0.7687756
## [949,] 0.8351256
## [950,] 0.7797445
## [951,] 0.7545330
## [952,] 0.7986597
## [953,] 0.8047628
## [954,] 0.7489161
## [955,] 0.7589485
## [956,] 0.7724806
## [957,] 0.7823334
## [958,] 0.8568781
## [959,] 0.7833293
## [960,] 0.7264851
## [961,] 0.7813733
## [962,] 0.7940398
## [963,] 0.7975860
## [964,] 0.7498381
## [965,] 0.7718703
## [966,] 0.8051130
## [967,] 0.7180853
## [968,] 0.7702042
## [969,] 0.8069261
## [970,] 0.7771842
## [971,] 0.7846445
## [972,] 0.7969909
## [973,] 0.7006254
## [974,] 0.8309466
## [975,] 0.8028860
## [976,] 0.8068805
## [977,] 0.7205433
## [978,] 0.7726099
## [979,] 0.7994979
## [980,] 0.7619772
## [981,] 0.7282084
## [982,] 0.8292161
## [983,] 0.7884996
## [984,] 0.8142736
## [985,] 0.7493390
## [986,] 0.7449802
## [987,] 0.7065467
## [988,] 0.7844928
## [989,] 0.7714304
## [990,] 0.7701340
## [991,] 0.6867391
## [992,] 0.7996358
## [993,] 0.6351320
## [994,] 0.7069170
## [995,] 0.7933563
## [996,] 0.8192812
## [997,] 0.7715237
## [998,] 0.7383316
## [999,] 0.7518149
## [1000,] 0.7882346
hist(Boots_r$t, col= 7)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Bonitas figurass de correlacion #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
head(Datos) # Los encabezados de los datos
## Ozone Solar.R Wind Temp Month Day Ozone_Box Temp_Box x y
## 1 41 190 7.4 67 5 1 2.055080 1380.471 2.055080 1380.471
## 2 36 118 8.0 72 5 2 2.003886 1562.344 2.003886 1562.344
## 3 12 149 12.6 74 5 3 1.619298 1637.713 1.619298 1637.713
## 4 18 313 11.5 62 5 4 1.751793 1208.113 1.751793 1208.113
## 5 23 299 8.6 65 5 7 1.837096 1310.375 1.837096 1310.375
## 6 19 99 13.8 59 5 8 1.770261 1109.351 1.770261 1109.351
M<-cor(Datos) # Correlación entre todas las variables
head(round(M,2)) # Correlacion de lass variables
## Ozone Solar.R Wind Temp Month Day Ozone_Box Temp_Box x y
## Ozone 1.00 0.35 -0.61 0.70 0.14 -0.01 0.94 0.71 0.94 0.71
## Solar.R 0.35 1.00 -0.13 0.29 -0.07 -0.06 0.44 0.29 0.44 0.29
## Wind -0.61 -0.13 1.00 -0.50 -0.19 0.05 -0.59 -0.50 -0.59 -0.50
## Temp 0.70 0.29 -0.50 1.00 0.40 -0.10 0.75 1.00 0.75 1.00
## Month 0.14 -0.07 -0.19 0.40 1.00 -0.01 0.18 0.39 0.18 0.39
## Day -0.01 -0.06 0.05 -0.10 -0.01 1.00 -0.03 -0.10 -0.03 -0.10
corrplot(M, method="circle") # Plot de correlacion
corrplot(M, method="color") # Plot de correlacion
corrplot(M, method="number") # Plot de correlacion
Otra_Corr=cor(Datos)
qgraph(Otra_Corr, shape="circle", posCol="darkgreen", negCol="darkred",
layout="spring", vsize=10)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Detección y remocion de outlayers #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
boxplot(Variable) # Box plot de la variable
nueva.var <- Variable[!Variable %in% boxplot.stats(Variable)$out] # Remove outliers
boxplot(nueva.var) # Box plot de la variable sin outliers