I know it has to be > 0, but didn't understand why it was
originally constrained to > 0.1.
Especially given that output I'm guessing your problem
is constraining the regression coefficients > 0. I'm guessing
if you remove that constraint, it'll work. When you add
a constraint and the value wants to be outside the constraint,
the draws pile up at the boundary.
Our recommendation is *always* to fit simulated data first to
see if the model works as expected. If the model fits simulated
data but nor real data, it typically indicates model misspecification.
I'm curious as to why you'd want to use beta regression rather
than a linear regression on logit(y) vs. x.
I was curious about beta regression (Ben and crew are adding it
to RStanArm, I believe), so I went and did the simulation myself
and realized that this model is very finicky.
data {
int<lower=1> N;
real<lower=0,upper=1> y[N];
vector[N] x;
}
parameters {
real<lower=0> phi;
real alpha;
real beta;
}
model {
for (n in 1:N) {
real mu;
mu = inv_logit(alpha + beta * x[n]);
y[n] ~ beta(mu * phi, (1 - mu) * phi);
}
}
I just used flat uniform priors here; if you do use a Cauchy and
expect high phi values, you should adjust the scale accordingly.
Here's the R simulation and fit code; I added some control to avoid
divergences.
inv_logit <- function (u) 1 / (1 + exp(-u));
logit <- function(v) log(v / (1 - v));
N <- 500;
alpha <- -0.5;
beta <- 1.9;
phi <- 57.4;
x <- rnorm(N);
y <- rep(NA, N);
for (n in 1:N) {
mu <- inv_logit(alpha + beta * x[n]);
y[n] <- rbeta(1, mu * phi, (1 - mu) * phi);
}
library(rstan);
fit <- stan("beta-reg.stan", data=c("N", "y", "x"),
control=list(stepsize=0.01, adapt_delta=0.95));
You can see that it fits just fine:
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
phi 57.12 0.06 3.45 50.63 54.83 57.01 59.30 64.02 2864 1
alpha -0.50 0.00 0.01 -0.53 -0.51 -0.50 -0.49 -0.47 2733 1
beta 1.89 0.00 0.02 1.85 1.88 1.89 1.90 1.93 2692 1
lp__ 902.42 0.03 1.22 899.11 901.92 902.74 903.29 903.73 2093 1
Recall that the simulated params were:
alpha <- -0.5;
beta <- 1.9;
phi <- 57.4;
Hope that helps.
- Bob