Forward Sampling Examples

84 views
Skip to first unread message

Michael Betancourt

unread,
Aug 1, 2013, 11:39:40 AM8/1/13
to stan...@googlegroups.com
Peter,

Do you have any good examples of a model with forward sampling?  Additionally, a list of the implemented random variables would be handy (is there a branch where they have been doc'd?).

Thanks.

-Mike

Peter Li

unread,
Aug 1, 2013, 11:50:17 AM8/1/13
to stan...@googlegroups.com, Li.Pe...@gmail.com
I'm not sure what you mean by forward sampling, but the ARM models that
I've added are all in the branch feature/arm. I've been working on the
doc (README files for each chapter and the wiki
https://github.com/stan-dev/stan/wiki/ARM-Models-Sorted-by-Chapter), but
haven't gotten to adding doc for most of the multilevel models (some of
which Alexij has done but still needs to upload).


Peter
> --
> You received this message because you are subscribed to the Google
> Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Michael Betancourt

unread,
Aug 1, 2013, 11:58:09 AM8/1/13
to stan...@googlegroups.com
I'm referring to generating random quantities in the "generated quantities" block, a la posterior predictive checking.  In other words is this the general procedure?

parameters {
  real mu;
}

model {
  mu ~ normal(0, 1);
}

generated_quantities {
  real nu;
  nu ~ normal_rng(mu, 1);
}

And have all of the distributions in Stan been rng'd, or are there still a few exceptions?


To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.

Peter Li

unread,
Aug 1, 2013, 12:06:34 PM8/1/13
to stan...@googlegroups.com, Li.Pe...@gmail.com

On 8/1/13 11:58 AM, Michael Betancourt wrote:
I'm referring to generating random quantities in the "generated quantities" block, a la posterior predictive checking.  In other words is this the general procedure?

I believe so. There are a few examples with simple models in src/models/ARM/Ch.3 and src/models/ARM/Ch.4 in the feature/ARM branch like https://github.com/stan-dev/stan/blob/feature/ARM/src/models/ARM/Ch.3/kidiq_prediction.stan.

parameters {
  real mu;
}

model {
  mu ~ normal(0, 1);
}

generated_quantities {
  real nu;
  nu ~ normal_rng(mu, 1);
}

And have all of the distributions in Stan been rng'd, or are there still a few exceptions?
I believe that most of the distributions support rng, but some extensions of distributions such as bernoullie_logit do not support rngs. Below is a more conclusive list (from test/gm/model_specs/compiled/rng.stan) where // indicates that the rng is not yet supported.

  n <- bernoulli_rng(0.5);
  // n <- bernoulli_logit_rng(0.0);
  n <- binomial_rng(15,0.3);
  // n <- binomial_logit_rng(15,-1.2);
  n <- beta_binomial_rng(42, 0.3, 1.9);
  n <- hypergeometric_rng(5,4,9);
  n <- neg_binomial_rng(1.2,3.9);
  n <- ordered_logistic_rng(1.9,theta);
  n <- poisson_rng(2.7);
  // n <- poisson_log_rng(2.7);

  n <- categorical_rng(theta);
  ns <- multinomial_rng(theta,20);

  z <- normal_rng(0,1);
  z <- exp_mod_normal_rng(0.2,1.9,1.5);
  z <- skew_normal_rng(1.1, 2.3, 9.8);
  z <- student_t_rng(3,1,2);
  z <- cauchy_rng(-1.0,2.9);
  z <- double_exponential_rng(1.0,3.8);
  z <- logistic_rng(1.0,3.8);
  z <- gumbel_rng(-1.0,2.31);
  z <- lognormal_rng(-1.0, 3.6);
  z <- chi_square_rng(4.1);
  z <- inv_chi_square_rng(4.1);
  z <- scaled_inv_chi_square_rng(1.0, 3.0);
  z <- exponential_rng(2.9);
  z <- gamma_rng(1.0, 3.0);
  z <- inv_gamma_rng(0.1,0.1);
  z <- weibull_rng(1.0,2.0);
  z <- pareto_rng(0.1, 1.5);
  z <- beta_rng(110.0, 250.1);
  z <- uniform_rng(-1.0, 1.0);
  z <- rayleigh_rng(1.0); 
 
  theta <- dirichlet_rng(alpha);
  v <- multi_normal_rng(mu,Sigma);
  // v <- multi_normal_prec_rng(mu,Sigma);
  // v <- multi_normal_cholesky_rng(mu,L);
  v <- multi_student_t_rng(3.0,mu,Sigma);
  Sigma <- wishart_rng(3.0,Sigma);
  Sigma <- inv_wishart_rng(3.0,Sigma);
  Sigma <- lkj_corr_rng(3,2.5);
  L <- lkj_corr_cholesky_rng(3,3.0);
  // DEPRECATE:  Sigma <- lkj_cov_rng(Sigma, mu, alpha, 2.0);
 


On Thu, Aug 1, 2013 at 4:50 PM, Peter Li <li.pe...@gmail.com> wrote:
I'm not sure what you mean by forward sampling, but the ARM models that I've added are all in the branch feature/arm. I've been working on the doc (README files for each chapter and the wiki https://github.com/stan-dev/stan/wiki/ARM-Models-Sorted-by-Chapter), but haven't gotten to adding doc for most of the multilevel models (some of which Alexij has done but still needs to upload).


Peter


On 8/1/13 11:39 AM, Michael Betancourt wrote:
Peter,

Do you have any good examples of a model with forward sampling?  Additionally, a list of the implemented random variables would be handy (is there a branch where they have been doc'd?).

Thanks.

-Mike
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.

Michael Betancourt

unread,
Aug 1, 2013, 12:09:36 PM8/1/13
to stan...@googlegroups.com
Great, thanks!
Reply all
Reply to author
Forward
0 new messages