### Sidebar

spatial-ecology.org

Trainings:

Learn:

Data:

Community:
teachers
students
projects
Matera 2015
Vancouver 2015
Santa Barbara 2015
Site design
Hands on:
Installations

Donations
USD

GBP

wiki:kappar

# 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)```