[R-sig-Geo] Error when running bfastlite using a monthly time-series matrix as input

Nikolaos Tziokas n|ko@@tz|ok@@ @end|ng |rom gm@||@com
Sat Dec 23 18:22:57 CET 2023


I have 12 raster images which I stack them. Then I converted the
rasterstack to a matrix, I remove the NA's from the matrix and I convert
the matrix to monthly time-series matrix. Finally, I run the bfastlite
function, like so:

library(bfast)
library(raster)

wd <- "path"

l <- list.files(paste0(wd), pattern='.tif$',
                all.files=TRUE, full.names=FALSE)

r <- raster::stack(paste0(wd, l))

m <- raster::as.matrix(r)
m <- m[!rowSums(is.na(m)), ]

# convert the matrix to timeseries matrix
tm <- ts(data = m, start = c(2019, 1), end = c(2019, 12), frequency = 12,
class = "ts")
class(tm)

bf <- bfastlite(
  tm,
  formula = response ~ trend + harmon,
  order = 3,
  breaks = "LWZ",
  na.action = na.omit,
  stl = "trend",
  decomp = "stl",
  sbins = 1,
  h = 0.5,
  level = 0.5,
  type = "OLS-MOSUM"
)
And the error:

Error in stats::stl(x, s.window = "periodic") :
  series is not periodic or has less than two periods

I have tried many variations in the parameters of the bfastlite function.

Any ideas what that error means and how I can overcome it? The dataset can
be downloaded from my GoogleDrive (
https://drive.google.com/drive/folders/1V115zpdU2-5fXssI6iWv_F6aNu4E5qA7).

RStudio 2023.12.0+369, R 4.3.2, Windows 11.

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list