Questions on Stan coding

638 views
Skip to first unread message

Jing Zhang

unread,
Aug 6, 2015, 1:38:13 PM8/6/15
to Stan users mailing list
I just learnt that Stan is a better choice for multilevel models than jags. I tried to convert JAGS code to Stan, but found the following error message. Can anyone help on this? Thanks a lot. 

variable identifier (name) may not be reserved word
    found identifier=mean

ERROR at line 18

 16:      real alpha[nS];
 17:      real beta[nS,nT];
 18:      real mean[nN];
              ^
 19:      for (i in 1:nN)

PARSER EXPECTED: <identifier>

Here is the JAGS code: 

model{
##### Model
for(i in 1:nN) {
y[i]~dnorm(mean[i],tau)
                mean[i]<-mu+alpha[s[i]]+beta[s[i],t[i]]*(1-equals(1,nT[s[i]]))       #s is subject; t is tumor                   
}

for(j in 1:nS){ 
alpha[j]~dnorm(0,tau1)               
                for(k in 1:nT[j]){
                          beta[j, k]~dnorm(0,tau2)
                }
}
##### Prior
        mu~dnorm(0, 0.001)
tau ~ dgamma(0.01,0.01)
        tau1 ~ dgamma(0.01,0.01)
        tau2 ~ dgamma(0.01,0.01)
}

Here is the Stan code: 

data {
  int<lower=0> nN; // number of obs
  int<lower=0> nS; // number of sub
  int<lower=0> nT; // number of tumor
  real y[nN]; 
  int<lower=0> s[nN]; 
  int<lower=0> t[nN]; 
}
parameters {
  real mu; 
  real<lower=0> sigma;
  real<lower=0> sigma1;
  real<lower=0> sigma2;
}
transformed parameters {
  real alpha[nS];
  real beta[nS,nT];
  real mean[nN];
  for (i in 1:nN)
    mean[i] <- mu + alpha[s[i]] + beta[s[i],t[i]];
}
model {
  for(j in 1:nS){ 
    alpha[j]~dnorm(0,sigma1);
    for(k in 1:nT[j]){
      beta[j, k]~dnorm(0,sigma2);
    }
  }
  for(i in 1:nN){
    y[i] ~ normal(mean[i], sigma);
  }
}

Dustin Tran

unread,
Aug 6, 2015, 1:46:48 PM8/6/15
to stan-...@googlegroups.com
Hi Jing,
The error says that you can’t use a variable name which is already the name of a function in Stan.

Dustin
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jing Zhang

unread,
Aug 6, 2015, 3:37:40 PM8/6/15
to Stan users mailing list
Hi Dustin: 

Thanks a lot. I fixed it according to your message. 

But now I have a new error. Could you help on this? Thanks again! 

DIAGNOSTIC(S) FROM PARSER:
Warning (non-fatal):
 Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
If so, you need to call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
    get_base1(beta,k,"beta",1) ~ normal(...)
Warning (non-fatal):
 Left-hand side of sampling statement (~) may contain a non-linear transform of a parameter or local variable.
If so, you need to call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
    get_base1(alpha,i,"alpha",1) ~ normal(...)

