Esty corriendo un script para correlacionar raster, son capas de variables marinas para el mundo entero, por lo que son un poco pesadas en cuanto a información, la resolución del raster es 9 km en cada pixel, este es el script:
memory
rm(list = ls())
# packages
library(caret)
library(corrplot)
library(GGally)
library(landscapetools)
library(raster)
library(rgdal)
library(tidyverse)
# directory
path <- "/home/mude/Downloads/Recortado actual"
setwd(path)
dir()
# import rasters -------------------------------------------------
# list variables
asc <- dir(pattern = ".asc$")
asc
# import
var <- raster::stack(asc)
var
# names
names(var) <- names(var) %>% stringr::str_replace("X", "var")
names(var)
landscapetools::show_landscape(var[[1]])
# extract values
var_da <- var %>%
raster::values() %>%
na.omit
# verify
head(var_da)
dim(var_da)
# correlation ----------------------------------------------------
# directory
dir.create("correlation")
setwd("correlation")
# correlation spearman
corr <- cor(var_da, method = "spearman")
corr
# export
readr::write_csv(tibble::as_tibble(corr), "correlation.csv")
# correlation plot
corrplot::corrplot(corr, type = "lower", diag = FALSE, tl.srt = 45, mar = c(3, 0.5, 2, 1))
# export figure
tiff("corr.tif", wi = 18, he = 18, units = "cm", res = 300, comp = "lzw+p")
corrplot::corrplot(corr, type = "lower", diag = FALSE, tl.srt = 45, mar = c(3, 0.5, 2, 1))
dev.off()
# select variables -------------------------------------------------------------
# verify
caret::findCorrelation(corr, cutoff = .7, names = TRUE, verbose = TRUE)
# correlated variables
fi <- caret::findCorrelation(corr, cutoff = .7)
fi
# new test
corr_fi <- cor(var_da[, -fi], method = "spearman")
corr_fi
# verify
caret::findCorrelation(corr_fi, cutoff = .7, names = TRUE, verbose = TRUE)
# export
readr::write_csv(tibble::as_tibble(corr_fi), "correlation_fi.csv")
# graphic
ggpairs(var_da[, -fi] %>% tibble::as_tibble() %>% dplyr::sample_n(1e3),
lower = list(continuous = wrap(ggally_points, pch = 21, color = "black", fill = "blue", size = 2, alpha = .7)),
diag = list(continuous = wrap(ggally_barDiag, color = "gray10", bins = 15)),
upper = list(continuous = wrap(ggally_cor, color = "black", size = 5, method = "spearman"))) +
theme_bw() +
theme(text = element_text(colour = "black"),
axis.text = element_text(size = 8, colour = "black"),
strip.text.x = element_text(size = 13),
strip.text.y = element_text(size = 13),
panel.grid.major = element_line(colour = "white"))
# export
ggsave("correlation_plot.tiff", wi = 20, he = 15, un = "cm", dpi = 300, comp = "lzw+p")
# end
pero donde dice
landscapetools::show_landscape(var[[1]])
# extract values
var_da <- var %>%
raster::values() %>%
na.omit
# verify
head(var_da)
dim(var_da)
me pone el siguiente error: ERROR: cannot allocate vector of size 854.3 Mb como puedo forzar a la maquina a hacerlo¿?`Necesito forzar a la maquina a correr el código, como puedo aumentar el uso de memoria de la maquina para el programa R corra el código?..Se puede correr este codigo en algun lugar en internet si mi maquina no me permitiera hacerlo?