-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththinData.R
32 lines (21 loc) · 878 Bytes
/
thinData.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# thin data using stratum probabilities
#input:
# - PPdat - output from genData
# - bias - output from addSpatialBias
thinData <- function(PPdat = PPdat, bias = bias){
#put points on same scale as strata
pp1 <- as.data.frame(PPdat$xy)
names(pp1) <- c("x", "y")
#add spatial bias info to PP data
pp2 <- merge(round(pp1), bias, by.x = c("x","y"), by.y = c("x","y"))
#thin points using the detection probability
#reducing also to presence absence here not abundance
pp2$presence <- rbinom(nrow(pp2),1,pp2$stratprobs)
# make it presence only data
pp3 <- pp2[pp2$presence == 1,]
image.plot(list(x=PPdat$Lam$xcol, y=PPdat$Lam$yrow, z=t(PPdat$rf.s)), main='log-Lambda', asp=1)
points(pp2$x, pp2$y, pch = 20, col = "white")
points(pp3$x, pp3$y, pch = 20)#note rescale again - plotting back on original
thinpp <- pp3
return(thinpp)
}