COMPILING THE C++ CODE FOR MODEL 'Model2' NOW.
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-31~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-31~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file280c2f48879.dll" WIN=64 TCLBIN=64 OBJECTS="file280c2f48879.o"' had status 127 

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: 
  5: // user includes
  6: #define STAN__SERVICES__COMMAND_HPP// Code generated by Stan version 2.7
  7: 
  8: #include <stan/model/model_header.hpp>
  9: 
 10: namespace model280c35c3154e_Model2_namespace {
 11: 
 12: using std::istream;
 13: using std::string;
 14: using std::stringstream;
 15: using std::vector;
 16: using stan::io::dump;
 17: using stan::math::lgamma;
 18: using stan::model::prob_grad;
 19: using namespace stan::math;
 20: 
 21: typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
 22: typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
 23: typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;
 24: 
 25: static int current_statement_begin__;
 26: class model280c35c3154e_Model2 : public prob_grad {
 27: private:
 28:     int nS;
 29:     int nT;
 30:     vector<vector<double> > y;
 31:     vector<int> Sub;
 32: public:
 33:     model280c35c3154e_Model2(stan::io::var_context& context__,
 34:         std::ostream* pstream__ = 0)
 35:         : prob_grad(0) {
 36:         current_statement_begin__ = -1;
 37: 
 38:         static const char* function__ = "model280c35c3154e_Model2_namespace::model280c35c3154e_Model2";
 39:         (void) function__; // dummy call to supress warning
 40:         size_t pos__;
 41:         (void) pos__; // dummy call to supress warning
 42:         std::vector<int> vals_i__;
 43:         std::vector<double> vals_r__;
 44:         context__.validate_dims("data initialization", "nS", "int", context__.to_vec());
 45:         nS = int(0);
 46:         vals_i__ = context__.vals_i("nS");
 47:         pos__ = 0;
 48:         nS = vals_i__[pos__++];
 49:         context__.validate_dims("data initialization", "nT", "int", context__.to_vec());
 50:         nT = int(0);
 51:         vals_i__ = context__.vals_i("nT");
 52:         pos__ = 0;
 53:         nT = vals_i__[pos__++];
 54:         context__.validate_dims("data initialization", "y", "double", context__.to_vec(nT,2));
 55:         validate_non_negative_index("y", "nT", nT);
 56:         validate_non_negative_index("y", "2", 2);
 57:         y = std::vector<std::vector<double> >(nT,std::vector<double>(2,double(0)));
 58:         vals_r__ = context__.vals_r("y");
 59:         pos__ = 0;
 60:         size_t y_limit_1__ = 2;
 61:         for (size_t i_1__ = 0; i_1__ < y_limit_1__; ++i_1__) {
 62:             size_t y_limit_0__ = nT;
 63:             for (size_t i_0__ = 0; i_0__ < y_limit_0__; ++i_0__) {
 64:                 y[i_0__][i_1__] = vals_r__[pos__++];
 65:             }
 66:         }
 67:         context__.validate_dims("data initialization", "Sub", "int", context__.to_vec(nT));
 68:         validate_non_negative_index("Sub", "nT", nT);
 69:         Sub = std::vector<int>(nT,int(0));
 70:         vals_i__ = context__.vals_i("Sub");
 71:         pos__ = 0;
 72:         size_t Sub_limit_0__ = nT;
 73:         for (size_t i_0__ = 0; i_0__ < Sub_limit_0__; ++i_0__) {
 74:             Sub[i_0__] = vals_i__[pos__++];
 75:         }
 76: 
 77:         // validate data
 78:         check_greater_or_equal(function__,"nS",nS,0);
 79:         check_greater_or_equal(function__,"nT",nT,0);
 80:         for (int k0__ = 0; k0__ < nT; ++k0__) {
 81:             check_greater_or_equal(function__,"Sub[k0__]",Sub[k0__],0);
 82:         }
 83: 
 84:         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 85:         (void) DUMMY_VAR__;  // suppress unused var warning
 86: 
 87: 
 88:         // initialize transformed variables to avoid seg fault on val access
 89: 
 90:         try {
 91:         } catch (const std::exception& e) {
 92:             stan::lang::rethrow_located(e,current_statement_begin__);
 93:             // Next line prevents compiler griping about no return
 94: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 95:         }
 96: 
 97:         // validate transformed data
 98: 
 99:         // set parameter ranges
100:         num_params_r__ = 0U;
101:         param_ranges_i__.clear();
102:         ++num_params_r__;
103:         ++num_params_r__;
104:         ++num_params_r__;
105:         ++num_params_r__;
106:     }
107: 
108:     ~model280c35c3154e_Model2() { }
109: 
110: 
111:     void transform_inits(const stan::io::var_context& context__,
112:                          std::vector<int>& params_i__,
113:                          std::vector<double>& params_r__,
114:                          std::ostream* pstream__) const {
115:         stan::io::writer<double> writer__(params_r__,params_i__);
116:         size_t pos__;
117:         (void) pos__; // dummy call to supress warning
118:         std::vector<double> vals_r__;
119:         std::vector<int> vals_i__;
120: 
121:         if (!(context__.contains_r("mu")))
122:             throw std::runtime_error("variable mu missing");
123:         vals_r__ = context__.vals_r("mu");
124:         pos__ = 0U;
125:         context__.validate_dims("initialization", "mu", "double", context__.to_vec());
126:         double mu(0);
127:         mu = vals_r__[pos__++];
128:         try {
129:             writer__.scalar_unconstrain(mu);
130:         } catch (const std::exception& e) { 
131:             throw std::runtime_error(std::string("Error transforming variable mu: ") + e.what());
132:         }
133: 
134:         if (!(context__.contains_r("sigma")))
135:             throw std::runtime_error("variable sigma missing");
136:         vals_r__ = context__.vals_r("sigma");
137:         pos__ = 0U;
138:         context__.validate_dims("initialization", "sigma", "double", context__.to_vec());
139:         double sigma(0);
140:         sigma = vals_r__[pos__++];
141:         try {
142:             writer__.scalar_lb_unconstrain(0,sigma);
143:         } catch (const std::exception& e) { 
144:             throw std::runtime_error(std::string("Error transforming variable sigma: ") + e.what());
145:         }
146: 
147:         if (!(context__.contains_r("sigma1")))
148:             throw std::runtime_error("variable sigma1 missing");
149:         vals_r__ = context__.vals_r("sigma1");
150:         pos__ = 0U;
151:         context__.validate_dims("initialization", "sigma1", "double", context__.to_vec());
152:         double sigma1(0);
153:         sigma1 = vals_r__[pos__++];
154:         try {
155:             writer__.scalar_lb_unconstrain(0,sigma1);
156:         } catch (const std::exception& e) { 
157:             throw std::runtime_error(std::string("Error transforming variable sigma1: ") + e.what());
158:         }
159: 
160:         if (!(context__.contains_r("sigma2")))
161:             throw std::runtime_error("variable sigma2 missing");
162:         vals_r__ = context__.vals_r("sigma2");
163:         pos__ = 0U;
164:         context__.validate_dims("initialization", "sigma2", "double", context__.to_vec());
165:         double sigma2(0);
166:         sigma2 = vals_r__[pos__++];
167:         try {
168:             writer__.scalar_lb_unconstrain(0,sigma2);
169:         } catch (const std::exception& e) { 
170:             throw std::runtime_error(std::string("Error transforming variable sigma2: ") + e.what());
171:         }
172: 
173:         params_r__ = writer__.data_r();
174:         params_i__ = writer__.data_i();
175:     }
176: 
177:     void transform_inits(const stan::io::var_context& context,
178:                          Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
179:                          std::ostream* pstream__) const {
180:       std::vector<double> params_r_vec;
181:       std::vector<int> params_i_vec;
182:       transform_inits(context, params_i_vec, params_r_vec, pstream__);
183:       params_r.resize(params_r_vec.size());
184:       for (int i = 0; i < params_r.size(); ++i)
185:         params_r(i) = params_r_vec[i];
186:     }
187: 
188: 
189:     template <bool propto__, bool jacobian__, typename T__>
190:     T__ log_prob(vector<T__>& params_r__,
191:                  vector<int>& params_i__,
192:                  std::ostream* pstream__ = 0) const {
193: 
194:         T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
195:         (void) DUMMY_VAR__;  // suppress unused var warning
196: 
197:         T__ lp__(0.0);
198:         stan::math::accumulator<T__> lp_accum__;
199: 
200:         // model parameters
201:         stan::io::reader<T__> in__(params_r__,params_i__);
202: 
203:         T__ mu;
204:         (void) mu;   // dummy to suppress unused var warning
205:         if (jacobian__)
206:             mu = in__.scalar_constrain(lp__);
207:         else
208:             mu = in__.scalar_constrain();
209: 
210:         T__ sigma;
211:         (void) sigma;   // dummy to suppress unused var warning
212:         if (jacobian__)
213:             sigma = in__.scalar_lb_constrain(0,lp__);
214:         else
215:             sigma = in__.scalar_lb_constrain(0);
216: 
217:         T__ sigma1;
218:         (void) sigma1;   // dummy to suppress unused var warning
219:         if (jacobian__)
220:             sigma1 = in__.scalar_lb_constrain(0,lp__);
221:         else
222:             sigma1 = in__.scalar_lb_constrain(0);
223: 
224:         T__ sigma2;
225:         (void) sigma2;   // dummy to suppress unused var warning
226:         if (jacobian__)
227:             sigma2 = in__.scalar_lb_constrain(0,lp__);
228:         else
229:             sigma2 = in__.scalar_lb_constrain(0);
230: 
231: 
232:         // transformed parameters
233:         vector<T__> alpha(nT);
234:         vector<T__> beta(nS);
235:         vector<T__> theta(nT);
236: 
237:         // initialize transformed variables to avoid seg fault on val access
238:         stan::math::fill(alpha,DUMMY_VAR__);
239:         stan::math::fill(beta,DUMMY_VAR__);
240:         stan::math::fill(theta,DUMMY_VAR__);
241: 
242:         try {
243:             current_statement_begin__ = 17;
244:             for (int i = 1; i <= nT; ++i) {
245:                 current_statement_begin__ = 18;
246:                 stan::math::assign(get_base1_lhs(theta,i,"theta",1), ((mu + get_base1(alpha,i,"alpha",1)) + get_base1(beta,get_base1(Sub,i,"Sub",1),"beta",1)));
247:             }
248:         } catch (const std::exception& e) {
249:             stan::lang::rethrow_located(e,current_statement_begin__);
250:             // Next line prevents compiler griping about no return
251: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
252:         }
253: 
254:         // validate transformed parameters
255:         for (int i0__ = 0; i0__ < nT; ++i0__) {
256:             if (stan::math::is_uninitialized(alpha[i0__])) {
257:                 std::stringstream msg__;
258:                 msg__ << "Undefined transformed parameter: alpha" << '[' << i0__ << ']';
259:                 throw std::runtime_error(msg__.str());
260:             }
261:         }
262:         for (int i0__ = 0; i0__ < nS; ++i0__) {
263:             if (stan::math::is_uninitialized(beta[i0__])) {
264:                 std::stringstream msg__;
265:                 msg__ << "Undefined transformed parameter: beta" << '[' << i0__ << ']';
266:                 throw std::runtime_error(msg__.str());
267:             }
268:         }
269:         for (int i0__ = 0; i0__ < nT; ++i0__) {
270:             if (stan::math::is_uninitialized(theta[i0__])) {
271:                 std::stringstream msg__;
272:                 msg__ << "Undefined transformed parameter: theta" << '[' << i0__ << ']';
273:                 throw std::runtime_error(msg__.str());
274:             }
275:         }
276: 
277:         const char* function__ = "validate transformed params";
278:         (void) function__; // dummy to suppress unused var warning
279: 
280:         // model body
281:         try {
282:             current_statement_begin__ = 21;
283:             for (int k = 1; k <= nS; ++k) {
284:                 current_statement_begin__ = 22;
285:                 lp_accum__.add(normal_log<propto__>(get_base1(beta,k,"beta",1), 0, sigma2));
286:             }
287:             current_statement_begin__ = 24;
288:             for (int i = 1; i <= nT; ++i) {
289:                 current_statement_begin__ = 25;
290:                 lp_accum__.add(normal_log<propto__>(get_base1(alpha,i,"alpha",1), 0, sigma1));
291:                 current_statement_begin__ = 26;
292:                 for (int j = 1; j <= 2; ++j) {
293:                     current_statement_begin__ = 27;
294:                     lp_accum__.add(normal_log<propto__>(get_base1(get_base1(y,i,"y",1),j,"y",2), get_base1(theta,i,"theta",1), sigma));
295:                 }
296:             }
297:         } catch (const std::exception& e) {
298:             stan::lang::rethrow_located(e,current_statement_begin__);
299:             // Next line prevents compiler griping about no return
300: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
301:         }
302: 
303:         lp_accum__.add(lp__);
304:         return lp_accum__.sum();
305: 
306:     } // log_prob()
307: 
308:     template <bool propto, bool jacobian, typename T_>
309:     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
310:                std::ostream* pstream = 0) const {
311:       std::vector<T_> vec_params_r;
312:       vec_params_r.reserve(params_r.size());
313:       for (int i = 0; i < params_r.size(); ++i)
314:         vec_params_r.push_back(params_r(i));
315:       std::vector<int> vec_params_i;
316:       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
317:     }
318: 
319: 
320:     void get_param_names(std::vector<std::string>& names__) const {
321:         names__.resize(0);
322:         names__.push_back("mu");
323:         names__.push_back("sigma");
324:         names__.push_back("sigma1");
325:         names__.push_back("sigma2");
326:         names__.push_back("alpha");
327:         names__.push_back("beta");
328:         names__.push_back("theta");
329:     }
330: 
331: 
332:     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
333:         dimss__.resize(0);
334:         std::vector<size_t> dims__;
335:         dims__.resize(0);
336:         dimss__.push_back(dims__);
337:         dims__.resize(0);
338:         dimss__.push_back(dims__);
339:         dims__.resize(0);
340:         dimss__.push_back(dims__);
341:         dims__.resize(0);
342:         dimss__.push_back(dims__);
343:         dims__.resize(0);
344:         dims__.push_back(nT);
345:         dimss__.push_back(dims__);
346:         dims__.resize(0);
347:         dims__.push_back(nS);
348:         dimss__.push_back(dims__);
349:         dims__.resize(0);
350:         dims__.push_back(nT);
351:         dimss__.push_back(dims__);
352:     }
353: 
354:     template <typename RNG>
355:     void write_array(RNG& base_rng__,
356:                      std::vector<double>& params_r__,
357:                      std::vector<int>& params_i__,
358:                      std::vector<double>& vars__,
359:                      bool include_tparams__ = true,
360:                      bool include_gqs__ = true,
361:                      std::ostream* pstream__ = 0) const {
362:         vars__.resize(0);
363:         stan::io::reader<double> in__(params_r__,params_i__);
364:         static const char* function__ = "model280c35c3154e_Model2_namespace::write_array";
365:         (void) function__; // dummy call to supress warning
366:         // read-transform, write parameters
367:         double mu = in__.scalar_constrain();
368:         double sigma = in__.scalar_lb_constrain(0);
369:         double sigma1 = in__.scalar_lb_constrain(0);
370:         double sigma2 = in__.scalar_lb_constrain(0);
371:         vars__.push_back(mu);
372:         vars__.push_back(sigma);
373:         vars__.push_back(sigma1);
374:         vars__.push_back(sigma2);
375: 
376:         if (!include_tparams__) return;
377:         // declare and define transformed parameters
378:         double lp__ = 0.0;
379:         (void) lp__; // dummy call to supress warning
380:         stan::math::accumulator<double> lp_accum__;
381: 
382:         vector<double> alpha(nT, 0.0);
383:         vector<double> beta(nS, 0.0);
384:         vector<double> theta(nT, 0.0);
385: 
386:         try {
387:             current_statement_begin__ = 17;
388:             for (int i = 1; i <= nT; ++i) {
389:                 current_statement_begin__ = 18;
390:                 stan::math::assign(get_base1_lhs(theta,i,"theta",1), ((mu + get_base1(alpha,i,"alpha",1)) + get_base1(beta,get_base1(Sub,i,"Sub",1),"beta",1)));
391:             }
392:         } catch (const std::exception& e) {
393:             stan::lang::rethrow_located(e,current_statement_begin__);
394:             // Next line prevents compiler griping about no return
395: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
396:         }
397: 
398:         // validate transformed parameters
399: 
400:         // write transformed parameters
401:         for (int k_0__ = 0; k_0__ < nT; ++k_0__) {
402:             vars__.push_back(alpha[k_0__]);
403:         }
404:         for (int k_0__ = 0; k_0__ < nS; ++k_0__) {
405:             vars__.push_back(beta[k_0__]);
406:         }
407:         for (int k_0__ = 0; k_0__ < nT; ++k_0__) {
408:             vars__.push_back(theta[k_0__]);
409:         }
410: 
411:         if (!include_gqs__) return;
412:         // declare and define generated quantities
413: 
414:         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
415:         (void) DUMMY_VAR__;  // suppress unused var warning
416: 
417: 
418:         // initialize transformed variables to avoid seg fault on val access
419: 
420:         try {
421:         } catch (const std::exception& e) {
422:             stan::lang::rethrow_located(e,current_statement_begin__);
423:             // Next line prevents compiler griping about no return
424: throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
425:         }
426: 
427:         // validate generated quantities
428: 
429:         // write generated quantities
430:     }
431: 
432:     template <typename RNG>
433:     void write_array(RNG& base_rng,
434:                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
435:                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
436:                      bool include_tparams = true,
437:                      bool include_gqs = true,
438:                      std::ostream* pstream = 0) const {
439:       std::vector<double> params_r_vec(params_r.size());
440:       for (int i = 0; i < params_r.size(); ++i)
441:         params_r_vec[i] = params_r(i);
442:       std::vector<double> vars_vec;
443:       std::vector<int> params_i_vec;
444:       write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
445:       vars.resize(vars_vec.size());
446:       for (int i = 0; i < vars.size(); ++i)
447:         vars(i) = vars_vec[i];
448:     }
449: 
450:     static std::string model_name() {
451:         return "model280c35c3154e_Model2";
452:     }
453: 
454: 
455:     void constrained_param_names(std::vector<std::string>& param_names__,
456:                                  bool include_tparams__ = true,
457:                                  bool include_gqs__ = true) const {
458:         std::stringstream param_name_stream__;
459:         param_name_stream__.str(std::string());
460:         param_name_stream__ << "mu";
461:         param_names__.push_back(param_name_stream__.str());
462:         param_name_stream__.str(std::string());
463:         param_name_stream__ << "sigma";
464:         param_names__.push_back(param_name_stream__.str());
465:         param_name_stream__.str(std::string());
466:         param_name_stream__ << "sigma1";
467:         param_names__.push_back(param_name_stream__.str());
468:         param_name_stream__.str(std::string());
469:         param_name_stream__ << "sigma2";
470:         param_names__.push_back(param_name_stream__.str());
471: 
472:         if (!include_gqs__ && !include_tparams__) return;
473:         for (int k_0__ = 1; k_0__ <= nT; ++k_0__) {
474:             param_name_stream__.str(std::string());
475:             param_name_stream__ << "alpha" << '.' << k_0__;
476:             param_names__.push_back(param_name_stream__.str());
477:         }
478:         for (int k_0__ = 1; k_0__ <= nS; ++k_0__) {
479:             param_name_stream__.str(std::string());
480:             param_name_stream__ << "beta" << '.' << k_0__;
481:             param_names__.push_back(param_name_stream__.str());
482:         }
483:         for (int k_0__ = 1; k_0__ <= nT; ++k_0__) {
484:             param_name_stream__.str(std::string());
485:             param_name_stream__ << "theta" << '.' << k_0__;
486:             param_names__.push_back(param_name_stream__.str());
487:         }
488: 
489:         if (!include_gqs__) return;
490:     }
491: 
492: 
493:     void unconstrained_param_names(std::vector<std::string>& param_names__,
494:                                    bool include_tparams__ = true,
495:                                    bool include_gqs__ = true) const {
496:         std::stringstream param_name_stream__;
497:         param_name_stream__.str(std::string());
498:         param_name_stream__ << "mu";
499:         param_names__.push_back(param_name_stream__.str());
500:         param_name_stream__.str(std::string());
501:         param_name_stream__ << "sigma";
502:         param_names__.push_back(param_name_stream__.str());
503:         param_name_stream__.str(std::string());
504:         param_name_stream__ << "sigma1";
505:         param_names__.push_back(param_name_stream__.str());
506:         param_name_stream__.str(std::string());
507:         param_name_stream__ << "sigma2";
508:         param_names__.push_back(param_name_stream__.str());
509: 
510:         if (!include_gqs__ && !include_tparams__) return;
511:         for (int k_0__ = 1; k_0__ <= nT; ++k_0__) {
512:             param_name_stream__.str(std::string());
513:             param_name_stream__ << "alpha" << '.' << k_0__;
514:             param_names__.push_back(param_name_stream__.str());
515:         }
516:         for (int k_0__ = 1; k_0__ <= nS; ++k_0__) {
517:             param_name_stream__.str(std::string());
518:             param_name_stream__ << "beta" << '.' << k_0__;
519:             param_names__.push_back(param_name_stream__.str());
520:         }
521:         for (int k_0__ = 1; k_0__ <= nT; ++k_0__) {
522:             param_name_stream__.str(std::string());
523:             param_name_stream__ << "theta" << '.' << k_0__;
524:             param_names__.push_back(param_name_stream__.str());
525:         }
526: 
527:         if (!include_gqs__) return;
528:     }
529: 
530: }; // model
531: 
532: } // namespace
533: 
534: typedef model280c35c3154e_Model2_namespace::model280c35c3154e_Model2 stan_model;
535: 
536: #include <rstan/rstaninc.hpp>
537: /**
538:  * Define Rcpp Module to expose stan_fit's functions to R.
539:  */
540: RCPP_MODULE(stan_fit4model280c35c3154e_Model2_mod){
541:   Rcpp::class_<rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2,
542:                boost::random::ecuyer1988> >("stan_fit4model280c35c3154e_Model2")
543:     // .constructor<Rcpp::List>()
544:     .constructor<SEXP, SEXP>()
545:     // .constructor<SEXP, SEXP>()
546:     .method("call_sampler",
547:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::call_sampler)
548:     .method("param_names",
549:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_names)
550:     .method("param_names_oi",
551:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_names_oi)
552:     .method("param_fnames_oi",
553:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_fnames_oi)
554:     .method("param_dims",
555:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_dims)
556:     .method("param_dims_oi",
557:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_dims_oi)
558:     .method("update_param_oi",
559:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::update_param_oi)
560:     .method("param_oi_tidx",
561:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::param_oi_tidx)
562:     .method("grad_log_prob",
563:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::grad_log_prob)
564:     .method("log_prob",
565:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::log_prob)
566:     .method("unconstrain_pars",
567:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::unconstrain_pars)
568:     .method("constrain_pars",
569:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::constrain_pars)
570:     .method("num_pars_unconstrained",
571:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::num_pars_unconstrained)
572:     .method("unconstrained_param_names",
573:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::unconstrained_param_names)
574:     .method("constrained_param_names",
575:             &rstan::stan_fit<model280c35c3154e_Model2_namespace::model280c35c3154e_Model2, boost::random::ecuyer1988>::constrained_param_names)
576:     ;
577: }
578: 
579: // declarations
580: extern "C" {
581: SEXP file280c2f48879( ) ;
582: }
583: 
584: // definition
585: 
586: SEXP file280c2f48879(  ){
587:  return Rcpp::wrap("Model2");
588: }
589: 
590: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-31~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-31~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file280c2f48879.dll" WIN=64 TCLBIN=64 OBJECTS="file280c2f48879.o"' had status 127 
In addition: Warning messages:
1: running command '"C:/PROGRA~1/R/R-31~1.3/bin/x64/R" CMD config CXX' had status 1 
2: running command 'C:/PROGRA~1/R/R-31~1.3/bin/x64/R CMD SHLIB file280c2f48879.cpp 2> file280c2f48879.cpp.err.txt' had status 1  



Best Regards, 
Jing 

Ben Goodrich

unread,
Aug 6, 2015, 4:08:43 PM8/6/15
to Stan users mailing list
On Thursday, August 6, 2015 at 3:37:40 PM UTC-4, Jing Zhang wrote:
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-31~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-31~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file280c2f48879.dll" WIN=64 TCLBIN=64 OBJECTS="file280c2f48879.o"' had status 127 

ERROR(s) during compilation: source code errors or compiler configuration errors!

See this thread

https://groups.google.com/d/msg/stan-users/tbhjcjF-Egs/-X-IdZ3eFwAJ

but once you fix that, be mindful of the Jacobian warnings the parser gave you.

Ben

Reply all
Reply to author
Forward
0 new messages