As a true beginner to Stan I’ve been working on a very basic probit model. It works well, please see R code and Stan code below.
However, I want to extend the model where [0,1] is a latent state reflecting the probability of reaching a level with a specific height. Next to estimating the variables of the probit model, I also want to include the estimates of the height of the level (in simulated example below 3 +/- measurement noise).
How do I need to extend the current Stan model to efficiently add the “level_height” and “noise” term?
Thank you very much! Thomas
R code:
# Number of attempts
N <- 300
# Input parameters
alpha <- 10
beta <- 1.5
level_height <- 3
# Random noise
e<-0.1
noise <- e*runif(N)-e/2
# Simulation of region where level becomes activated
x_val <- alpha + (6*beta*runif(N)-3*beta)
# Active or inactive level
# Only 0's or 1's
y_act <-pnorm(x_val,alpha,beta)>runif(N);
# Add height of level
# Includes level height + noise
y_level <-y_act*level_height + noise
Stan code (works well for y_act
):
data {
int<lower=1> N;
vector[N] x;
int<lower=0,upper=1> y[N];
}
parameters {
real<lower=0> alpha;
real<lower=0.1,upper=10>beta;
}
model {
vector[N] eta;
eta = 1/beta * (x - alpha);
alpha ~ normal(0,10);
beta ~ cauchy(0,10);
for (i in 1:N)
{
y[i] ~ bernoulli(Phi(eta[i]));
}
}
Stan code (starting point for “y_level”):
data {
int<lower=1> N;
vector[N] x;
vector[N] y;
}
parameters {
real<lower=0> alpha;
real<lower=0.1,upper=10>beta;
real<lower=0.1,upper=10> levelheight;
real<lower=0.01> noise;
}
model {
vector[N] eta;
eta = 1/beta * (x - alpha);
alpha ~ normal(0,10);
beta ~ cauchy(0,10);
levelheight ~ normal(0,10);
noise ~ cauchy(0,5);
for (i in 1:N)
{
y[i] ~ bernoulli(Phi(eta[i]));
}
}