I have two land use rasters (6 classes each) and I'd like to create an error matrix (errors of omission and commission) from them both.
The premise is that I have a very fine 'base' raster and have aggregated it to a new, coarser resolution. I would like to know not just the difference in total area of each land use class but from what and to what land class have changed;
# make a raster to simulate fine res base raster; require(raster) ras.fine <- raster(nrows=10, ncols=10,xmn=0, xmx=10, ymn=0, ymx=10) ras.fine <- sample(seq(from = 1, to = 6, by = 1), size = 100, replace = TRUE) # aggregate it to represent the coarser raster ras.coarse <- aggregate(ras.fine,fact=2,expand=FALSE,fun=modal,na.rm=T)
Once we have done the above, it's easy enough to establish the total areas of land use classes and establish the difference ;
# use freq to count instances of land class and multiply by square of resolution data.frame(class = freq(ras.fine)[,1],count = freq(ras.fine)[,2],area = freq(ras.fine)[,2]*(res(ras.fine))^2) data.frame(class = freq(ras.coarse)[,1],count = freq(ras.coarse)[,2],area = freq(ras.coarse)[,2]*(res(ras.coarse))^2)
but the differences in total area of land class aren't enough; i'd like to know from what land classes the error has occurred from etc, making an error matrix.
As a start, we could directly compare the base raster and the aggregated raster by disaggregating the coarser raster back to the base resolution (is this fair??);
# disaggregate back to original resolution rc.d <- disaggregate(ras.coarse,fact=2) # then create a grid of 'disagreement'; that is where the two rasters do not agree disagree <- ras.fine != rc.d # and establish what land classes make up those cells of disagreement, from both the fine raster and the coarser raster fine.cov <- ras.fine * disagree coarse.cov <- rc.d * disagree
so now I have statistics for how much of each land class is classified incorrectly at a coarser scale, and theoretically what it is going to/coming from.
I'm a bit stuck from here; how do i fashion it into an error matrix? from what land class has another land class commissioned area from and vice versa?
I am essentially analysing the aggregation method but this allows quantification in uncertainty mapped against cost of effort.
Further: Qu on Cross Validation with regards to the validity of error matrices and raster aggregation