Skip to content

Commit

Permalink
add optional lower bound on diag
Browse files Browse the repository at this point in the history
  • Loading branch information
ericward-noaa committed Jul 18, 2022
1 parent 1ccac73 commit 7100489
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 236 deletions.
4 changes: 4 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @param varss Boolean, whether to fit a VARSS model (defaults to true) or VAR model
#' @param b_diag A 2 element list specifying the mean and sd of a normal prior on the diagonal elements.
#' These elements are `mu` (default= 0.7) and `sd` (default = 1)
#' @param b_diag_min The minimum value of the B diagonal, defaults to 0. Setting this lower,
#' e.g. -1, allows for oscillations
#' @param b_offdiag A 2 element list specifying the mean and sd of a normal prior on the off-diagonal elements.
#' These elements are `mu` (default= 0) and `sd` (default = 1)
#' @param off_diag_prior Character string denoting which prior to use for
Expand Down Expand Up @@ -130,6 +132,7 @@ fit <- function(data,
est_trend = FALSE,
varss = TRUE,
b_diag = list(mu = 0.7, sd =1),
b_diag_min = 0,
b_offdiag = list(mu = 0, sd = 1),
off_diag_prior = c("normal", "student-t", "laplace", "hs","normal_pp"),
sigma_pro = list(mu = 0, sd = 1),
Expand Down Expand Up @@ -276,6 +279,7 @@ fit <- function(data,
b_sd = b_offdiag$sd,
b_mu_diag = b_diag$mu,
b_sd_diag = b_diag$sd,
b_diag_min = b_diag_min,
nu_known = nu_known,
sigma_proc_sd = sigma_pro$sd,
sigma_proc_mu = sigma_pro$mu,
Expand Down
3 changes: 2 additions & 1 deletion inst/stan/varlasso.stan
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ data {
real yy[n_pos]; // data
//real b_mu[n_off]; // prior on mean of offdiagonal
real b_sd[n_off]; // prior on sd offdiagonal
real b_diag_min; // minimum value of estimated B diag
real b_mu_diag[n_spp];// prior on mean of diagonal
real b_sd_diag[n_spp];// prior on sd of diagonal
real fixed_r[n_spp]; // fixed_r is optional, will be all 0s if estimated
Expand Down Expand Up @@ -106,7 +107,7 @@ parameters {
real<lower=0> sigma_obs[est_sigma_obs * n_r];
vector<lower=0>[est_sigma_scale] sigma_scale; // variance for shrinkage / hierarchical B off diags
vector[n_off] B_z; // off-diags of B, in normal (0,1) space
vector<lower=0,upper=1>[n_spp] Bdiag; // diag of B
vector<lower=b_diag_min,upper=1>[n_spp] Bdiag; // diag of B
vector[n_spp] x0;
vector[est_trend*n_spp] U;
vector<lower=2>[est_nu] nu; // student-t df parameters for Student-t priors
Expand Down
4 changes: 4 additions & 0 deletions man/fit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7100489

Please sign in to comment.