PARSER EXPECTED: <expression assignable to left-hand side>

Below is my model, however, when I run it, always showed that

Cannot assign to variable outside of declaration block; left-hand-side variable origin=parameter
error in ‘model49df3845277a_simulation_v4’ at line 24, column 13

22:   target += log(normal_cdf( x1[n] , alpha, sigma) - normal_cdf( x2[n] , alpha, sigma));     // interval censored titer
23: for (n in 1:N)
24:   theta[n] = inv_logit(b_0 + b_titer * x1[n]);  // infection rate
                ^
25: for (n in 1:N)

PARSER EXPECTED:
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model ‘simulation_v4’ due to the above error.

data {
int<lower=0> N;
real<lower=0> x1[N];
real<lower=0> x2[N];
int<lower=0,upper=1> output[N];
}
parameters {
real alpha;
real<lower=0> sigma;
real theta;
real b_0;
real b_titer;
}
model {
alpha ~ normal(0,10);
sigma ~ cauchy(0,10);
theta ~ cauchy(0,10);
b_0 ~ cauchy(0,10);
b_titer ~ cauchy(0,10);
for (n in 1:N)
target += log(normal_cdf( x1r[n] , alpha, sigma) - normal_cdf( x2[n] , alpha, sigma));
for (n in 1:N)
theta[n] = inv_logit(b_0 + b_titer * x1[n]);
for (n in 1:N)
target += bernoulli_lpmf(output[n] | theta[n]);
print(alpha, sigma, theta, b_0, b_titer);
}

You declare theta as real theta in the parameters block, i.e. a single real number. In the model block you say theta[n] = inv_logit(b_0 + b_titer * x1[n]); which implies theta is a vector. You probably need to change the way theta is defined in the parameters block.

yes, it’s true, but I change

real theta;

as

vector[N] theta;

it still doesn’t work

vector[N] theta = inv_logit(b_0 + b_titer * x1);

needs to be in the transformed parameter block. See Chapter 6 in the Stan Reference Manual (version 2.17) for an explanation of the different blocks.

oh, I just debug successfully, thanks, I put them together, I think you are right, theta shouldn’t belong to parameters block.

Thanks all