Transformed parameters omitted in output if input parameters omitted?

I want to omit the constituent parameters beta_ord and beta_unord from the output, but want to retain the matrix of parameters beta that contains the former. For some reason, despite the sampling argument indicating that only those are supposed to be omitted, beta is also omitted from the output. I wasn’t able to replicate this issue in a toy example.

$pars
[1] "beta_un"  "beta_ord" "gamma"    "delta"    "lambda"  
 sampling_args <- set_sampling_args(
   object = stanfit,
   pars = pars,
   include = FALSE,
   user_dots = list(...),
   user_adapt_delta = adapt_delta,
   data = standata,
   show_messages = FALSE)
 stanfit <- do.call(rstan::sampling, sampling_args)

the relevant Stan code


parameters {
  // Discrete state model
  simplex[K] pi1[N];                 // initial state probabilities
  simplex[K] A[N_, K];              // tvtp coefficient (only initialization)

  // Continuous observation model
  ordered[K] phi;                    // observation AR
  vector[Mx_d_] alpha;                 // continuous observation model coefficients
    // ordering
  vector[K] beta_un[Mx_e_un];
  ordered[K] beta_ord[Mx_e_ord];
  real<lower=0> sigma;               // observation standard deviations
}

transformed parameters {
  vector[K] logalpha[T, N];
  // create beta matrix from components
  matrix[Mx_e_, K] beta;
  {
    int count_ordered = 1;
    int count_unordered = 1;
    for (m in 1:Mx_e_){
      if (order_x_e[m]) {
        beta[m] = beta_ord[count_ordered]'; count_ordered += 1;
      } else {
        beta[m] = beta_un[count_unordered]'; count_unordered += 1;
      }
    }
  }

Some background for others who may know more.

    pars: A vector of character strings specifying parameters of
          interest.  The default is ‘NA’ indicating all parameters in
          the model.  If ‘include = TRUE’, only samples for parameters
          named in ‘pars’ are stored in the fitted results. Conversely,
          if ‘include = FALSE’, samples for all parameters _except_
          those named in ‘pars’ are stored in the fitted results.

@Merlin_Heidemanns, you confirm what happens if you specify include=T and list out the fields you want? That could be an easy work around if you haven’t yet tried it. This may be a bug.

1 Like

Thanks! Embarassingly enough it turned out to be the case that beta just got buried in the output because logalpha is so big that it doesn’t print all parameters. Hence, it was there all along but I didn’t see it.