Tracking individual observation estimates

I’m using rstan Version 2.21.2.

I have my code and data for the model as follows:

y <- c(8, 35, 31, 19, 38, 47, 44, 44, 29, 18);
m <- c(37, 450, 456, 61, 218, 722, 664, 481, 76, 480);
  data{
    int <lower=1> nm;
    int y[nm];
    int m[nm];
  }
  
  parameters {
    real lodds;
  }

  transformed parameters {
    real <lower=0, upper=1> p;
    p = 1/(1+exp(-lodds));
  }

  model{
    // likelihood & prior 
    y ~ binomial(m, p);
  }

After fitting the model, I get a estimate for p. I want to be able to track my p’s as they iterate over the different observations of y and m. I see that I can’t make a parameter/ transformed parameter an array. What can I do?

Ideally I would have an model output as follows:

p1 : <estimate>
.
.
.
p10: <estimate>

Hi Eli,

You’ve only requested one odds parameter, so there won’t be a per-observation odds:

  parameters {
    real lodds;
  }

If you wanted one for each observation, then you would request a vector of odds:

  parameters {
    vector[nm] lodds;
  }

Additionally, instead of constructing p in the transformed parameters block, you can just use the binomial_logit distribution directly:

  model{
    // likelihood & prior 
    y ~ binomial_logit(m, lodds);
  }
2 Likes