wiki:kappar

# Differences

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

 wiki:kappar [2017/12/05 22:53] wiki:kappar [2020/07/17 06:39] (current) Line 1: Line 1: + ====== ​ Plotting a confusion matrix and calculate kappa statistics ====== + ==== generate simulated data ==== + + library(PresenceAbsence) + ​set.seed(666) + ​N=1000 + N + ​SIMDATA<​-matrix(0,​N,​3) + str(SIMDATA) + ​SIMDATA<​-as.data.frame(SIMDATA) + str(SIMDATA) + ​names(SIMDATA)<​-c("​plotID","​Observed","​Predicted"​) + ​SIMDATA\$plotID<​-1:​N + str(SIMDATA) + ​SIMDATA\$Observed<​-rbinom(n=N,​size=1,​prob=.2) + str(SIMDATA) + ​SIMDATA\$Predicted[SIMDATA\$Observed==1]<​-rnorm(n=length(SIMDATA\$Observed[SIMDATA\$Observed==1]),​mean=.8,​sd=.15) + ​SIMDATA\$Predicted[SIMDATA\$Observed==0]<​-rnorm(n=length(SIMDATA\$Observed[SIMDATA\$Observed==0]),​mean=.2,​sd=.15) + ​SIMDATA\$Predicted<​-(SIMDATA\$Predicted-min(SIMDATA\$Predicted))/​(max(SIMDATA\$Predicted)-min(SIMDATA\$Predicted)) + + ### plot simulated data + ​hist(SIMDATA\$Predicted,​100) + ​hist(SIMDATA\$Observed,​100) + ### calculate confusion matrix ### + ​confusion.matrix=cmx(SIMDATA) + ​Kappa(confusion.matrix,​ st.dev = TRUE) + + data(SIM3DATA) + + ​cmx(SIM3DATA) + ​cmx(SIM3DATA,​which.model=2) + ​cmx(SIM3DATA,​which.model=3,​threshold=.2) + +