---
output: html_document
---
### Null OccDet

Need to use greta.multivariate. This model and model evolving saved for later.
#### data
```{r data, highlight = FALSE}
# make fake data
n_species <- 1
n_sites <- 50
n_obs <- 10

occupancy <- matrix(rbinom(n_sites * n_obs, 1, 0.5), nrow = n_sites)
```

#### greta code
```{r null_occdet_greta}

 #### constant occupancy detection model ####
  psi ~ dunif(0,1)
  p ~ dunif(0,1)
  
  for(i in 1:n.sites){
    z[i] ~ dbern(psi) #occupancy
    p.eff[i] <- z[i] * p #detectability
    
    for(j in 1:n.reps){
      y[i,j] ~ dbern(p.eff[i])
    }
  }


# load greta
library(greta)

# data
Y <- as_data(occupancy)

# variables
psi <- uniform(0,1) # average detectability
p <- uniform(0,1) # average occupancy

z <- bernoulli(psi) # true occupancy
p.eff <- z %*% p #detectability

distribution(Y) = bernoulli(p.eff)

# create model object with the things we want samples of
m <- model(psi, p)

# plot model structure
plot(m)

fit <- mcmc(m)

```
