Adding a varying intercept for mu in beta_proportion model when mu is a vector of parameters

Hi, before I address the question at hand, let me point out a few potential points of confusion.

  • The variable observed_countin your post seems to be intended to represent the sample size. However, intuitively, I would understand observed_count to refer to the number of positive observations in a sample. Your R code to simulate fake data seems to suggest that observed_count is indeed the total sample size. I would advise to rename the variable accordingly.
  • In your simulation code, `true_proportion’ can simply be drawn with bounds at 0 and 1. None of this “0.00001” is necessary.
  • The specification of shape1 and shape2 in your simulation code is flawed. Assuming a uniform prior for the true but known proportion, see here for the definition of the shape parameters is. Note that the “+1” term should happen after multiplication.
  • None of lines with “ifelse” are needed. If zero of observation are positive, the true proportion simply follows a beta distribution with shape parameters 1 and [sample size + 1] (still assuming a uniform prior).
  • In your stan model, you set kappa toobserved_count + 1, which means that you are assuming that the prior for your unknown true_proportionis a beta distribution with both shape parameters set to 0.5 (instead of 1.0 as suggested here). In contrast, you would assume a beta prior with shape parameters of 1.0 and 1.0, this would correspond to kappa = total sample size + 2. After all, kappa = shape1 + shape2.
  • It is not entirely clear from your description what you are thinking of in terms of the generative process for the observed counts and how these groups of counts arise. Either way, if you want to define a hierarchical model for how the binomial counts arise, you are easier off just specifying a hierarchical logistic regression model with normal distributions for the group-level effects. The estimated log-odds of positives in each group level and each set of samples within a group can then be simply translated to a proportion with the inverse logit transformation.