私はスタンを学んでいて、いくつか質問があります。私はスタンで注文されたプロビットモデルをやろうとしています。いくつか質問があります。最初に、以下のモデルはエラー メッセージをスローしますStan model does not contain samples.
。
次に、モデルを識別したい制約をスタンに伝えるにはどうすればよいですか? 現在のところ、場所は不明です。tau
s の 1 つを特定の値 (たとえば 0)に設定するように stan に伝えたいのですが、その方法がわかりません。
data{
int<lower=1> N; // number of obs
int<lower=3> J; // number of categories
int<lower=2> K; // num of predictors
int y[N]; // outcome var
matrix[N, K] x; // predictor vars
}
parameters{
ordered[J-1] tau; // thresholds
vector[K] beta; // beta coefficients
}
model{
vector[J] theta;
vector[N] xB;
beta ~ normal(0, 100);
xB <- x*beta;
for(n in 1:N){
theta[1] <- 1 - Phi(xB[n] - tau[1]);
for(j in 2:J-1)
theta[j] <- Phi(xB[n]-tau[j-1]) - Phi(xB[n]-tau[j]);
theta[J] <- Phi(xB[n] - tau[J-1]);
y[n] ~ categorical(theta);
}
}
編集
私が呼んだRコードは次のとおりです。
stan_data <- list(N = dim(insurance)[1], # 1000
K = dim(insurance)[2], #5
J = length(table(insurance$spend)), #3
y = insurance$spend, # vector of length N where each element is 0, 1, or 2
x = my_xmatrix) # matrix of dim 1000, 5
mcmc_oprobit <- stan(file="stan/oprobit.stan",
data = stan_data)