You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/Wkeitft_J7c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Process model:
logit(psi[i]) = mu + X*Beta
Observation model:
z[i] ~ Bernoulli(psi[i]*rho + (1-psi[i])*(1-phi))
Data model:
y[i] ~ Bernoulli(z[i]*pi)
"Exception thrown at line 64: stan::math::bernoulli_log: Probability parameter is -1.64453, but must be between (0, 1)"
S_it ~ Binomial(N_it-1, omega)
G_it ~ Binomial(N_it-1, gamma)
N_it = S_it + G_it
n_it ~ Poisson(N_it)
Here is my Stan code:
'
data{
int<lower=0> N_cam; // number cameras (i)
int<lower=0> N_t; // number of occasions (t)
int<lower=0> obs[N_cam, N_t]; // observations (nit)
int<lower=1> K; // upper bound of population size could allow this to change at each time?
}
transformed data{
int<lower=0> max_obs[N_cam];
for(i in 1:N_cam){
max_obs[i] = max(obs[i]);
}
}
parameters{
real<lower=0,upper=1> gamma; // arrival rate
real<lower=0,upper=1> omega; // survival probability
//real<lower=0,upper=1> pi; // probability of detecting same individual more than once
real<lower=0> sigma;
}
transformed parameters{
}
model{
// specify priors
gamma ~ beta(1,1);
omega ~ beta(1,1);
for(i in 1:N_cam){
for(t in 2:N_t){
int S[i,t];
int G[i,t];
int N;
vector[K-max_obs[i] + 1] lp;
// try specifying values at timestep 1
S[i,1] = 10;
G[i,1] = 2;
// this is the part of the code that I know is incorrect, but Im not sure how to do it properly
for(j in 1:(K-max_obs[i] +1)){ // or for (j in 1:K)
lp[j] = binomial_lpmf(S[i,t]|(G[i,(t-1)] + S[i,(t-1)]), omega)
+ binomial_lpmf(G[i,t]|(G[i,(t-1)] + S[i,(t-1)]), gamma);
target += log_sum_exp(lp);
N = S[i,t] + G[i,t];
sigma ~ gamma(2,1);
//obs[i,t] ~ neg_binomial(-pow(mu,2)/(mu-sigma), mu/(mu-sigma));
obs[i,t] ~ poisson(N);
}
}
}
}',
# And here is the code to simulate data
mean_pop <- 20
ncam <- 10
Nt <- 5 # might need to make this specific to each camera
gamma <- 0.1 # arrival rate
omega <- 0.8 # survival rate
pi <- 0.2 # pr detecting more than once
S <- matrix(NA, ncam, Nt)
G <- matrix(NA, ncam, Nt)
N_tot <- matrix(NA, ncam, Nt)
N1 <- rpois(ncam, mean_pop)
N_tot[,1] <- N1
for(i in 1:ncam){
for(t in 2:Nt){
S[i,t] <- rbinom(1,N_tot[,t-1],(omega*(1-pi)))
G[i,t] <- rbinom(1,N_tot[,t-1], gamma)
N_tot[i,t] <- rpois(1,S[i,t] + G[i,t])
}
}
Thank you in advance for your help,
Mikey
Thank you in advance for your help,
Mikey
Hi all,
I'm working on another model now that has latent discrete parameters (this time they are unbounded, which makes it more complicated). I'll present with just the most simple model structure. It is an open population mixture model where I'm looking N (true population size) as a function of Survival (S) and gains (G), with n_it observations. I get the error message: "Rejecting initial value: Error evaluating log probability at initial value". I tried specifying initial values for omega and gamma, but maybe I am missing something.
<w:LsdException Locked="false" SemiHidden="true" UnhideWhenUsed
S_it ~ Binomial(N_it-1, omega)
G_it ~ Binomial(N_it-1, gamma)
N_it = S_it + G_it
obs_it ~ Poisson(N_it)
//sigma ~ gamma(2,1);
//obs[i,t] ~
neg_binomial(-pow(mu,2)/(mu-sigma), mu/(mu-sigma));
obs[i,t] ~ poisson(N);
}
}
}
}'
# And here is the R code to simulate data
mean_pop <- 20
ncam <- 10
Nt <- 5 # might need to make this specific to each camera
gamma <- 0.1 # arrival rate
omega <- 0.8 # survival rate
pi <- 0.2 # pr detecting more than once
S <- matrix(NA, ncam, Nt)
G <- matrix(NA, ncam, Nt)
N_tot <- matrix(NA, ncam, Nt)
N1 <- rpois(ncam, mean_pop)
N_tot[,1] <- N1
for(i in 1:ncam){
for(t in 2:Nt){
S[i,t] <- rbinom(1,N_tot[,t-1],(omega*(1-pi)))
G[i,t] <- rbinom(1,N_tot[,t-1], gamma)
N_tot[i,t] <- rpois(1,S[i,t] + G[i,t])
}
}
data <- list(N_cam=ncam, N_t=Nt, obs=N_tot, K=1000)
Thank you for any help you can provide,