Simulating datasets for gdistsamp

19 views
Skip to first unread message

Max Khoo

unread,
Apr 22, 2024, 8:52:33 AMApr 22
to unmarked
Hello everyone,

I'm fairly new to unmarked, and even newer to simulating data. I have been trying to simulate data for bird surveys so that we can decide on a realistic number of sites to survey for a study. We intend to use distance sampling, and I have been trying to observe the different results for 'distsamp' and 'gdistsamp'. I had no issues simulating the dataset for 'distsamp' (code in the bottom, 2nd section), but am facing some problems with 'gdistsamp'. 

Would anyone be able to point me to any guide on simuating data for gdistsamp, or would kindly be able to help me out and let me know which part is causing the error?

Thank you! 

Code:
forms3 <- list(lambdaformula=~1,phiformula = ~1, pformula =~1)
coefs3 <- list(lambdaformula=c(intercept=2.55), phiformula=c(intercept=3.42), pformula=c(intercept=1))
design3 <- list(M=400, J=2, T=3) 
df_distsamp<-simulate("gdistsamp", formulas=forms3, coefs = coefs3, design=design3, keyfun = "halfnorm",  survey="point", dist.breaks=c(0,50,100), unitsIn="m", K=500, mixture="NB")

Error:
Error in matrix(0, design$M, design$T * design$J) :   non-numeric matrix extent


--- My simulation code for distsamp, which works fine.

forms <- list(state=~1, det=~1)
coefs <- list(state=c(intercept=2.55), det=c(intercept=3.42)) #Based on state and detection coefficient from previous study
design <- list(M=400, J=2) # 400 sites
df_distsamp<-simulate("distsamp", formulas=forms, coefs = coefs, design=design, keyfun = "halfnorm", survey="point", dist.breaks=c(0,50,100), unitsIn="m")
df2<-(distsamp(~1 ~1, df_distsamp))

# Modelling uncertainty
getDens.hat<- function(fit) {
d <- predict(fit, type="state")$Predicted
Dens.hat <- c(Dens.hat = mean(d))
return(Dens.hat)
}

df3 <- parboot(df2, statistic=getDens.hat, nsim=1000)
df3


Regards,

Max

Ken Kellner

unread,
Apr 22, 2024, 8:57:06 AMApr 22
to unmarked
Hi Max,

The main issue with your code is the names assigned to the formula and coefficient lists - these have to exactly match what unmarked::simulate is expecting. For gdistsamp it's lambda, phi, and det (and also alpha for an NB model). unmarked is unfortunately a little unpredictable in exactly how it names these submodels across different model types. If you aren't sure about the names for a given model a good approach is to fit an example model of that type (e.g. from the ?gdistsamp help file) and then find the names of the submodels with code names(modelobject) and match these. The following modified code should get you started:

library(unmarked) forms3 <- list(lambda=~1, phi = ~1, det =~1) 
coefs3 <- list(lambda=c(intercept=2.55), phi = c(intercept=0), det = c(intercept=log(50)), alpha=c(alpha=0.5))
design3 <- list(M=400, J=2, T=3)
df_distsamp<-simulate("gdistsamp", formulas=forms3, coefs = coefs3, design=design3, 
keyfun = "halfnorm", survey="point", dist.breaks=c(0,50,100), unitsIn="m", K=100, mixture="NB") 

mod <- gdistsamp(lambdaformula=~1, phiformula=~1, pformula=~1, data=df_distsamp, mixture="NB")

Ken
Reply all
Reply to author
Forward
0 new messages