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

Micha Silver t@v|b@r @end|ng |rom gm@||@com
Sun Dec 24 14:48:32 CET 2023


On 23/12/2023 19:22, Nikolaos Tziokas wrote:
> 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


Could it be that the 12 monthly data do not show more than one full 
period of whatever the rasters are showing? That seems to be what the 
error is indicating. If you want to decompose some seasonal time series, 
then you need several seasons of data.


>
> 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]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918



More information about the R-sig-Geo mailing list