-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow bounds on fixed effect priors #28
Comments
@nicholasjclark - I'm curious that in the meantime while this feature is considered/developed, are there any "hacks" in mvgam akin to this one in brms by which uses can enforce bounds on parameters? I believe the answer is no, but I figured I would not assume and ask 😄 I was checking out the forecasting course you have on your github, and I did see that mvgam does accept brms priors which have implemented |
Hi @A108669, unfortunately this can't be done currently with the |
Thank you, @nicholasjclark, for all the help. If you are open to nudging me the right way, I would greatly appreciate it. In a dummy example (code below), I was able to, per your instructions, write the
Any help on this piece would be appreciated. I'm assuming I need to somehow inject I found code here that shows how to pull the stan code from library(mvgam)
library(cmdstanr)
set.seed(1000)
simdat <- sim_mvgam(T = 100,
n_series = 1,
trend_model = 'GP',
prop_trend = 0.75,
family = poisson(),
prop_missing = 0.10)
form = formula(y ~ 1 + time)
mod1 <- mvgam(form,
trend_model = 'None',
data = simdat$data_train,
backend="cmdstanr",
use_stan = TRUE,
run_model = FALSE)
model_data <- mod1$model_data
stan_file_path <- write_stan_file(mod1$model_file)
#** Edit stan_file_path in editor **#
# Add <upper/lower> to parameters
#
# parameters {
# // raw basis coefficients
# vector [num_basis] b_raw;
# }
#
# parameters {
# // raw basis coefficients
# vector<lower=0> [num_basis] b_raw;
# }
# Also can bound via the prior such as b_raw[2] ~ student_t(3, 0, 2) T[,0];
cmd_mod <- cmdstan_model(stan_file_path,
stanc_options = list('canonicalize=deprecations,braces,parentheses'))
cmd_mod$print()
fit <- cmd_mod$sample(data = model_data,
chains = 4,
refresh = 100)
fit$summary()
posterior_samples <- fit$draws(format="draws_matrix") |
Hi @A108669, sorry about the slow reply. Good to see that you've worked out all the modification and sampling steps. As you have probably notices, Once you've done the sampling, there are really just a few steps that use internal functions to get the object in the right structure. Here is your example completed with these steps:
|
@nicholasjclark - Thank you a ton for the example. Extremely helpful! |
Incorporating bounds on fixed effect priors can be done using the truncation syntax i.e.
b[1] ~ normal(0, 1)T[0, ]
This would require checks on inits to ensure they respect the correct bounding, but would be a useful feature to allow more domain expertise to be included in the prior
The text was updated successfully, but these errors were encountered: