cbergmeir / Rlgt

Rlgt is an R package for Bayesian Exponential Smoothing
20 stars 11 forks source link

add dummy prior #2

Closed pochoi closed 5 years ago

pochoi commented 5 years ago

Leaving unconstrained parameters innovSizeInit, regCoef and regOffset no prior in model block, it is implicitly assuming uniform (improper) prior. Theoretically it would not affect HMC. However, Stan does produce tons of divergent transitions. Set dummy priors to avoid it.

Example:

library(rstan)

without_prior_code =
'data {
  int<lower=0> N;
  vector[N] y;
}
parameters {
  real mu;
  real<lower=0> dummy;
}
model {
  y ~ normal(mu, 1);
}
'
model_without_prior = stan_model(model_code = without_prior_code)

set.seed(123)
y = rnorm(100, 2.3, 1)
data = list(N = length(y), y = y)

samples_without_prior = sampling(object = model_without_prior, 
                                 data = data, chains = 1, seed = 123)
check_hmc_diagnostics(samples_without_prior)

It would produce

Divergences:
758 of 1000 iterations ended with a divergence (75.8%).
Try increasing 'adapt_delta' to remove the divergences.

Tree depth:
0 of 1000 iterations saturated the maximum tree depth of 10.

Energy:
E-BFMI indicated no pathological behavior.

Btw, the original stan files has mixing tabs and spaces. That's why the diff is displayed in github with very ugly spacing.

cbergmeir commented 5 years ago

Many thanks, I've just merged this.