I am working with an NDVI time series raster composite (1989 to 2019). I am running a time series function on each pixel of the raster stack using the R code provided by Pironkova et al. 2018. The code looks like this:
#install packages
install.packages("raster")
install.packages("rkt")
install.packages("trend")
install.packages("zoo")
#load packages
require(raster)
require(rkt)
require(trend)
require(zoo)
rasterOptions(maxmemory=1e+06, chunksize=1e+07, progress = 'text')
# Set working directory (location of raster)
setwd("D:/Local /Data/NDVI_10yr")
results <-"D:/Local /Data/NDVI_10yr/Results"
# stack all files with .tif extension in working directory
stacked_files <-stack(list.files(pattern = ".tif"))
#brick the stacked files
bricked_files <-brick("ndvi30year_sbr.tif")
#remove unnecessary files from memory
rm(stacked_files)
gc()
plot(bricked_files)
# Set year range for analysis
years <-seq(1989, 2019)
# Analysis function
rktFun <-function(x) {
if(all(is.na(x))){
c(NA,NA,NA)
} else {
analysis <-rkt(years, x)
a <-analysis$B # theil sen slope
b <-analysis$sl # pvalue
c <-analysis$tau # tau
return(cbind(a, b, c))
} }
rRaster <-calc(bricked_files, rktFun)
This function returns an error :
*Error: first mandatory vector should be positive: year or year+fraction
second mandatory vector should be numerical: measured data (ties allowed)
third optional vector should be positive integer: season, month, site or a unique code for season and site
fourth optional vector should be numerical: covariable
all with the same length, at least 4*
Where am I going wrong?