I have 30 rasters layers which represent a value for 30 consecutive years. How to create a linear regression for each cell over the 30 layers and output the slope? I am assuming they represent consecutive times.
You have a raster cell (i,j) is part of a N x M grid say.
Let raster cell (i,j) have the value Y_ijt at time t, for t =1,2,...,30
Suppose as suggested by your questions that the years / times of observation are evenly spaced.
Your question asks for Y_ijt = a_ij + b_ij (t) where a_ij and b_ij are the regression parameters for that ij cell.
I assume others will tell you how to do this, but I am here to question the basic approach. Have you heard of spatial or temporal auto-correlation? Let's look at temporal auto-correlation -- cell ij has values that vary over time -- perhaps there is trend, seasonality, or even periods of "up" or "down" trend. None of these will be handled properly with the regression you are asking about.You can model the time series at cell ij in better ways. Then there is the spatial auto-correlation -- the value at cell (i,j) may depend or relate to adjacent values at (i+1, j+1), etc.. It is best to model or account for this similarity than comes from adjacent areas. For example I very much doubt that all the spatial cells (the rasters) have independent values.
Just trying to raise more questions than you have asked so far.
You have a raster cell (i,j) is part of a N x M grid say.
Let raster cell (i,j) have the value Y_ijt at time t, for t =1,2,...,30
Suppose as suggested by your questions that the years / times of observation are evenly spaced.
Your question asks for Y_ijt = a_ij + b_ij (t) where a_ij and b_ij are the regression parameters for that ij cell.
I assume others will tell you how to do this, but I am here to question the basic approach. Have you heard of spatial or temporal auto-correlation? Let's look at temporal auto-correlation -- cell ij has values that vary over time -- perhaps there is trend, seasonality, or even periods of "up" or "down" trend. None of these will be handled properly with the regression you are asking about.You can model the time series at cell ij in better ways. Then there is the spatial auto-correlation -- the value at cell (i,j) may depend or relate to adjacent values at (i+1, j+1), etc.. It is best to model or account for this similarity than comes from adjacent areas. For example I very much doubt that all the spatial cells (the rasters) have independent values.
Just trying to raise more questions than you have asked so far.
If you have a cloud layer from the same time period(s), one effect might be that this cloud acts as a mask on the cell ... in a sense you have missing values for Y_ijt for some (hopefully not all!) t. You might be able to model the missing value with a good model.
Alternatively, you could try to patch the area "under" the cloud by smoothly replacing Y_ijt by values from nearby unclouded patch (depends on how big the raster cells are compared to the cloud cover)
Sorry if this is not a sensible answer to the questions you have