I want to perform a moving window regression on every pixel of two raster stacks representing Band3 and Band4 of Landsat data. The result should be two additional stacks, one representing the Intercept and the other one representing the slope of the regression. So layer 1 of stack "B3" and stack "B4" result in layer 1 of stack "intercept" and stack "slope". Layer 2 of stack B3 and stack B4 result in layer 2,.... and so on.
I already came along the
gwrfunction, but want to stay in the raster package.
I somehow know that
focal must be included in order to set my moving window (which should be 3x3 pixels) and somehow a linear model like:
lm(as.matrix(b3)~as.matrix(b4)) although I don't think that this gets me the values pixelwise...
Instead of a rasterstack a layer by layer approach is also possible. (So it must not necessarily be a rasterstack of Band3.
Has anyone a glue how to program this in R?