I am wondering if it is possible to constrain within Stan the sum of two variables to stay positive. I.e. consider the eight schools example pasted below. Let's assume that the theta variables have to be positive for some reason - then how do you express this in the best way in such a model? One way to do this is to model log(theta), but this is numerically not advisable if some of the parameters are almost 0; resulting in very small log-values. Can I just declare real theta<lower=0> and thats it? How does this affect the sampling performance as many draws of eta will get rejected.
parameters {
real a;
real<lower=0> c; // a + b
}
transformed parameters {
real b;
b <- c - a;
}
- Bob
--
You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
To model variables x, y in (-inf,inf) s.t. (x + y) > 0,
you could use:
parameters {
real<lower=0> x_plus_y;
real x;
}
transformed parameters {
real y;
y <- x_plus_y - x;
}
You can use other parameters in the bounds. So you could
also do this:
parameters {
real x;
real<lower=-x> y;
}
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/JI6yrSZz_Xg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
theta <- 0.0;
for (i in 1:N) {
theta <- theta + ( ( gain[i] ^alpha - 1.0) / alpha - (lambda * loss[i]^beta - 1.0 ) / beta ) * p^gamma / (p^gamma + (1.0-p)^gamma)^( 1.0 / gamma);
}
data ~ bernoulli_logit( scale_factor * theta )
gamma <- b_sex * sex + b_age * age + b_household_size * household_size
The usual thing to do here is have
On Aug 30, 2014, at 3:01 PM, Katherine Grace Jonas <katherine....@gmail.com> wrote:In transformed data and transformed parameters, the constraints are just consistency tests.
> The constraint is essentially an ordering constraint. The model is an graded response IRT model, in which category thresholds are decomposed into a item-specific and person-specific component. The item thresholds can be declared as an ordered vector. The person components are not necessarily ordered, but the sum of the person and item components is an ordered vector. So each person component depends on the distance between item thresholds and the adjacent person component. For example, if the minimum distance between two item thresholds is z, and the person components of those two thresholds are x and y, respectively, then x < z + y.
>
> I've tried declaring a (person x item x category) array of ordered vectors, but it becomes prohibitively large. Declaring the array as a local variable would work, but it looks like local variables need to be basic variable types.
For parameters, they implicitly perform a transform to unconstrained representations
and include the log Jacobian in the log probability function.
> It's tricky, but I think the constraint is coming from a reasonable assumption: that individuals may differ in the extent to which they are willing to endorse "good" versus "very good," (or some similar categories), but that those tendencies do not change the rank ordering of categories.Does each person use the same regression coefficients to produce
a latent "quality" score and then just have different cutpoints?
Otherwise, I don't see how you could maintain the same ordering across
items.
I don't even see how that'd make sense in a context like grading stage of
tumor --- two different doctors might order two tumor images differently
in terms of cancer stage.
And if you look at something like the Netflix challenge data
with customer ratings, there was wildly different orderings among
customers of movies.
parameters {
ordered[K-1] c_i[I];
ordered[K-1] c_ni[N,I];
...other parameters...
}
model {
...prior on item cutpoints...
for (n in 1:N) {
for (i in 1:I) {
for (k in 1:(K-1)) {
c_ni[n,i,k] ~ normal(c_i[i,k],c_n_sigma[k]);
}
}
}
c_n_sigma ~ cauchy(0,2.5);for (n in 1:N) { for (k in 1:(K-1)) { segment(c_ni[n],1,I-1)[k] ~ normal(0,c_n_sigma[k]) + col(c_i,k); }
} for (n in 1:N)
c[n] ~ normal(mu_c, sigma_c);
If two vectors are both ordered and you add them, the result's
still ordered.
- Bob
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/JI6yrSZz_Xg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
It's only hard to program because we don't allow vectors
in the declaration. Adding them is on the to-do list.
That would allow:
vector[K] a;
vector<lower=-a>[K] b;