(Count) Model:
\[ n_j = A_j\hat{p}_j \exp\left[ \beta_0 + s(\text{y}_j) + s(\text{Depth}_j) \right] + \epsilon_j \]
Predictions (index \( r \)):
\[ n_r = A_r \exp\left[ \beta_0 + s(\text{y}_r) + s(\text{Depth}_r) \right] \]
Need to “fill-in” values for \( A_r \), \( \text{y}_r \) and \( \text{Depth}_r \).
predict
in Rpredict(model, newdata=data)
x y Depth SST NPP DistToCAS EKE off.set
126 547984.6 788254 153.5983 8.8812 1462.521 11788.974 0.0074 1e+08
127 557984.6 788254 552.3107 9.2078 1465.410 5697.248 0.0144 1e+08
258 527984.6 778254 96.8199 9.6341 1429.432 13722.626 0.0024 1e+08
259 537984.6 778254 138.2376 9.6650 1424.862 9720.671 0.0027 1e+08
260 547984.6 778254 505.1439 9.7905 1379.351 8018.690 0.0101 1e+08
261 557984.6 778254 1317.5952 9.9523 1348.544 3775.462 0.0193 1e+08
LinkID Nhat_tw
126 1 0.01417657
127 2 0.05123483
258 3 0.01118858
259 4 0.01277096
260 5 0.04180434
261 6 0.45935801
data.frame
is kingas.data.frame
existsdata.frame
predgrid$Nhat_tw <- predict(dsm_all_tw_rm, predgrid)
p <- ggplot(predgrid) +
geom_tile(aes(x=x, y=y,
fill=Nhat_tw)) +
scale_fill_viridis() +
coord_equal()
print(p)
Each cell has an abundance, sum to get total
sum(predict(dsm_all_tw_rm, predgrid))
[1] 2491.864
R subsetting lets you calculate “interesting” estimates:
# how many sperm whales at depths less than 2500m?
sum(predgrid$Nhat_tw[predgrid$Depth < 2500])
[1] 1006.272
# how many sperm whales North of 0?
sum(predgrid$Nhat_tw[predgrid$x>0])
[1] 1383.742
predict
Now we are dangerous.
(Getting a little fast-and-loose with the mathematics)
dsm
to do thisdsm.var.gam
dsm.var.prop
count
models (more or less)Using dsm.var.gam
dsm_tw_var_ind <- dsm.var.gam(dsm_all_tw_rm, predgrid,
off.set=predgrid$off.set)
summary(dsm_tw_var_ind)
Summary of uncertainty in a density surface model calculated
analytically for GAM, with delta method
Approximate asymptotic confidence interval:
2.5% Mean 97.5%
1539.018 2491.864 4034.643
(Using log-Normal approximation)
Point estimate : 2491.864
CV of detection function : 0.2113123
CV from GAM : 0.1329
Total standard error : 622.0389
Total coefficient of variation : 0.2496
Using dsm.var.prop
dsm_tw_var <- dsm.var.prop(dsm_all_tw_rm, predgrid,
off.set=predgrid$off.set)
summary(dsm_tw_var)
Summary of uncertainty in a density surface model calculated
by variance propagation.
Probability of detection in fitted model and variance model
Fitted.model Fitted.model.se Refitted.model
1 0.3624567 0.07659373 0.3624567
Approximate asymptotic confidence interval:
2.5% Mean 97.5%
1556.898 2458.634 3882.646
(Using log-Normal approximation)
Point estimate : 2458.634
Standard error : 581.0379
Coefficient of variation : 0.2363
dsm.var.*
thinks predgrid
is one “region”split()
)width
and height
of cells for plottingpredgrid$width <- predgrid$height <- 10*1000
predgrid_split <- split(predgrid, 1:nrow(predgrid))
head(predgrid_split,3)
$`1`
x y Depth SST NPP DistToCAS EKE off.set
126 547984.6 788254 153.5983 8.8812 1462.521 11788.97 0.0074 1e+08
LinkID Nhat_tw height width
126 1 0.01417657 10000 10000
$`2`
x y Depth SST NPP DistToCAS EKE off.set
127 557984.6 788254 552.3107 9.2078 1465.41 5697.248 0.0144 1e+08
LinkID Nhat_tw height width
127 2 0.05123483 10000 10000
$`3`
x y Depth SST NPP DistToCAS EKE off.set
258 527984.6 778254 96.8199 9.6341 1429.432 13722.63 0.0024 1e+08
LinkID Nhat_tw height width
258 3 0.01118858 10000 10000
dsm_tw_var_map <- dsm.var.prop(dsm_all_tw_rm, predgrid_split,
off.set=predgrid$off.set)
p <- plot(dsm_tw_var_map, observations=FALSE, plot=FALSE) +
coord_equal() +
scale_fill_viridis()
print(p)
cut()
in R to make categorical variable
c(seq(0,1, len=100), 2:4, Inf)
or somesuch