Hi all (especially Bob). During the times we've discussed discrete sampling, one possibility we've talked about is to work with latent continuous variables.
I think we could just write the models as is, but we can see.
Ben,No, what you're saying is different from what I'm saying. In your first example, I would _keep_ the linebinary ~ bernoulli(inv_logit(mu));and then just augment it withreal z[N];
simplex[K] p;real<lower=0,upper=1> cutpoints[K]
cutpoints <- cumulative_sum ℗etc.
I don't think Stan would need to use a truncated logistic distribution in this case. Couldn't it just define z and p and go from there?
data {
int<lower=1> K;
int<lower=K> N;
matrix[N,K] X;
int y[n];
int<lower=0,upper=1> R[N];
}
transformed data {
vector[N] lower;
vector[N] upper;
int n_miss;
n_miss <- N - sum(R);
for(i in 1:N) {
if(R[i] == 1) {
lower[i] <- 0.0;
upper[i] <- Infinity();
}
else {
lower[i] <- -Infinity();
upper[i] <- 0.0;
}
}
}
parameters {
vector<lower=lower,upper=upper>[N] z; # does not work now
vector[K] beta;
}
model {
z ~ normal(X * beta, 1)[lower,upper];
beta ~ cauchy(0,5);
// maybe a likelihood for R too
}
transformed data {
vector[N] lower;
vector[N] upper;
int n_miss;
n_miss <- N - sum(R);
for(i in 1:N) {
if(R[i] == 1 && y[i] == 1) {
lower[i] <- 0.0;
upper[i] <- Infinity();
}
else if(R[i] == 1 && y[i] == 0) {
lower[i] <- -Infinity();
upper[i] <- 0.0;
}
else { // missing y[i]
lower[i] <- -Infinity();
upper[i] <- Infinity();
}
}
}
Technically, I don't think it would be that hard to add
vectors of lower and upper bounds. They're not too hard
to do by hand if they're in vectors, but not something we
probably want users messing with on a regular basis.
parameters {
matrix<vector_of_restrictions>[N,3] Z;
}
parameters {
matrix[N,3] Z;
}
model {
matrix[N,3] ZZ;
ZZ <- Z;
for(i in 1:N) {
if(y[i] == 1) {
if(Z[i,2] > Z[i,3]) {
ZZ[i,1] <- exp(Z[i,1]) + Z[i,2];
}
else {
ZZ[i,1] <- exp(Z[i,1]) + Z[i,3];
}
lp__ <- lp__ + Z[i,1]; // Jacobian
}
if(y[i] == 2) {
...
}
if(y[i] == 3) {
...
}
}
}
BenI'll have to take a look, but my first thought is that you may be making it more difficult than you need to be. You're expressing the model using these truncated distributions (the way that Bugs does latent variables). I think it will be ok to express the model using untruncated distributions. As I see it, the full joint distribution is untruncated; the truncation comes conditional on the discrete variable, but that will come out naturally in the model. I could be missing something, though (of course).A
theta ~ normal(x * beta,1);
Yes, but, in my formulation, z has unrestricted support, its uniformly distributed on (0,1).
No need to reject z outside of (0,1). Stan automatically does a logit transformation on parameters bounded at both ends.
Sorry for the empty message. What I meant was,
"what Matt said". The step functions essentially
cut off the derivative information from propagating
through the step function. So if you use the resulting
discrete parameter, information from its use (such
as as a mixture component), doesn't get back.
- Bob
On 5/3/13 2:39 AM, Bob Carpenter wrote:
On 5/2/13 6:56 PM, Andrew Gelman wrote:
Hi all (especially Bob). During the times we've discussed discrete sampling, one possibility we've talked about is to
work with latent continuous variables. We've talked about this as a possibility but I always had the sense that it
might be tricky to get the distributions right.
But, thinking about it, I think it's close to trivial. For simplicity, suppose our model has only two parameters: a
N-dimensional discrete parameter a (which can take on the values 1,2,…,K) and an M-dimensional continuous parameter
--
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.