# example confusion matrix
# rows: allocation (user's counts)
# columns: reference (producer's counts)
crossclass <- matrix(data=c(2,1,0,5,0,0,
1,74,2,1,3,6,
0,5,8,6,1,3,
6,1,3,91,0,0,
0,4,0,0,0,4,
0,6,2,2,4,38),
nrow=6, byrow=TRUE)
row.names(crossclass) <- c("OP", "SA", "UA", "UC", "AV", "AC")
colnames(crossclass) <- row.names(crossclass)
# build the weights matrix
# how much credit for a mis-allocation
weights <- matrix(data=c(1.00,0.05,0.05,0.15,0.05,0.15,
0.05,1.00,0.05,0.05,0.05,0.35,
0.05,0.05,1.00,0.20,0.15,0.15,
0.15,0.05,0.25,1.00,0.10,0.25,
0.05,0.10,0.15,0.10,1.00,0.15,
0.20,0.30,0.10,0.25,0.20,1.00),
nrow=6, byrow=TRUE)
# unweighted accuracy
summaryTauW(nnaive <- tauW(crossclass))
# unweighted tau with equal priors, equivalent to Foody (1992) modified Kappa
tauW(crossclass)$tau
# unweighted tau with user's = producer's marginals, equivalent to original kappa
(priors <- apply(crossclass, 2, sum)/sum(crossclass))
tauW(crossclass, P=priors)$tau
# weighted accuracy; tau with equal priors
summaryTauW(weighted <- tauW(crossclass, W=weights))
# weighted accuracy; tau with user's = producer's marginals
summaryTauW(tauW(crossclass, W=weights, P=priors))
# change in accuracy statistics weighted vs. non-weighted
(weighted$overall.weighted - weighted$overall.naive)
(weighted$user.weighted - weighted$user.naive)
(weighted$prod.weighted - weighted$prod.naive)
Run the code above in your browser using DataLab