Hi,
I’m trying to apply censore regression whenever the censor ==1, I use the following code:
# ----------------- CASE VI (testing )
modelWithCensor5= """
data {
int<lower=0> Nobs_train; // Number of total data points
real activation_train[Nobs_train]; // the predictor vector
real y_train[Nobs_train]; // the outcome
real censore[Nobs_train];
int<lower=0,upper=1> run_estimation; // simulate (0) or estimate (1)
}
parameters {
real alpha;
real beta;
real<lower=0> eps;
}
model {
// prior
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
eps ~ normal(0, 10);
// likelihood, which we only evaluate conditionally
for (i in 1:Nobs_train) {
if (run_estimation ==1){
if (censore[i] == 0 ) {
target += normal_lpdf(y_train[i]|alpha + beta * activation_train[i] , eps);
}
else if (censore[i] == 1){
target += normal_lccdf(y_train[i]|alpha + beta * activation_train[i], eps);
}
}
}
}
generated quantities {
vector[Nobs_train] y_tilde;
for(i in 1:Nobs_train) {
y_tilde[i] = normal_rng(alpha + beta * activation_train[i] , eps);
}
}
I run using the following data:
run_estimation = 1
data11 = {'Nobs_train':Nobs_train,
'N_tilde':N_tilde,
'activation_train':activation_train,
'y_train':y_train,
'run_estimation':run_estimation,
'censore':censore,
'N_cens_train':N_cens_train}
fit11 = pystan.stan(model_code = modelWithCensor5, data=data11, iter=1000, chains=4)
print(fit11)
I get the initialization failed error as follows:
RuntimeError Traceback (most recent call last)
<ipython-input-266-e817eaef854e> in <module>()
10
11
---> 12 fit11 = pystan.stan(model_code = modelWithCensor5, data=data11, iter=1000, chains=4)
13 print(fit11)
/usr/local/lib/python2.7/site-packages/pystan/api.pyc in stan(file, model_name, model_code, fit, data, pars, chains, iter, warmup, thin, init, seed, algorithm, control, sample_file, diagnostic_file, verbose, boost_lib, eigen_lib, n_jobs, **kwargs)
400 sample_file=sample_file, diagnostic_file=diagnostic_file,
401 verbose=verbose, algorithm=algorithm, control=control,
--> 402 n_jobs=n_jobs, **kwargs)
403 return fit
/usr/local/lib/python2.7/site-packages/pystan/model.pyc in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs)
724 call_sampler_args = izip(itertools.repeat(data), args_list, itertools.repeat(pars))
725 call_sampler_star = self.module._call_sampler_star
--> 726 ret_and_samples = _map_parallel(call_sampler_star, call_sampler_args, n_jobs)
727 samples = [smpl for _, smpl in ret_and_samples]
728
/usr/local/lib/python2.7/site-packages/pystan/model.pyc in _map_parallel(function, args, n_jobs)
79 try:
80 pool = multiprocessing.Pool(processes=n_jobs)
---> 81 map_result = pool.map(function, args)
82 finally:
83 pool.close()
/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.pyc in map(self, func, iterable, chunksize)
251 '''
252 assert self._state == RUN
--> 253 return self.map_async(func, iterable, chunksize).get()
254
255 def imap(self, func, iterable, chunksize=1):
/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.pyc in get(self, timeout)
570 return self._value
571 else:
--> 572 raise self._value
573
574 def _set(self, i, obj):
RuntimeError: Initialization failed.
Can someone help me, please?
[edit: escaped code]