## Example 1 in Olofsson et al. (2013)
r<-c(rep("1",102),rep("2",280),rep("3",118))
m<-c(rep("1",97) ,rep("2",3), rep("3",2),rep("2",279),
"3",rep("1",3),rep("2",18),rep("3",97))
Nh<-c(22353, 1122543, 610228)
names(Nh)<-c("1", "2", "3")
a<-olofsson(r, m, Nh)
# compare to paper:
a$area[1] # eq. 9
a$area[1]*sum(Nh) # eq. 10
a$SEa[1]*sum(Nh) # eq. 12
a$area[1]*sum(Nh)-qnorm(0.975)*a$SEa[1]*sum(Nh) # 95% CI lower bound (note typo in the paper)
a$area[1]*sum(Nh)+qnorm(0.975)*a$SEa[1]*sum(Nh) # 95% CI upper bound
a$UA[1] # eq. 14
a$PA[1] # eq. 15
a$OA # eq. 16
a$UA # table 4
qnorm(0.975)*a$SEua # table 4
a$PA # table 4
qnorm(0.975)*a$SEpa # table 4
a$matrix # table 4
## Example 2 in Olofsson et al. (2013)
r<-c(rep("1", 129), rep("2", 403), rep("3", 611))
m<-c(rep("1", 127), "2", "2", rep("1", 66), rep("2", 322), rep("3", 15), rep("1", 54),
rep("2", 17), rep("3", 540))
Nh<-c(0.007, 0.295, 0.698)
names(Nh)<-c("1", "2", "3")
b<-olofsson(r, m, Nh)
# compare to paper (table 6):
b$OA
qnorm(0.975)*b$SEoa
b$UA
qnorm(0.975)*b$SEua
b$PA
qnorm(0.975)*b$SEpa
## Example of table 8 in Olofsson et al. (2014)
r<-c(rep(1,69),rep(2,56),rep(3,175),rep(4,340))
m<-c(rep(1,66), 3, rep(4,2), rep(2,55), 4, rep(1,5), rep(2,8),
rep(3,153),rep(4,9),rep(1,4),rep(2,12),rep(3,11),rep(4,313))
r[r==1] <- m[m==1] <- "Deforestation"
r[r==2] <- m[m==2] <- "Forest gain"
r[r==3] <- m[m==3] <- "Stable forest"
r[r==4] <- m[m==4] <- "Stable non-forest"
Nh<-c("Deforestation"=200000, "Forest gain"=150000,
"Stable forest"=3200000, "Stable non-forest"=6450000) * 30^2 # Landsat pixel area = 30^2
e<-olofsson(r, m, Nh)
# compare to paper, left-hand of p. 54:
e$UA # User's accuracy
qnorm(0.975)*e$SEua # 95% CI width
e$PA # Producer's accuracy
qnorm(0.975)*e$SEpa # 95% CI width
e$OA # Overall accuracy
qnorm(0.975)*e$SEoa # 95% CI width
# compare to paper, right-hand of p. 54:
e$area[1]*sum(Nh)/10000 # deforestation in hectares
qnorm(0.975)*e$SEa[1]*sum(Nh)/10000 # 95% CI width in hectares
e$area[2]*sum(Nh)/10000 # forest gain in hectares
qnorm(0.975)*e$SEa[2]*sum(Nh)/10000 # 95% CI width in hectares
e$area[3]*sum(Nh)/10000 # stable forest in hectares
qnorm(0.975)*e$SEa[3]*sum(Nh)/10000 # 95% CI width in hectares
e$area[4]*sum(Nh)/10000 # stable non-forest in hectares
qnorm(0.975)*e$SEa[4]*sum(Nh)/10000 # 95% CI width in hectares
# change class order
olofsson(r, m, Nh[c(4,2,1,3)])
# m (map) may include classes not found in r (reference)
r<-c(rep("1",102),rep("2",280),rep("3",118))
m<-c(rep("1",97) ,rep("2",3), rep("3",2),rep("2",279),
"3",rep("1",3),rep("2",18),rep("3",95), rep("4",2))
Nh<-c("1"=22353, "2"=1122543, "3"=610228, "4"=10)
olofsson(r, m, Nh)
# r (reference) may include classes not found in m (map)
r<-c(rep("1",102),rep("2",280),rep("3",116),rep("4",2))
m<-c(rep("1",97) ,rep("2",3), rep("3",2),rep("2",279),
"3",rep("1",3),rep("2",18),rep("3",97))
Nh<-c("1"=22353, "2"=1122543, "3"=610228)
olofsson(r, m, Nh)
# can add classes not found neither in r nor m
Nh<-c(Nh, "9"=0)
olofsson(r, m, Nh)
Run the code above in your browser using DataLab