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
library(grid)
mis_datos<-read.csv("ene_feb.csv", header = T) #entre comillas es el archivo a abrir
head(mis_datos)
## a b
## 1 8.5 0.0
## 2 5.0 18.0
## 3 75.4 16.0
## 4 0.0 8.0
## 5 19.0 13.5
## 6 65.5 2.0
attach(mis_datos) #este es muy importante
mi_plot<-plot(a, b)
fit <- lm(b~a)
abline(fit, col="blue")

df <- data.frame(a, b)
p <- ggplot(df, aes(a, b)) + geom_point() + theme_classic()
ggExtra::ggMarginal(p, type = "histogram")

cor(a,b)
## [1] 0.06685343
ggqqplot(mis_datos$a, ylab = "a")

ggqqplot(mis_datos$b, ylab = "b")

# FUNCIÃN PARA APLICAR JACKKNIFE A LA CORRELACIÃN DE PEARSON
correlacion_jackknife <- function(matriz, method = "pearson"){
n <- nrow(matriz) # número de observaciones
valores_jackknife <- rep(NA, n)
for (i in 1:n) {
# Loop para excluir cada observación y calcular la correlación
valores_jackknife[i] <- cor(matriz[-i, 1], matriz[-i, 2], method = method)
}
promedio_jackknife <- mean(valores_jackknife)
standar_error <- sqrt(((n - 1)/n)*sum((valores_jackknife-promedio_jackknife)^2))
bias <- (n - 1) * (promedio_jackknife - cor(matriz[, 1], matriz[, 2],
method = method))
return(list(valores_jackknife = valores_jackknife,
promedio = promedio_jackknife,
se = standar_error,
bias = bias))
}
correlacion <- correlacion_jackknife(mis_datos)
correlacion$promedio
## [1] 0.06740275
correlacion
## $valores_jackknife
## [1] 0.059040157 0.075179888 0.042220704 0.062311985 0.066262723
## [6] 0.119907831 0.065608023 0.053049077 0.007039075 0.077958817
## [11] 0.056740263 0.088705115 0.073776277 0.129694111 0.056435277
## [16] 0.050579905 0.056673677 0.062505692 0.074868532 0.066330778
## [21] 0.049809107 0.056475821 0.079387079 0.066016652 0.094157624
## [26] 0.065660863 0.079638223 0.071234773 0.060055203 0.050565782
## [31] 0.050252252 0.067553728 0.049809107 0.078623531 0.094968686
##
## $promedio
## [1] 0.06740275
##
## $se
## [1] 0.1242232
##
## $bias
## [1] 0.01867702
Datos <- data.frame(correlacion)
attach(Datos)
plot(valores_jackknife, type = "l", pch = 1, col = "blue", ylab="Correlaciæ¼ã¸³n promedio")

Tarea
Conteste
- Cual es la correlación más adecuada o que deberá realizarse.
- En qué mes se observa la mayor correlación con el MEI
- Cual de los dos tipos de correlación presenta menor error
- Presente las figuas de la correlacion promedio (ultima figura del script)