Skip to content

poisson_log_glm sampling statement fails to fit #1498

Description

@FJCC

Summary:

Fitting data with
y ~ poisson_log_glm(X, alpha, beta)
fails with almost 100% treedepth warnings but using
target += poisson_log_glm_lpmf(y | X, alpha, beta)
works well

Description:

Poisson regression on a toy data set using
y ~ poisson_log_glm(X, alpha, beta)
in the model section returns a warning for 3997 (out of 4000) transitions exceeding the maximum treedepth, Rhat is > 100 and neff = 2. Using either
y ~ poisson_log(alpha + X * beta)
or
target += poisson_log_glm_lpmf(y | X, alpha, beta)
results in a high quality fit: Rhat ~ 1.000, neff in the range 2000 -4000. The rstan code for generating the toy data and fitting with the three versions is below.

Reproducible Steps:

set.seed(1)
DF2 <- data.frame(X1 = rnorm(200, 0, 1), X2 = runif(200, -2, 2), X3 = rnorm(200, 1, 2))
DF2 <- DF2 %>% mutate(Y = 0.3 * X1 - 0.15 * X2 + 0.2 * X3 + 1.4)
DF2 <- DF2 %>% mutate(Cnt = rpois(200, lambda =  exp(Y)))

dataList2 <- list(N = nrow(DF2), K = 3, y = DF2$Cnt, X = as.matrix(DF2[, 1:3]))
PoissonMod <- "
data {
    int N; //number obs
    int K; //number of columns in the model matrix
    int y[N]; //response
    matrix[N,K] X; 
  }
parameters {
  real alpha;
  vector[K] beta; //the regression parameters
}
model {  
  alpha ~ normal(0,1.5);
  
  beta ~ normal(0,1);
  
  //y ~ poisson_log(alpha + X * beta); //version 1, works well
  //y ~ poisson_log_glm(X, alpha, beta); //version 2, treedepth failures near 100%
  target += poisson_log_glm_lpmf(y | X, alpha, beta); //version 3, works well
}
"
PoisOut <- stan(model_code = PoissonMod, data = dataList2, verbose = FALSE, control = list(max_treedepth = 10))

RStan Version:

rstan_2.19.2 StanHeaders_2.19.0

R Version:

R version 3.5.2 (2018-12-20)

Operating System:

Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions