This is on windows 10. PYSTAN was installed using conda which installed python 2.18.00 and libpython_2,1 . ( Incidentally installing pystan with pip fails with " NameError: name ‘logger’ is not defined" ) but at least conda install works. Anyway…
The program is :
import os
import pystan
sm = pystan.StanModel(file=“C:/Users/N903193/Documents/Claims/model_np_utf8.txt”)
When I run this python program via Spyder I get the following error:
ValueError: Failed to parse Stan model ‘anon_model_b0ce2e73ab82ec9cfa804312d1756e6e’. Error message:
PARSER EXPECTED: whitespace to end of file.
FOUND AT line 1:
data {
int<lower=0> N;
int<lower=0> J; # number of counties
int<lower=0,upper=J> county[N];
vector[N] y;
}
parameters {
vector[J] a; # county intercepts
real mu_a;
real<lower=0> sigma_a;
real<lower=0> sigma_y;
}
transformed parameters {
vector [N] y_hat;
}
model {
//vector[N] y_hat1;
real y_hat1;
mu_a ~ normal(0, 1);
sigma_a ~ cauchy(0, 2.5);
sigma_y ~ cauchy(0, 2.5);
a ~ normal (mu_a, sigma_a);
for (i in 1:N) y_hat1[i] = a[county[i]];
// y_hat[1] = a[county[1]];
y ~ normal(y_hat1, sigma_y);
}
The input file contents are as described in the error message. I created the file in windows notepad and saved it wikth UTF-8 encoding.
When I use an input file created by windows notepad and save with ANSI encoding or use a python three quotes string with the input program I get a different error
ValueError: Failed to parse Stan model ‘anon_model_fcc9006ee9df993afd6bf34d447ecdda’. Error message:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Warning (non-fatal): Comments beginning with # are deprecated. Please use // in place of # for line comments.
Warning (non-fatal): Comments beginning with # are deprecated. Please use // in place of # for line comments.
Unknown variable: real
variable “real” does not exist.
error in ‘model_np_ansi.txt’ at line 21, column 5
19:
20: //vector[N] y_hat1;
21: real y_hat1;
If I save the code in windows notepad as a unicode or a unicode bigendian file I get this error :
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xfe in position 0: invalid start byte