This is the error message:
"In writeBin(v, x@file@con, size = x@file@dsize) : problem writing to connection 6: In .rasterFromRasterFile(grdfile, band = band, objecttype) : size of values file does not match the number of cells (given the data type)"
I have 15 raster files of the same extent and dimension. I just want to find out the Correlation of this data across time (15 years) ie 15 raster files.
I used the script below:
list <- c(list.files(pattern = "\\.tif$"))
y <- stack()
for (i in 1:length(list)){
y <- stack(y,list[i]) }
corT <- layerStats(y, 'pearson', na.rm=TRUE)
OR Used the stacked file directly like this
test = brick ("EOS_ALL_STACK.tif")
corT = layerStats(test, 'pearson', na.rm=TRUE)
I also tried to use this function to get correlation coefficients and r squared like this
fun5=function(x) { if (is.na(x[1])){ NA } else { m <- lm(x[1:15] ~ c(1:15));summary(m)$coefficients[1,4]}} #fstatistic[1]
fun5=function(x) { if (is.na(x[1])){ NA } else { m <- lm(x[1:15] ~ c(1:15));summary(m)$coefficients[2,4]}} #fstatistic[2]
fun3=function(x) { if (is.na(x[1])){ NA } else { m <- lm(x[1:15] ~ x[1:15]);summary(m)$r.squared }}
then used "calc" to calculate these across all pixels. For example:
r.squared <- calc(y, fun3)
However, my results still has the above errors and even when there is an output, it does not seem to make sense.