I would like to fit a custom regression model (mblm package) to each cell in a time series raster (each layer is a year). My raster manipulation is all happening with terra, so I’d prefer to continue in that package world if possible.
Example dataset:
d<-rast(lapply(1:10, FUN = function(x){
rast(matrix(rnorm(100, mean=x), ncol=10))
}))
names(d)<-1:10
I’ve looked through the regress function, but I think I might be misunderstanding something about how it works. For example, if I create a hypothetical 10-layer year raster:
d1<-rast(lapply(names(d)[1:10], function(x) {rast(matrix(x, nrow=10, ncol=10))
}))
names(d1)<-1:10
and use the built-in lm within regress:
plot(regress(d, d1))
The slope raster (labelled ‘x’ comes out as all zero).