Created
October 5, 2020 09:44
-
-
Save dill/db6d049a504f52f4b414d7769beffbff to your computer and use it in GitHub Desktop.
point transect distance sampling in Nimble (half-normal with 2 detection function covariates)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# need to define half-normal point transect detection function pdf | |
dhnpt <<- nimbleFunction( | |
run = function(x = double(0), b0 = double(0), b1 = double(0), | |
covar = double(0), width = double(0), | |
log = integer(0, default = 0)) { | |
returnType(double(0)) | |
# calculate scale parameter | |
sigma <- exp(b0 + b1*covar) | |
# analytic expression for integral of 2*r*g(r)/width^2 when | |
# g(r) is half-normal (Intro distance book eqn 3.45) | |
nu <- sigma^2 * (1 - exp(-(width^2)/(2*sigma^2))) | |
# evaluate the detection function at distance/chaparral combination | |
g <- exp(-(x^2)/(2*sigma^2)) | |
L <- (x * g)/nu | |
if(log) return(log(L)) | |
else return(L) | |
} | |
) | |
rhnpt <<- nimbleFunction( | |
run = function(n = integer(0), b0 = double(0), b1 = double(0), | |
covar = double(0), width = double(0), | |
log = integer(0, default = 0)) { | |
returnType(double()) | |
return(0) | |
} | |
) | |
nimble::registerDistributions(list( | |
dhnpt = list(BUGSdist="dhnpt(b0, b1, covar, width)", | |
pqAvail = FALSE, | |
range = c(0, 1000)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment