gerasy1987 / hiddenmeta

R package for diagnosis and meta-analysis of studies that measure size and prevalence of hard-to-reach populations
http://gsyunyaev.com/hiddenmeta/
MIT License
1 stars 1 forks source link

Stan #21

Closed gerasy1987 closed 3 years ago

gerasy1987 commented 3 years ago

My RStan stopped working while debugging, so seeking help:

macartan commented 3 years ago

note:

TRANSLATING MODEL '5782c87cfbed0e1e3b2712a4c26498fc' FROM Stan CODE TO C++
CODE NOW.
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Duplicate declaration of variable, name=observed1; attempt to redeclare as
int in data; previously declared as int[ ] in data
 error in 'model1570384e77ed_5782c87cfbed0e1e3b2712a4c26498fc' at line 6,
column 30
  -------------------------------------------------
     4: int<lower=0,upper=N> n1;
     5: int<lower=0,upper=N> observed1[n1];
     6: int<lower=0,upper=N> observed1;
                                     ^
     7: int<lower=0,upper=N> observed1[n1];
  -------------------------------------------------

Error in stanc(file = file, model_code = model_code, model_name =
model_name,  :
  failed to parse Stan model '5782c87cfbed0e1e3b2712a4c26498fc' due to the
above error.

But:

> get_meta_stan(stan_data)
[1] "data {\nint<lower=0> N;\nint<lower=0> K;\nint<lower=0,upper=N>
n1;\nint<lower=0,upper=N> observed1[n1];\nint<lower=0,upper=N>
observed1;\nint<lower=0,upper=N> observed1[n1];\nint<lower=0,upper=N>
observed1[n1];\nint<lower=0,upper=N> observed1;\nint<lower=0,upper=N>
observed1;\nint<lower=0,upper=N> observed1;\nint<lower=0,upper=N>
observed1;\nreal<lower=0> est1[n1];\nreal<lower=0>
est1_se[n1];\n}\nparameters {\nreal error[K];\nvector<lower=0>[N]
alpha;\n}\nmodel {\ntarget += normal_lpdf(est1| error[1] +
alpha[observed1], est1_se);\nerror ~ normal(0, 100);\nalpha ~ normal(0,
100);\n}"
> cat(get_meta_stan(stan_data))
data {
int<lower=0> N;
int<lower=0> K;
int<lower=0,upper=N> n1;
int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;
real<lower=0> est1[n1];
real<lower=0> est1_se[n1];
}
parameters {
real error[K];
vector<lower=0>[N] alpha;
}
model {
target += normal_lpdf(est1| error[1] + alpha[observed1], est1_se);
error ~ normal(0, 100);
alpha ~ normal(0, 100);
}

the line that generates this is (ignoring K):

> paste0("int<lower=0,upper=N> observed", 1, ifelse(.sizes, ";",
paste0("[n", 1, "];")), collapse = "\n")
[1] "int<lower=0,upper=N> observed1[n1];\nint<lower=0,upper=N>
observed1;\nint<lower=0,upper=N> observed1[n1];\nint<lower=0,upper=N>
observed1[n1];\nint<lower=0,upper=N> observed1;\nint<lower=0,upper=N>
observed1;\nint<lower=0,upper=N> observed1;\nint<lower=0,upper=N>
observed1;"

int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1[n1];
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;
int<lower=0,upper=N> observed1;

which: