generated quantities{
vector[N] p;
real dev;
dev = 0;
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
dev = dev + (-2)*binomial_logit_lpmf( y | 1 , p );
model_code_0 <- "
data{
int N;
int N_j_ID;
int y[N];
int j_ID[N];
}
parameters{
real a;
vector[N_j_ID] v_j_ID;
real<lower=0> sigma_j_ID;
}
model{
vector[N] p;
a ~ normal( 0 , 5 );
v_j_ID ~ normal ( 0, 1);
sigma_j_ID ~ exponential( 1 );
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
y ~ bernoulli(Phi( 1 , p ));
}
generated quantities{
vector[N] p;
real dev;
dev = 0;
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
dev = dev + (-2)*binomial_lpmf (y | N, Phi(alpha));
}
"
## Short chain for testing
mfit <- stan ( model_code = model_code_0, data = dat_list_0, chains = 1, cores = 1, warmup = 40, iter = 120, control = list(adapt_delta = 0.8))
Unfortunately, that yields the following error and it is not clear why:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
c++ exception (unknown reason)
- Bob
--
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/7ynljqtxLWk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Unfortunately, that yields the following error and it is not clear why:Error in stanc(file = file, model_code = model_code, model_name = model_name, :
c++ exception (unknown reason)
model_code_0 <- "
data{
int N;
int N_j_ID;
int y[N];
int j_ID[N];
}
parameters{
real a;
vector[N_j_ID] v_j_ID;
real<lower=0> sigma_j_ID;
}
model{
vector[N] p;
a ~ normal( 0 , 5 );
v_j_ID ~ normal ( 0, 1);
sigma_j_ID ~ exponential( 1 );
for ( i in 1:N ) {
y[i] ~ bernoulli(Phi(a + v_j_ID[j_ID[i]] * sigma_j_ID));
}
}
generated quantities{
vector[N] p;
real dev;
dev = 0;
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
dev = dev + (-2)*binomial_lpmf (y | N, Phi(alpha));
}
"
mfit <- stan ( model_code = model_code_0, data = dat_list_0, chains = 1, cores = 1, warmup = 40, iter = 120, control = list(adapt_delta = 0.8))
ERROR at line 33
31: p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
32: }
33: dev = dev + (-2)*binomial_lpmf (y | N, Phi(alpha));
^
34: }
#### Define variables from data frame
N <- nrow(df)
N_j_ID <- max(df$j_ID)
dat_list_0 <- list(
N = N,
N_j_ID = N_j_ID,
y = df$y,
j_ID = df$j_ID
)
model_code_0 <- "
data{
int N;
int N_j_ID;
int y[N];
int j_ID[N];
}
parameters{
real a;
vector[N_j_ID] v_j_ID;
real<lower=0> sigma_j_ID;
}
model{
vector[N] p;
a ~ normal( 0 , 5 );
v_j_ID ~ normal ( 0, 1);
sigma_j_ID ~ exponential( 1 );
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
y ~ binomial_logit( 1 , p );
}
generated quantities{
vector[N] p;
real dev;
dev = 0;
for ( i in 1:N ) {
p[i] = a + v_j_ID[j_ID[i]] * sigma_j_ID;
}
dev = dev + (-2)*binomial_logit_lpmf( y | 1 , p );
}
"
mfit <- stan ( model_code = model_code_0, data = dat_list_0, chains = 1, cores = 1, warmup = 40, iter = 120, control = list(adapt_delta = 0.8))
y ~ binomial_logit( 1 , p );
y ~ bernoulli(Phi(p));
dev = dev + (-2)*binomial_logit_lpmf( y | 1 , p );
dev = dev - 2 * bernoulli_lpmf(y | Phi(p))
I'm not sure where stan user is confused---I wrote exactly that
a few messages back.
- Bob
> On May 11, 2017, at 1:30 PM, Ben Goodrich <goodri...@gmail.com> wrote:
>
> On Thursday, May 11, 2017 at 11:59:56 AM UTC-4, stan user wrote:
> y ~ binomial_logit( 1 , p );
>
> First, it does not make much sense to use binomial_* with a size of 1. It is clearer to use bernoulli_*. In your case, it would be
>
> y ~ bernoulli(Phi(p));
>
>
> dev = dev + (-2)*binomial_logit_lpmf( y | 1 , p );
>
> Change this line to
>
> dev = dev - 2 * bernoulli_lpmf(y | Phi(p))
>
> But deviance calculations are pretty useless to a Bayesian.
>
> Ben
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
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/7ynljqtxLWk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
model_code_b <- "
data{
int N;
int N_j_ID;
int y[N];
int j_ID[N];
}
parameters{
real a;
// Random effect for higher-level
vector[N_j_ID] v_j_ID;
real<lower=0> sigma_j_ID;
}
model{
vector[N] p;
//priors
a ~ normal( 0 , 5 );
sigma_j_ID ~ exponential (1);
// LIKELIHOOD
for ( i in 1:N ) {
p[i] =
a
+ v_j_ID [ j_ID[i]] * sigma_j_ID
;
}
// update target
y ~ bernoulli (Phi(p));
}
generated quantities{
vector[N] p;
vector[N] log_lik;
for ( i in 1:N) {
p[i] =
a
+ v_j_ID [ j_ID[i]] * sigma_j_ID;
log_lik[i] = bernoulli_lpmf (y[i]) | Phi(p) );