Cargando los datos de ejemplo

knitr::opts_chunk$set(echo = TRUE)
setwd("G:/UAAAN/MATERIAS/2019/REGRESION APLICADA/DATOS")
library(corrplot)
## corrplot 0.84 loaded
library(ecospat)
## Loading required package: ade4
## Loading required package: ape
## Loading required package: gbm
## Loaded gbm 2.1.5
## Loading required package: sp
library(ggplot2)
library(ggpubr)
## Loading required package: magrittr
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:ape':
## 
##     rotate
library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:ape':
## 
##     zoom
## The following objects are masked from 'package:base':
## 
##     format.pval, units
mis_datos<-read.csv("Pinus_halepensis.csv", header = T)  #entre comillas es el archivo a abrir
head(mis_datos)
##   ID    DB     H    DC   VT     BH     BF      BT   PBH   PBF
## 1  1 55.40 10.60  8.78 0.82 201.30 518.43  719.73 27.97 72.03
## 2  2 54.30 11.10  8.00 0.86 166.56 498.91  665.47 25.03 74.97
## 3  3 30.20  7.20  5.50 0.14  72.19  82.52  154.71 46.66 53.34
## 4  4 57.50  9.57  8.50 0.60 191.30 348.40  539.70 35.45 64.55
## 5  5 39.30  8.60  8.90 0.34  70.60 212.33  282.93 24.95 75.05
## 6  6 75.45 12.99 12.30 1.34 487.67 864.70 1352.37 36.06 63.94
attach(mis_datos) #este es muy importante

Calculo de las estadísticas básicas

library("pastecs")
## 
## Attaching package: 'pastecs'
## The following object is masked from 'package:magrittr':
## 
##     extract
round(stat.desc(mis_datos [2:9]), digits = 2) 
##                   DB      H     DC    VT      BH       BF       BT     PBH
## nbr.val        40.00  40.00  40.00 40.00   40.00    40.00    40.00   40.00
## nbr.null        0.00   0.00   0.00  0.00    0.00     0.00     0.00    0.00
## nbr.na          0.00   0.00   0.00  0.00    0.00     0.00     0.00    0.00
## min            26.90   7.12   4.48  0.13   23.41    78.65   102.06   22.77
## max            75.45  13.86  12.30  1.34  487.67   864.70  1352.37   46.90
## range          48.55   6.74   7.82  1.21  464.26   786.05  1250.31   24.13
## sum          1874.50 393.23 303.21 23.71 7033.63 13961.87 20995.50 1371.55
## median         46.45   9.49   7.28  0.55  178.81   299.61   524.47   34.77
## mean           46.86   9.83   7.58  0.59  175.84   349.05   524.89   34.29
## SE.mean         1.70   0.30   0.28  0.05   13.27    28.95    40.83    1.04
## CI.mean.0.95    3.44   0.60   0.56  0.10   26.83    58.55    82.60    2.09
## var           115.65   3.49   3.07  0.10 7040.39 33516.31 66697.67   42.90
## std.dev        10.75   1.87   1.75  0.31   83.91   183.07   258.26    6.55
## coef.var        0.23   0.19   0.23  0.53    0.48     0.52     0.49    0.19

Una figura entre diámetro basal y altura

plot(DB, H, xlab = "Diámetro basal (cm)", ylab = "Altura (m)",  
     lty=1:5, pch=1, col=3)  

En esta figura puede observar que existe una correlacion importate entre ambas variables

Prueba de normalidad

shapiro.test(mis_datos$DB) #
## 
##  Shapiro-Wilk normality test
## 
## data:  mis_datos$DB
## W = 0.97914, p-value = 0.6577

Inspección de normalidad con q-q plots

ggqqplot(mis_datos$DB, ylab = "DB", color = 3)

Inspección de normalidad con box plots

boxplot(mis_datos$DB, col = 3, plot = TRUE) 

Inspección de normalidad con un histograma

hist(mis_datos$DB, col = 3) #

Calculo de correlación de Pearson a la matriz de datos q-q plots

cor_2 <- rcorr(as.matrix(mis_datos))
## Warning in sqrt(1 - h * h): Se han producido NaNs
cor_2
##        ID    DB     H    DC    VT    BH    BF    BT   PBH   PBF
## ID   1.00 -0.36 -0.21 -0.38 -0.29 -0.25 -0.32 -0.31  0.04 -0.04
## DB  -0.36  1.00  0.59  0.71  0.88  0.86  0.84  0.88 -0.09  0.09
## H   -0.21  0.59  1.00  0.56  0.74  0.53  0.68  0.65 -0.36  0.36
## DC  -0.38  0.71  0.56  1.00  0.76  0.75  0.80  0.81 -0.20  0.20
## VT  -0.29  0.88  0.74  0.76  1.00  0.82  0.95  0.94 -0.35  0.35
## BH  -0.25  0.86  0.53  0.75  0.82  1.00  0.85  0.93  0.08 -0.08
## BF  -0.32  0.84  0.68  0.80  0.95  0.85  1.00  0.99 -0.39  0.39
## BT  -0.31  0.88  0.65  0.81  0.94  0.93  0.99  1.00 -0.25  0.25
## PBH  0.04 -0.09 -0.36 -0.20 -0.35  0.08 -0.39 -0.25  1.00 -1.00
## PBF -0.04  0.09  0.36  0.20  0.35 -0.08  0.39  0.25 -1.00  1.00
## 
## n= 40 
## 
## 
## P
##     ID     DB     H      DC     VT     BH     BF     BT     PBH    PBF   
## ID         0.0233 0.1900 0.0169 0.0685 0.1221 0.0464 0.0554 0.8263 0.8263
## DB  0.0233        0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.5809 0.5809
## H   0.1900 0.0000        0.0002 0.0000 0.0004 0.0000 0.0000 0.0234 0.0234
## DC  0.0169 0.0000 0.0002        0.0000 0.0000 0.0000 0.0000 0.2081 0.2081
## VT  0.0685 0.0000 0.0000 0.0000        0.0000 0.0000 0.0000 0.0274 0.0274
## BH  0.1221 0.0000 0.0004 0.0000 0.0000        0.0000 0.0000 0.6031 0.6031
## BF  0.0464 0.0000 0.0000 0.0000 0.0000 0.0000        0.0000 0.0122 0.0122
## BT  0.0554 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000        0.1186 0.1186
## PBH 0.8263 0.5809 0.0234 0.2081 0.0274 0.6031 0.0122 0.1186              
## PBF 0.8263 0.5809 0.0234 0.2081 0.0274 0.6031 0.0122 0.1186

Tarea

De la siguiente liga: http://clicom-mex.cicese.mx/, descarge los datos de a) Precipitacion, Temperatura máxima y temperatura mínima de la estacion climatológica de Saltillo. Arreglelos para que con los datos del MEI https://www.esrl.noaa.gov/psd/enso/mei/, realice correlacion mensual, no sin antes probar la normalidad de los datos para que decida que tipo de correlacion debera realizar

Conteste

Que tipo de correlacion es la adecuada (Pearson, Spearman, Kendall)
Que variable climática responde mejor al MEI
Cuanto explica el fenomeno del ENSO la variable climática.