Error in stanc(model.code, model.name) :
Failed to parse Stan model 'anon_model' and error message provided as:
LOCATION: file=input; line=22, column=40
y[n] ~ categorical(softmax(beta*x[n]));
^-- here
DIAGNOSTIC(S) FROM PARSER:
no matches for function name="softmax"
arg 0 type=vector
expression is ill formed
Parser expecting: <eps>
library(rstan)
scode <- "
data {
int<lower=0> N;
int<lower=0> D;
int<lower=0> K;
int<lower=1,upper=K> y[N];
vector[D] x[N];
}
parameters {
matrix[K,D] beta;
}
model {
for (k in 1:K)
for (d in 1:D)
beta[k,d] ~ normal(0,5);
for (n in 1:N)
y[n] ~ categorical(softmax(beta*x[n]));
}
"
y = c(1,2,3,3,1,1,3,2,1,1)
x = c(5,6,8,9,6,3,10,6,6,1)
N = length(y)
D = 1
K = 3
dat = list(x=x,y=y,K=K,D=D,N=N)
s.f <- stan(model.code = scode,data=dat , n.inter = 1000, n.chains = 1, verbose = FALSE)
argument to variance must have size >= 2; found v.size()=1