Skip to content

Commit

Permalink
more experiments - beta distributed interannual variation in recruitm…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
Hughes authored and Hughes committed Aug 29, 2024
1 parent b0bda74 commit d2c1ac9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/getPriors.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ getPriors <- function(modList = NULL,
sSigmaMax = 0.18,
rIntSE = 0.25,
rSigmaMin =0.00001,
rSigmaMax = 0.79,
rSigmaMax =0.7,
qMin=0, qMax =0.6,
uMin = 0, uMax = 0.2,
zMin = 0, zMax = 0.2,
Expand Down
26 changes: 21 additions & 5 deletions inst/templates/JAGS_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ for(k in 1:nCounts){

#Survival
for(k in 1:nYears){
#Note adjustment as in Johnson et al 2020.
#mu.S[k] <- min(1,exp(l.Saf + anthro[k]*beta.Saf))
#sig.S[k] <- cv.S*mu.S[k]
#Get beta distribution parameters from mean and sd
#alpha.S[k] <- max(0.01,((1-mu.S[k])/sig.S[k]^2 - 1/mu.S[k]) * mu.S[k]^2)
#beta.S[k] <- max(0.01,alpha.S[k] * (1/mu.S[k] - 1))
#Saf2[k]~dbeta(alpha.S[k],beta.S[k])
#S.annual.KM[k] <- min((Saf2[k]*46-0.5)/45,1)

#Adult female survival - process variance
epsilon.Saf[k]~dnorm(0,tau.Saf)
log(Saf2[k]) <- l.Saf + anthro[k]*beta.Saf + epsilon.Saf[k]
Expand All @@ -20,11 +29,17 @@ for(k in 1:nYears){

#Recruitment
for(k in 1:nYears){
fixedEffect[k] <- l.R + anthro[k]*beta.Rec.anthro + fire[k]*beta.Rec.fire
sig.R[k]<-cv.R*fixedEffect[k]^2
tau.R[k]<-pow(sig.R[k], -2)
epsilon.R[k]~dnorm(0,tau.R[k])
log(R[k]) <- fixedEffect[k]+ epsilon.R[k]
mu.R[k] <- min(1,exp(l.R + anthro[k]*beta.Rec.anthro + fire[k]*beta.Rec.fire))
sig.R[k] <- cv.R*mu.R[k]
#Get beta distribution parameters from mean and sd
alpha.R[k] <- max(0.01,((1-mu.R[k])/sig.R[k]^2 - 1/mu.R[k]) * mu.R[k]^2)
beta.R[k] <- max(0.01,alpha.R[k] * (1/mu.R[k] - 1))
R[k]~dbeta(alpha.R[k],beta.R[k])

#sig.R[k]<-cv.R*exp(fixedEffect[k])
#tau.R[k]<-pow(sig.R[k], -2)
#epsilon.R[k]~dnorm(0,tau.R[k])
#log(R[k]) <- fixedEffect[k]+ epsilon.R[k]
}

#Growth
Expand Down Expand Up @@ -55,6 +70,7 @@ for(k in 2:nYears){

#NOTE truncate distribution to ensure intercept between 0 and (45+0.5)/46.
l.Saf ~ dnorm(l.Saf.Prior1,pow(l.Saf.Prior2,-2)) T(-10,-0.01092911)
#cv.S~dunif(sig.Saf.Prior1,sig.Saf.Prior2)
sig.Saf~dunif(sig.Saf.Prior1,sig.Saf.Prior2)
tau.Saf<-pow(sig.Saf, -2)

Expand Down
2 changes: 1 addition & 1 deletion man/getPriors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-caribouBayesianPM.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ test_that("results match expected", {
manyObs <- doScn(nCollar = 2000, rQuantile = 0.9, sQuantile = 0.9)
doPlot(manyObs, title = "2000 collars")

fewCollarObs <- doScn(nCollar = 0, rQuantile = 0.9, sQuantile = 0.9)
doPlot(fewCollarObs, title = "5 collars")
fewCollarObs <- doScn(nCollar = 5, rQuantile = 0.9, sQuantile = 0.9)
doPlot(fewCollarObs, title = "5 collars")#,var="Adult female survival")

difMany <- calcDif(manyObs$obs.all)
difFew <- calcDif(fewCollarObs$obs.all)
Expand Down

0 comments on commit d2c1ac9

Please sign in to comment.