# Fake data
#Parameters
N <- 100; J <- 3; S <- 3
psi <- c(0.5,0.3,0.2)
p11 <- 0.4; p12 <- 0.25; p22 <- 0.3
#Simulate state
z <- sample(0:2, N, replace=TRUE, prob=psi)
#Simulate detection
y <- matrix(0,nrow=N,ncol=J)
for (n in 1:N){
probs <- switch(z[n]+1,
c(0,0,0),
c(1-p11,p11,0),
c(1-p12-p22,p12,p22))
if(z[n]>0){
y[n,] <- sample(0:2, J, replace=TRUE, probs)
}
}
#Covariates
site_covs <- as.data.frame(matrix(rnorm(N*2),ncol=2)) # nrow = # of sites
obs_covs <- as.data.frame(matrix(rnorm(N*J*2),ncol=2)) # nrow = N*J
#Build unmarked frame
umf <- unmarkedFrameOccuMS(y=y,siteCovs=site_covs,obsCovs=obs_covs)
umf # look at data
summary(umf) # summarize
plot(umf) # visualize
umf@numStates # check number of occupancy states detected
Run the code above in your browser using DataLab