### Site Tools

wiki:rstat:r_cohen_kappa

# Differences

This shows you the differences between two versions of the page.

 — wiki:rstat:r_cohen_kappa [2017/12/05 22:53] (current) Line 1: Line 1: + ====== Cohen'​s Kappa statistics for comparing categorical maps ====== + Back to R geographical analyses [[wiki:​rstat:​r_geography| main menue]].\\ + \\ + In this tutorial we learn how to compare 2 categorical maps using the kappa statistics.\\ + [[http://​virtualhost.cs.columbia.edu/​~julia/​courses/​CS6998/​Interrater_agreement.Kappa_statistic.pdf| Supplementary readings]] on Cohen'​s Kappa statistics.\\ + As rule of thumbs these are Kappa values for interpretation:​ + * < 0 - Less than chance agreement + * 0.01–0.20 - Slight agreement + * 0.21– 0.40 - Fair agreement + * 0.41–0.60 - Moderate agreement + * 0.61–0.80 - Substantial agreement + * 0.81–0.99 - Almost perfect agreement + + First create a working directory, migrate there and download raster data. + wget http://​www.spatial-ecology.net/​ost4sem/​exercise/​r_ecoservice/​raster/​carS_m9.asc + wget http://​www.spatial-ecology.net/​ost4sem/​exercise/​r_ecoservice/​raster/​carA_m9.asc + wget http://​www.spatial-ecology.net/​ost4sem/​exercise/​r_ecoservice/​raster/​recA_m9.asc + wget http://​www.spatial-ecology.net/​ost4sem/​exercise/​r_ecoservice/​raster/​recT_m9.asc + + Then open an R session: + + + SoilCarbon=raster(readGDAL("​carS_m9.asc"​)) + AeriCarbon=raster(readGDAL("​carA_m9.asc"​)) + hist(SoilCarbon) + hist(AeriCarbon) + breaks=seq(0,​100,​20) + SoilCarbonClass <- cut(SoilCarbon,​ breaks=breaks) + AeriCarbonClass <- cut(AeriCarbon,​ breaks=breaks) + Confusion.Soil_Aerial <- table(SoilCarbonClass@data@values,​ AeriCarbonClass@data@values) + confusionMatrix(Confusion.Soil_Aerial) + + + # Confusion Matrix and Shtatistics + # + #    ​ + #        1    2    3    4    5 + #   1 1822  235   ​62 ​  ​11 ​   4 + #   ​2 ​ 522   ​87 ​  ​48 ​  ​18 ​   3 + #   ​3 ​ 408   ​48 ​  ​21 ​   7    4 + #   ​4 ​  ​56 ​   5    0    0    0 + #   ​5 ​ 175   ​12 ​   4    0    0 + # + # Overall Statistics + # + #                Accuracy : 0.5434 ​         ​ + #                  95% CI : (0.5268, 0.5598) + #     No Information Rate : 0.8398 ​         ​ + #     ​P-Value [Acc > NIR] : 1 + # + #                   Kappa : 0.0265 ​         ​ + #  Mcnemar'​s Test P-Value : NA              ​ + # + # Statistics by Class: + # + #                      Class: 1 Class: 2 Class: 3 Class: 4 Class: 5 + # Sensitivity ​           0.6108 ​ 0.22481 0.155556 ​ 0.00000 0.000000 + # Specificity ​           0.4517 ​ 0.81327 0.863330 ​ 0.98265 0.946060 + # Pos Pred Value         ​0.8538 ​ 0.12832 0.043033 ​ 0.00000 0.000000 + # Neg Pred Value         ​0.1812 ​ 0.89562 0.962794 ​ 0.98969 0.996727 + # Prevalence ​            ​0.8398 ​ 0.10895 0.038007 ​ 0.01014 0.003097 + # Detection Rate         ​0.5130 ​ 0.02449 0.005912 ​ 0.00000 0.000000 + # Detection Prevalence ​  ​0.6008 ​ 0.19088 0.137387 ​ 0.01717 0.053773 + ​ + + + + You can do the same for comparing Aesthetic value and turism: + + + breaks=seq(0,​100,​20) + Aesthetic=raster(readGDAL("​recA_m9.asc"​)) + Turism=raster(readGDAL("​recT_m9.asc"​)) + AestheticClass <- cut(Aesthetic,​ breaks=breaks) + TurismClass <- cut(Turism, breaks=breaks) + Confusion.Aesthetic_Turism <- table(AestheticClass@data@values,​TurismClass@data@values) + confusionMatrix(Confusion.Aesthetic_Turism) + + # Confusion Matrix and Statistics + # + #    ​ + #       ​1 ​  ​2 ​  ​3 ​  ​4 ​  5 + #   1 245   ​7 ​  ​0 ​  ​0 ​  0 + #   ​2 ​ 53   ​5 ​  ​1 ​  ​1 ​  0 + #   ​3 ​ 16   ​4 ​  ​1 ​  ​1 ​  0 + #   ​4 ​ 11   ​2 ​  ​0 ​  ​0 ​  1 + #   ​5 ​  ​2 ​  ​1 ​  ​0 ​  ​0 ​  0 + # + # Overall Statistics + # + #                Accuracy : 0.7151 ​         ​ + #                  95% CI : (0.6648, 0.7618) + #     No Information Rate : 0.9316 ​         ​ + #     ​P-Value [Acc > NIR] : 1 + # + #                   Kappa : 0.1132 ​         ​ + #  Mcnemar'​s Test P-Value : NA              ​ + # + # Statistics by Class: + # + #                      Class: 1 Class: 2 Class: 3 Class: 4 Class: 5 + # Sensitivity ​           0.7492 ​ 0.26316 0.500000 0.000000 0.000000 + # Specificity ​           0.7083 ​ 0.83434 0.939828 0.959885 0.991429 + # Pos Pred Value         ​0.9722 ​ 0.08333 0.045455 0.000000 0.000000 + # Neg Pred Value         ​0.1717 ​ 0.95189 0.996960 0.994065 0.997126 + # Prevalence ​            ​0.9316 ​ 0.05413 0.005698 0.005698 0.002849 + # Detection Rate         ​0.6980 ​ 0.01425 0.002849 0.000000 0.000000 + # Detection Prevalence ​  ​0.7179 ​ 0.17094 0.062678 0.039886 0.008547 + + ​ + \\ + Aesthetic and Carbon in the soil give a Kappa : -0.0363 - Less than chance agreement