In [1]:
library(ggplot2)
library(plyr)
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
rstan (Version 2.9.0-3, packaged: 2016-02-11 15:54:41 UTC, GitRev: 05c3d0058b6a)
For execution on a local, multicore CPU with excess RAM we recommend calling
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
In [11]:
cox_model <- 
"data {
    int<lower=0> Nsubj; 
    int<lower=1> T;
    vector[Nsubj] pscenter;
    vector[Nsubj] hhcenter;
    int<lower=0,upper=1> ncomact[Nsubj];
    int<lower=0,upper=1> rleader[Nsubj];
    int<lower=0,upper=1> dleader[Nsubj];
    vector[Nsubj] inter1;
    vector[Nsubj] inter2;
    int<lower=0,upper=1> FAIL[Nsubj];
    int<lower=0> obs_t[Nsubj];
    int<lower=0> t[T];
    
} 

transformed data {
    int<lower=0> Y[Nsubj, T];
    int<lower=0> dN[Nsubj, T];
    
    # Set up data
    for(i in 1:Nsubj) {
        for(j in 1:T) {
            # risk set = 1 if obs_t >= t
            Y[i,j] <- int_step(obs_t[i] - t[j]);
            # counting process 
            dN[i,j] <- Y[i, j] * int_step(t[j + 1] - obs_t[i]) * FAIL[i];
        }
    }
}

parameters {
    vector[7] beta;
    real<lower=0> c;
    real<lower=0> r;
    vector[T] dL0;   
}

transformed parameters {
    vector[T] mu;
    matrix[Nsubj, T] Idt;
    vector[T] dL0_star;
    
    for(j in 1:T) {
        for(i in 1:Nsubj) {
            # Intensity
            Idt[i, j] <- Y[i, j] * exp(beta[1]*pscenter[i] + beta[2]*hhcenter[i] + beta[3]*ncomact[i] 
                        + beta[4]*rleader[i] + beta[5]*dleader[i] + beta[6]*inter1[i] + beta[7]*inter2[i]) * dL0[j];
        }     
        # prior mean hazard 
        mu[j] <- dL0_star[j] * c;   
        
        dL0_star[j] <- r * (t[j + 1] - t[j]);
    }
} 

model {
    
    for(j in 1:T) {
        for(i in 1:Nsubj) {
            # Likelihood
            dN[i, j] ~ poisson(Idt[i, j]);  
        }     
        dL0[j] ~ gamma(mu[j], c);
    }
    
    c ~ gamma(0.0001, 0.00001);
    r ~ gamma(0.001, 0.0001);
    
    beta ~ normal(0.0, 100000);
}"
In [12]:
data <- list(T=73, 
    Nsubj=430, 
    t=c(1, 21, 85, 128, 129, 148, 178, 204,
         206, 210, 211, 212, 225, 238, 241,
         248, 259, 273, 275, 281, 286, 289,
         301, 302, 303, 304, 313, 317, 323,
         344, 345, 349, 350, 351, 355, 356,
         359, 364, 385, 386, 389, 390, 391,
         392, 394, 395, 396, 397, 398, 399,
         400, 406, 415, 416, 426, 427, 434,
         435, 437, 441, 447, 448, 449, 450,
         451, 453, 455, 456, 458, 459, 460,
         461, 462, 463),
    obs_t=c(460, 313, 435, 350, 435, 350, 350, 460, 460, 448, 225, 225, 396, 435, 396, 396, 
    453, 396, 456, 397, 397, 396, 395, 275, 449, 395, 395, 462, 302, 302, 458, 461, 396, 241, 389, 
    458, 304, 304, 395, 395, 364, 460, 415, 463, 396, 459, 441, 435, 396, 458, 437, 396, 356, 356, 
    396, 455, 396, 462, 399, 400, 350, 350, 395, 395, 441, 355, 85, 458, 128, 396, 386, 386, 386, 462, 
    458, 390, 390, 396, 396, 396, 427, 458, 395, 275, 275, 395, 359, 395, 395, 441, 395, 463, 178, 275, 
    463, 396, 396, 259, 396, 396, 458, 441, 396, 463, 396, 463, 435, 396, 437, 396, 398, 463, 460, 462, 
    460, 460, 210, 396, 435, 458, 385, 323, 323, 359, 396, 396, 460, 238, 441, 450, 392, 458, 396, 458, 
    396, 396, 462, 435, 396, 394, 396, 435, 458, 1, 395, 395, 451, 462, 458, 462, 396, 286, 396, 349, 
    449, 462, 455, 21, 463, 461, 461, 456, 435, 396, 460, 462, 462, 435, 435, 460, 386, 396, 458, 386, 
    461, 441, 435, 435, 463, 456, 396, 275, 460, 406, 460, 406, 317, 406, 461, 396, 359, 458, 463, 435, 
    462, 458, 396, 396, 273, 396, 435, 281, 275, 396, 447, 225, 447, 396, 435, 416, 396, 248, 396, 435, 
    435, 396, 461, 385, 396, 458, 458, 396, 461, 396, 448, 396, 396, 460, 455, 456, 463, 462, 458, 463, 
    396, 462, 395, 456, 396, 463, 396, 435, 459, 396, 396, 396, 395, 435, 455, 395, 461, 344, 396, 395, 
    396, 317, 396, 395, 426, 461, 396, 289, 441, 395, 396, 458, 396, 396, 435, 396, 395, 396, 441, 345, 
    396, 359, 435, 435, 396, 396, 395, 458, 461, 458, 212, 301, 458, 456, 395, 396, 395, 435, 396, 396, 
    303, 458, 460, 400, 396, 462, 359, 458, 396, 206, 441, 396, 458, 396, 462, 396, 396, 275, 396, 395, 
    435, 435, 462, 225, 458, 462, 396, 396, 289, 396, 303, 455, 400, 400, 359, 461, 396, 462, 460, 463, 
    463, 463, 204, 435, 435, 396, 396, 396, 463, 458, 396, 455, 435, 396, 396, 463, 396, 461, 463, 460, 
    441, 460, 435, 435, 460, 455, 460, 395, 460, 460, 460, 435, 449, 463, 462, 129, 391, 396, 391, 391, 
    434, 356, 462, 396, 349, 225, 396, 435, 461, 391, 391, 351, 211, 461, 212, 434, 148, 356, 458, 456, 
    455, 435, 463, 463, 462, 435, 463, 437, 460, 396, 406, 451, 460, 435, 396, 460, 455, 396, 398, 456, 
    458, 396, 456, 449, 396, 128, 396, 462, 463, 396, 396, 396, 435, 460, 396, 458),
    FAIL<- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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866, -.0387039, 
 -.0553269, -.03238896, -.07464545, -.07325128, -.07062459, -.07464545, -.07032613, -.0703005, .00965232, 
 -.01408955, .00577483, -.00219072, -.00084567, .01643198, .06509522, .06824313, .07300876, .07300876, .01394272, 
 .06824313, .02063087, .00383186, -.02573045, -.02410864, -.02272752, .05120398, -.00997729, -.00550709, 
 -.02062663, -.03077685, -.01688493, .01035959, .01149963, .01149963, .01149963, .01149963, .01149963, .01149963, 
 .01149963, .01149963, .01149963, .01149963, .01149963, .01149963, .01149963, .01149963, .0034338, .0376236, 
 .00733331, .01520069, .03832785, .03832785, -.02622275, -.02622275, -.02622275, -.01492678, -.02897806, 
 -.02897806, -.02897806, -.02847666, -.031893, -.03919478, -.04224754, -.04743705, -.0510477, -.031893, 
 -.01129093, .01706207, .00193999, -.01503116, .003101, -.00083466, .02395027, -.07952866, -.08559135, -.07251801, 
 -.06586029, -.08432532, -.0613939, -.081205, -.07540084, -.08488011, -.08488011, -.08488011, -.07492433, 
 -.08907269, -.09451609, -.05301854, -.08980743, -.0771635, -.0771635, -.08650947, -.07856082, -.0771635, 
 -.08204606, -.08178245, -.05263504, -.05355574, -.05109092, -.04696729, -.04696729, -.04696729, -.05257489, 
 -.05303248, -.05348096, -.04983674, -.04699414, .00584956, -.00792241, -.01719816, -.02138029, -.01576016, 
 -.04274812, -.04014061, .0471441, .0471441, .0471441, .0471441, .0471441, .0471441, .0471441, .04233112, 
 .0471441, .04233112, .050568, .07388823, .0493324, .04512087, .03205975, .02913185, .06010427, .05324252, 
 .06973204, .05579907, .01212243, .07962459, .05054695, .06672142, .14026688, .01734403, .06078221, .06543709, 
 .06438115, .20126908, -.03138622, -.02180659, .01637333, -.02415774, .01828684, .03106104, .04268495, .01897239, 
 .01591935, -.02367065, -.0619156, -.06403028, -.06851645, -.04821694, -.03889525, -.05023452, -.05013452, 
 -.01557191, -.01171948, -.01362136, -.01174715, -.02707938, -.02634164, -.02634164, -.02634164, -.00692153, 
 -.02381614, -.00890537, -.00611669, -.00894752, -.03551984, -.0252678, -.01513384, -.01016569, -.03551984, 
 -.03773227, -.01978032, .06803483, .06706496, .10551275, .15091534, .03092981, .06556855, .10781559, .12671031, 
 .0936299, .09362991, .09362991, .08294538, .09362991, .09362991, .09362991, .01177025, .02610553, .03546937, 
 .03546937, .03546937, .034415, -.00305626, .04973665, .05103208, .07546701, .05306436, .00824125, .01961115, 
 .01202359, -.02919447, -.01016712, .01756074, -.04035511, -.04753104, -.04463152, -.04845615, -.05010044, 
 .00031411, -.07911871, -.08799869, -.07980882, -.09393142, -.08000018, -.07666632, -.07817401, -.07444922, 
 -.07226554, -.08216553, -.0777643, -.07752042, -.05767992, -.04727952, -.03774814, -.06870384, -.05999847, 
 -.05947695, .02989959, .04627543, .02772475, .02883079, .03642944, .02871235, .04148949, .04240279, .07747082, 
 .07626323, .04268012, .03225577, .06468724, -.05140995, -.05399637, -.05351515, .07302427, .02432223, .0490674, 
 .0490674, .0490674, .0490674, .09013112, .10476315, .10476315, .10476315, .10476315, .10476315, .10476315, 
 .10476315, .10476315, .10476315, .10476315, .10476315, .10476315, .10476315, .07008056, .08666077, .01546215, 
 .01667466, .03417671, .05253941, .04293926, .01496588, .02692172, -.03827151, .04809769, .08742411, .04533176, 
 .01455173, .01831875, .02710811, .09834951, .09952456, .06993483, .02945534, .038731, .1181948, .04435538, 
 .04435538, -.02357505, .05824019, .05820741, -.02357505, .09324722, .15534712, .07207468, .04692869, -.03490683, 
 -.04404809, -.05054474, -.05325826, -.0474724, -.04905931, .01068221, .02879751, .00852646, .02693032, .01835589, 
 .02989959, .02989959, .02989959, .04976377, .04439012, .03397319, .02989959, .02989959, .05468828, .04463226, 
 .05886378, .06311052, .02989959, .04595331, .04203459, .01231324, -.01399783, .04595331, .00145386, .04601278, 
 .06459354, -.0007196, .00012216, -.07614055, -.08435525, -.07957162, -.10299519, -.08156988, -.08225659, 
 -.07449063, -.00210284, -.00797183, -.025355, -.01258251, -.04372031, -.03985972, -.03545086, -.03384566, 
 -.04025533, -.07523724, -.05947702, -.061286, -.07666647, -.07663169, -.05902354, -.07652324, -.07645561, 
 -.06258684, -.09604834, -.08813326, -.03292062, -.07848112, -.08239502, -.08316891, -.07244316, -.075417, 
 -.07652324, -.07922532, -.08755959, -.08583414, -.07450142, -.08066016, -.06057205, -.07652324, -.06249051, 
 -.08781742, -.086076, -.07652324, -.07696518, -.0618688, -.06073988, -.06524737, -.04419825, -.04489509, 
 -.04390368, -.04358438, -.04489509, -.04520512, -.04187583, -.03653955, -.03973426, -.03753508, -.03569439, 
 -.06789339, .06689456, .05526327, .05139003, .02641841, .04891529, .07078697, .06862645, .06832582, .04104258, 
 -.00120631, .01947345, .04891779, .04891779, .03561932, .02576244, .03158225, .03608047, .08685057, .04632537, 
 .06841581, -.02899643),
    hhcenter = c( -.78348798, -.63418788, -.91218799, -.98388809, -.23518796, .11481193, -1.415588, -1.2535881, 
    -.55738801, -.88128799, -1.109488, .05721192, -1.045788, -.30888793, .29651192, -.36688802, -.50058788, 
    .02271203, -.59088796, -.04198809, .50561196, -.07418796, .98481184, .78921205, .09431199, -.06488796, 
    2.1662121, .08891205, 1.4004121, 1.316112, 1.9362121, 2.0107121, 1.150712, .31951192, -.23918791, -.1562881, 
    -.9575879, -.07728811, .29641202, 1.2273121, 1.7717118, 1.5764117, .14181189, .72131211, 1.279212, .68241197, 
    -.72808808, -.00488802, -.23938794, -1.000788, .55081207, -.52348799, 1.780612, -.35888812, .36481193, 
    1.5480118, -.03078791, 1.389112, .30211189, .70901209, -.16668792, 1.435812, .47001198, 2.0838118, 1.1673121,
    .18461208, -.30608794, 1.4470119, .23301201, -.58458799, .44011191, -.61948794, -.41388795, .263212, 
    .66171199, .92451197, .78081208, .90991193, 1.6920118, 1.334012, 1.2101121, .41591194, -.48498794, 
    -.73278803, -1.093588, .09911207, -.93418807, -.46908805, .0205119, .0535119, -.14228792, -.55708808, 
    -.45498797, -.54008788, -.30998799, -.10958811, -.0960879, -.01338812, -.88168806, -.51788801, .36801198, 
    .46621206, .13271193, -.11208793, -.76768798, -.54508799, -1.2773881, .16641192, .95871216, -.48238799, 
    1.6281118, -.18848796, -.49718806, -.41348812, -.31628796, -.59528798, -.11718794, -.57058805, -.59488791, 
    -.21248789, -.65658802, -.56298798, -.52698797, -.65758795, -.04988809, .55341202, -.76328796, .254612, 
    1.3500118, -.54958791, 1.665812, .14671211, 1.963912, .29161194, -.56838793, 1.9371119, .90991193, -.39558789, 
    .39521196, -.55208796, -.05268808, -.77368802, -.45428798, .05841212, -.45308802, -.12458798, .01431207, 
    -.28228804, .79281193, -.26358792, -.54738802, -.38158795, -.54118794, -.72828788, -.58128804, .355912, 
    -.24078794, -1.0384881, -.75038809, -.41018793, -.43538806, -1.566388, -.53388804, -.28388807, -1.2348881, 
    -.69028801, -1.620088, -.78128809, -.54648799, -.92738789, .11871199, .26851204, .61571199, .82891208, 
    1.1985121, 1.012012, 1.0602121, -.02988811, .79301196, .67731196, .43991187, .9404121, .5254119, 1.0365119, 
    1.6220121, .61671191, -.50318807, 2.6073117, .02361206, -.60438794, -.79278797, -.18108793, -.48178813, 
    -.44038793, -.22628804, -.07398792, .519512, .40211204, .582012, 1.830512, .80441195, .58801204, -.56368798, 
    -1.5451881, .45991209, -.23448797, -.36918804, 1.3247118, .19541197, -.20818801, 1.163012, -.78228801, 
    -.6048879, -.575288, 1.3241119, .0147119, -.76518792, -.37478802, -.35508797, -.90038794, -1.250888, 
    -.46608803, -.98488802, -1.5185881, -.90908808, -1.048188, -.90138787, -.77278799, -1.248988, -.34448811, 
    -.61628789, .38531187, -.51728791, -.00878807, -.60078806, -.45358798, .46301201, -.22048803, -.71518797, 
    -.76478809, -.75028795, -.4952881, .01731209, -.83718795, .57951194, .54291207, .45341209, .16941194, 1.054112, 
    .61721212, 2.2717118, 1.1593118, 2.0280118, .92281204, 1.0100121, -.1866879, 2.6503119, 2.3914118, -.19948788, 
    -.36418793, -.9259879, -.71058792, -.1104879, .16971211, 1.474812, 1.9360118, 2.5344119, 2.0171118, 1.9387121, 
    .55071193, -.03918811, .20681195, .40421203, -.75518793, -.45678803, -1.0271881, .77211195, 1.146812, -1.147788, 
    -1.565588, -.34888789, 1.303812, 1.952312, 1.639112, .07731203, .25901201, -.45608804, -.5028879, .03641204, 
    -.03808804, .38571194, .31831196, -.17648788, -.44528791, -.55918807, -.53108805, .39721206, -.06328794, 
    -.34038803, -.05988808, -.89548796, -.03518792, .045512, -.1859879, -.039288, -.82568806, .01431207, .40091208, 
    -.2531881, .030412, -.31918809, -.54958791, -.79078788, .36691192, -.324388, -1.0082881, -1.232188, -.53248805, 
    -.23678799, -.89188808, .25111201, -.6766879, -.3565881, -.61228794, -.21078797, -1.0343881, -.58358806, 
    -.15588804, -.39238808, -.67818803, -.19498797, 1.099412, 1.2767119, -.64068788, -.50678796, -.64058799, 
    -.86918801, 1.4048119, -.59648794, .23331194, .68371207, .11251191, -.17128797, .17081194, -.44218799, 
    -.48708794, .09591202, .20131211, -.20108791, -.02158805, -.48188803, -.3012881, -.55008787, -1.146188, 
    -.82128805, -.87638801, -.54488796, -.60288805, -1.003088, -.25078794, -.14818807, -.14738794, -.80938786, 
    -.85988802, -.90188807, -.94998807, -.75718802, -.37418792, -.66708797, 1.0981121, 1.1441121, .47381189, 
    -.12958808, -.34358808, -.84328789, -.33498809, -.98088807, -.6903879, -1.284988, -.80838794, -.91838807, 
    -.81848806, -.34488794, -.83438796, .12971191, .99381214, -.91608804, -.31808802, -.01018806, .98171192, 
    -.91638798, -1.043988, -1.0103881, 1.451612, -.01528808, .02441196, -.41458794, .25691202, .18601207, -.815988, 
    -.02908798, -.59088796, -.35608789, .79691201, 1.8123121, -.98588794, 1.548912, 2.3653121, -.09238812, 
    .96741205, .05891208, -.15618797, -.5660879, -.28338811, -.10088798, 1.1663117, .21981196, .07151202, -.009088,
    -.49578807, .15441208, -.44488809, -.2677879, -.54388803, -.25468799, .68631202, -.88128799, -.84628791,
    -1.2549881, -.36198804),
    ncomact = c( 0, 0, 0, 0, 0, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 
    0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    inter1 = c( -.01434325, -.01460965, 0, 0, 0, -.01113493, 0, 0, 0, -.0553269, -.03238896, 0, 0, -.07062459, 
    -.07464545, -.07032613, 0, 0, -.01408955, 0, -.00219072, 0, 0, 0, 0, 0, .07300876, .01394272, 0, 0, 0, 0, 0, 
    0, .05120398, 0, -.00550709, -.02062663, -.03077685, -.01688493, 0, .01149963, 0, .01149963, .01149963, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, .01149963, .0034338, .0376236, .00733331, 0, .03832785, .03832785, -.02622275, -.02622275, 
    -.02622275, -.01492678, 0, 0, -.02897806, -.02847666, 0, 0, -.04224754, -.04743705, -.0510477, -.031893, 0, 0, 
    0, -.01503116, .003101, -.00083466, .02395027, -.07952866, 0, 0, -.06586029, 0, -.0613939, -.081205, -.07540084, 
    -.08488011, -.08488011, 0, -.07492433, -.08907269, -.09451609, 0, -.08980743, 0, -.0771635, 0, 0, -.0771635, 
    -.08204606, 0, -.05263504, 0, -.05109092, -.04696729, 0, -.04696729, 0, -.05303248, -.05348096, 0, 0, .00584956, 
    -.00792241, -.01719816, 0, -.01576016, 0, -.04014061, 0, 0, 0, 0, 0, .0471441, 0, .04233112, 0, .04233112, 0, 0, 
    .0493324, .04512087, .03205975, .02913185, 0, .05324252, 0, 0, 0, 0, .05054695, 0, .14026688, .01734403, .06078221, 
    0, 0, 0, -.03138622, 0, .01637333, 0, 0, 0, 0, .01897239, .01591935, 0, -.0619156, 0, -.06851645, 0, -.03889525, 
    -.05023452, -.05013452, 0, 0, -.01362136, 0, 0, -.02634164, 0, 0, 0, 0, -.00890537, -.00611669, 0, 0, 0, 
    -.01513384, 0, -.03551984, 0, -.01978032, 0, .06706496, .10551275, 0, .03092981, .06556855, 0, 0, 0, .09362991, 
    0, 0, 0, 0, 0, 0, .02610553, .03546937, 0, 0, .034415, 0, 0, 0, .07546701, 0, 0, 0, 0, -.02919447, -.01016712, 0, 
    0, 0, 0, -.04845615, -.05010044, 0, 0, 0, 0, 0, 0, -.07666632, 0, 0, -.07226554, -.08216553, -.0777643, 0, 0, 
    -.04727952, 0, -.06870384, -.05999847, 0, 0, 0, .02772475, .02883079, .03642944, 0, .04148949, 0, 0, 0, .04268012, 
    .03225577, 0, -.05140995, -.05399637, 0, 0, .02432223, 0, .0490674, .0490674, .0490674, 0, 0, 0, 0, 0, 0, 0, 0, 
    .10476315, 0, 0, 0, 0, 0, .07008056, 0, 0, .01667466, 0, .05253941, .04293926, 0, .02692172, 0, 0, .08742411, 
    .04533176, 0, .01831875, 0, .09834951, .09952456, 0, .02945534, .038731, 0, .04435538, 0, -.02357505, 0, 0, 
    -.02357505, .09324722, 0, 0, 0, -.03490683, 0, -.05054474, 0, -.0474724, -.04905931, 0, .02879751, 0, 0, 0, 0, 
    0, 0, 0, .04439012, 0, .02989959, .02989959, .05468828, .04463226, 0, 0, 0, 0, 0, .01231324, -.01399783, .04595331, 
    .00145386, 0, .06459354, -.0007196, 0, -.07614055, -.08435525, 0, -.10299519, 0, 0, 0, -.00210284, -.00797183, 0, 
    0, 0, 0, -.03545086, 0, 0, 0, 0, -.061286, -.07666647, 0, -.05902354, -.07652324, -.07645561, 0, 0, 0, -.03292062, 
    0, 0, 0, 0, -.075417, 0, -.07922532, 0, -.08583414, -.07450142, -.08066016, 0, 0, -.06249051, 0, 0, 0, 0, 
    -.0618688, 0, -.06524737, -.04419825, -.04489509, 0, 0, 0, -.04520512, -.04187583, 0, 0, -.03753508, 0, 0, 0, 0, 
    0, 0, 0, 0, .06862645, 0, 0, -.00120631, .01947345, 0, 0, .03561932, 0, .03158225, .03608047, 0, 0, 0, -.02899643),
    inter2<- c(-.78348798, -.63418788, 0, 0, 0, .11481193, 0, 0, 0, -.88128799, -1.109488, 0, 0, -.30888793, .29651192, 
    -.36688802, 0, 0, -.59088796, 0, .50561196, 0, 0, 0, 0, 0, 2.1662121, .08891205, 0, 0, 0, 0, 0, 0, -.23918791, 0, 
    -.9575879, -.07728811, .29641202, 1.2273121, 0, 1.5764117, 0, .72131211, 1.279212, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    .36481193, 1.5480118, -.03078791, 1.389112, 0, .70901209, -.16668792, 1.435812, .47001198, 2.0838118, 1.1673121, 
    0, 0, 1.4470119, .23301201, 0, 0, -.61948794, -.41388795, .263212, .66171199, 0, 0, 0, 1.6920118, 1.334012, 
    1.2101121, .41591194, -.48498794, 0, 0, .09911207, 0, -.46908805, .0205119, .0535119, -.14228792, -.55708808, 0, 
    -.54008788, -.30998799, -.10958811, 0, -.01338812, 0, -.51788801, 0, 0, .13271193, -.11208793, 0, -.54508799, 0, 
    .16641192, .95871216, 0, 1.6281118, 0, -.49718806, -.41348812, 0, 0, -.11718794, -.57058805, -.59488791, 0, 
    -.65658802, 0, -.52698797, 0, 0, 0, 0, 0, 1.3500118, 0, 1.665812, 0, 1.963912, 0, 0, 1.9371119, .90991193, 
    -.39558789, .39521196, 0, -.05268808, 0, 0, 0, 0, -.12458798, 0, -.28228804, .79281193, -.26358792, 0, 0, 0, 
    -.72828788, 0, .355912, 0, 0, 0, 0, -.43538806, -1.566388, 0, -.28388807, 0, -.69028801, 0, -.78128809, -.54648799, 
    -.92738789, 0, 0, .61571199, 0, 0, 1.012012, 0, 0, 0, 0, .43991187, .9404121, 0, 0, 0, .61671191, 0, 2.6073117, 
    0, -.60438794, 0, -.18108793, -.48178813, 0, -.22628804, -.07398792, 0, 0, 0, 1.830512, 0, 0, 0, 0, 0, 0, 
    -.36918804, 1.3247118, 0, 0, 1.163012, 0, 0, 0, 1.3241119, 0, 0, 0, 0, -.90038794, -1.250888, 0, 0, 0, 0, 
    -1.048188, -.90138787, 0, 0, 0, 0, 0, 0, -.00878807, 0, 0, .46301201, -.22048803, -.71518797, 0, 0, -.4952881, 
    0, -.83718795, .57951194, 0, 0, 0, 1.054112, .61721212, 2.2717118, 0, 2.0280118, 0, 0, 0, 2.6503119, 2.3914118, 
    0, -.36418793, -.9259879, 0, 0, .16971211, 0, 1.9360118, 2.5344119, 2.0171118, 0, 0, 0, 0, 0, 0, 0, 0, .77211195, 
    0, 0, 0, 0, 0, 1.952312, 0, 0, .25901201, 0, -.5028879, .03641204, 0, .38571194, 0, 0, -.44528791, -.55918807, 
    0, .39721206, 0, -.34038803, -.05988808, 0, -.03518792, .045512, 0, -.039288, 0, .01431207, 0, 0, .030412, 
    -.31918809, 0, 0, 0, -.324388, 0, -1.232188, 0, -.23678799, -.89188808, 0, -.6766879, 0, 0, 0, 0, 0, 0, 0, 
    -.67818803, 0, 1.099412, 1.2767119, -.64068788, -.50678796, 0, 0, 0, 0, 0, .68371207, .11251191, -.17128797, 
    .17081194, 0, -.48708794, .09591202, 0, -.20108791, -.02158805, 0, -.3012881, 0, 0, 0, -.87638801, -.54488796, 
    0, 0, 0, 0, -.14738794, 0, 0, 0, 0, -.75718802, -.37418792, 0, 1.0981121, 1.1441121, .47381189, 0, 0, 0, 
    -.33498809, 0, 0, 0, 0, -.91838807, 0, -.34488794, 0, .12971191, .99381214, -.91608804, 0, 0, .98171192, 0, 0, 
    0, 0, -.01528808, 0, -.41458794, .25691202, .18601207, 0, 0, 0, -.35608789, .79691201, 0, 0, 1.548912, 0, 0, 0, 
    0, 0, 0, 0, 0, 1.1663117, 0, 0, -.009088, -.49578807, 0, 0, -.2677879, 0, -.25468799, .68631202, 0, 0, 0, 
    -.36198804))
In [14]:
fit <- stan(model_code=cox_model, data=data, iter=2000, chains=2, verbose=T)
TRANSLATING MODEL '8a9184527d1aaa7826928917a7e1f9f5' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '8a9184527d1aaa7826928917a7e1f9f5'.
OS: x86_64, darwin15.4.0; rstan: 2.9.0.3; Rcpp: 0.12.5; inline: 0.3.14 
 >> setting environment variables: 
PKG_LIBS = 
PKG_CPPFLAGS =   -isystem"/usr/local/lib/R/3.2/site-library/Rcpp/include/"  -isystem"/usr/local/lib/R/3.2/site-library/RcppEigen/include/"  -isystem"/usr/local/lib/R/3.2/site-library/RcppEigen/include/unsupported"  -isystem"/usr/local/lib/R/3.2/site-library/rstan/include/boost_not_in_BH" -isystem"/usr/local/lib/R/3.2/site-library/BH/include" -isystem"/usr/local/lib/R/3.2/site-library/StanHeaders/include/src/"  -isystem"/usr/local/lib/R/3.2/site-library/StanHeaders/include/"  -I"/usr/local/lib/R/3.2/site-library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG
 >> 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.9
   7 : 
   8 : #include <stan/model/model_header.hpp>
   9 : 
  10 : namespace model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_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 model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5 : public prob_grad {
  27 : private:
  28 :     int Nsubj;
  29 :     int T;
  30 :     vector_d pscenter;
  31 :     vector_d hhcenter;
  32 :     vector<int> ncomact;
  33 :     vector<int> rleader;
  34 :     vector<int> dleader;
  35 :     vector_d inter1;
  36 :     vector_d inter2;
  37 :     vector<int> FAIL;
  38 :     vector<int> obs_t;
  39 :     vector<int> t;
  40 :     vector<vector<int> > Y;
  41 :     vector<vector<int> > dN;
  42 : public:
  43 :     model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5(stan::io::var_context& context__,
  44 :         std::ostream* pstream__ = 0)
  45 :         : prob_grad(0) {
  46 :         current_statement_begin__ = -1;
  47 : 
  48 :         static const char* function__ = "model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5";
  49 :         (void) function__; // dummy call to supress warning
  50 :         size_t pos__;
  51 :         (void) pos__; // dummy call to supress warning
  52 :         std::vector<int> vals_i__;
  53 :         std::vector<double> vals_r__;
  54 :         context__.validate_dims("data initialization", "Nsubj", "int", context__.to_vec());
  55 :         Nsubj = int(0);
  56 :         vals_i__ = context__.vals_i("Nsubj");
  57 :         pos__ = 0;
  58 :         Nsubj = vals_i__[pos__++];
  59 :         context__.validate_dims("data initialization", "T", "int", context__.to_vec());
  60 :         T = int(0);
  61 :         vals_i__ = context__.vals_i("T");
  62 :         pos__ = 0;
  63 :         T = vals_i__[pos__++];
  64 :         validate_non_negative_index("pscenter", "Nsubj", Nsubj);
  65 :         pscenter = vector_d(Nsubj);
  66 :         context__.validate_dims("data initialization", "pscenter", "vector_d", context__.to_vec(Nsubj));
  67 :         vals_r__ = context__.vals_r("pscenter");
  68 :         pos__ = 0;
  69 :         size_t pscenter_i_vec_lim__ = Nsubj;
  70 :         for (size_t i_vec__ = 0; i_vec__ < pscenter_i_vec_lim__; ++i_vec__) {
  71 :             pscenter[i_vec__] = vals_r__[pos__++];
  72 :         }
  73 :         validate_non_negative_index("hhcenter", "Nsubj", Nsubj);
  74 :         hhcenter = vector_d(Nsubj);
  75 :         context__.validate_dims("data initialization", "hhcenter", "vector_d", context__.to_vec(Nsubj));
  76 :         vals_r__ = context__.vals_r("hhcenter");
  77 :         pos__ = 0;
  78 :         size_t hhcenter_i_vec_lim__ = Nsubj;
  79 :         for (size_t i_vec__ = 0; i_vec__ < hhcenter_i_vec_lim__; ++i_vec__) {
  80 :             hhcenter[i_vec__] = vals_r__[pos__++];
  81 :         }
  82 :         context__.validate_dims("data initialization", "ncomact", "int", context__.to_vec(Nsubj));
  83 :         validate_non_negative_index("ncomact", "Nsubj", Nsubj);
  84 :         ncomact = std::vector<int>(Nsubj,int(0));
  85 :         vals_i__ = context__.vals_i("ncomact");
  86 :         pos__ = 0;
  87 :         size_t ncomact_limit_0__ = Nsubj;
  88 :         for (size_t i_0__ = 0; i_0__ < ncomact_limit_0__; ++i_0__) {
  89 :             ncomact[i_0__] = vals_i__[pos__++];
  90 :         }
  91 :         context__.validate_dims("data initialization", "rleader", "int", context__.to_vec(Nsubj));
  92 :         validate_non_negative_index("rleader", "Nsubj", Nsubj);
  93 :         rleader = std::vector<int>(Nsubj,int(0));
  94 :         vals_i__ = context__.vals_i("rleader");
  95 :         pos__ = 0;
  96 :         size_t rleader_limit_0__ = Nsubj;
  97 :         for (size_t i_0__ = 0; i_0__ < rleader_limit_0__; ++i_0__) {
  98 :             rleader[i_0__] = vals_i__[pos__++];
  99 :         }
 100 :         context__.validate_dims("data initialization", "dleader", "int", context__.to_vec(Nsubj));
 101 :         validate_non_negative_index("dleader", "Nsubj", Nsubj);
 102 :         dleader = std::vector<int>(Nsubj,int(0));
 103 :         vals_i__ = context__.vals_i("dleader");
 104 :         pos__ = 0;
 105 :         size_t dleader_limit_0__ = Nsubj;
 106 :         for (size_t i_0__ = 0; i_0__ < dleader_limit_0__; ++i_0__) {
 107 :             dleader[i_0__] = vals_i__[pos__++];
 108 :         }
 109 :         validate_non_negative_index("inter1", "Nsubj", Nsubj);
 110 :         inter1 = vector_d(Nsubj);
 111 :         context__.validate_dims("data initialization", "inter1", "vector_d", context__.to_vec(Nsubj));
 112 :         vals_r__ = context__.vals_r("inter1");
 113 :         pos__ = 0;
 114 :         size_t inter1_i_vec_lim__ = Nsubj;
 115 :         for (size_t i_vec__ = 0; i_vec__ < inter1_i_vec_lim__; ++i_vec__) {
 116 :             inter1[i_vec__] = vals_r__[pos__++];
 117 :         }
 118 :         validate_non_negative_index("inter2", "Nsubj", Nsubj);
 119 :         inter2 = vector_d(Nsubj);
 120 :         context__.validate_dims("data initialization", "inter2", "vector_d", context__.to_vec(Nsubj));
 121 :         vals_r__ = context__.vals_r("inter2");
 122 :         pos__ = 0;
 123 :         size_t inter2_i_vec_lim__ = Nsubj;
 124 :         for (size_t i_vec__ = 0; i_vec__ < inter2_i_vec_lim__; ++i_vec__) {
 125 :             inter2[i_vec__] = vals_r__[pos__++];
 126 :         }
 127 :         context__.validate_dims("data initialization", "FAIL", "int", context__.to_vec(Nsubj));
 128 :         validate_non_negative_index("FAIL", "Nsubj", Nsubj);
 129 :         FAIL = std::vector<int>(Nsubj,int(0));
 130 :         vals_i__ = context__.vals_i("FAIL");
 131 :         pos__ = 0;
 132 :         size_t FAIL_limit_0__ = Nsubj;
 133 :         for (size_t i_0__ = 0; i_0__ < FAIL_limit_0__; ++i_0__) {
 134 :             FAIL[i_0__] = vals_i__[pos__++];
 135 :         }
 136 :         context__.validate_dims("data initialization", "obs_t", "int", context__.to_vec(Nsubj));
 137 :         validate_non_negative_index("obs_t", "Nsubj", Nsubj);
 138 :         obs_t = std::vector<int>(Nsubj,int(0));
 139 :         vals_i__ = context__.vals_i("obs_t");
 140 :         pos__ = 0;
 141 :         size_t obs_t_limit_0__ = Nsubj;
 142 :         for (size_t i_0__ = 0; i_0__ < obs_t_limit_0__; ++i_0__) {
 143 :             obs_t[i_0__] = vals_i__[pos__++];
 144 :         }
 145 :         context__.validate_dims("data initialization", "t", "int", context__.to_vec(T));
 146 :         validate_non_negative_index("t", "T", T);
 147 :         t = std::vector<int>(T,int(0));
 148 :         vals_i__ = context__.vals_i("t");
 149 :         pos__ = 0;
 150 :         size_t t_limit_0__ = T;
 151 :         for (size_t i_0__ = 0; i_0__ < t_limit_0__; ++i_0__) {
 152 :             t[i_0__] = vals_i__[pos__++];
 153 :         }
 154 : 
 155 :         // validate data
 156 :         check_greater_or_equal(function__,"Nsubj",Nsubj,0);
 157 :         check_greater_or_equal(function__,"T",T,1);
 158 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 159 :             check_greater_or_equal(function__,"ncomact[k0__]",ncomact[k0__],0);
 160 :             check_less_or_equal(function__,"ncomact[k0__]",ncomact[k0__],1);
 161 :         }
 162 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 163 :             check_greater_or_equal(function__,"rleader[k0__]",rleader[k0__],0);
 164 :             check_less_or_equal(function__,"rleader[k0__]",rleader[k0__],1);
 165 :         }
 166 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 167 :             check_greater_or_equal(function__,"dleader[k0__]",dleader[k0__],0);
 168 :             check_less_or_equal(function__,"dleader[k0__]",dleader[k0__],1);
 169 :         }
 170 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 171 :             check_greater_or_equal(function__,"FAIL[k0__]",FAIL[k0__],0);
 172 :             check_less_or_equal(function__,"FAIL[k0__]",FAIL[k0__],1);
 173 :         }
 174 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 175 :             check_greater_or_equal(function__,"obs_t[k0__]",obs_t[k0__],0);
 176 :         }
 177 :         for (int k0__ = 0; k0__ < T; ++k0__) {
 178 :             check_greater_or_equal(function__,"t[k0__]",t[k0__],0);
 179 :         }
 180 :         validate_non_negative_index("Y", "Nsubj", Nsubj);
 181 :         validate_non_negative_index("Y", "T", T);
 182 :         Y = std::vector<std::vector<int> >(Nsubj,std::vector<int>(T,int(0)));
 183 :         validate_non_negative_index("dN", "Nsubj", Nsubj);
 184 :         validate_non_negative_index("dN", "T", T);
 185 :         dN = std::vector<std::vector<int> >(Nsubj,std::vector<int>(T,int(0)));
 186 : 
 187 :         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 188 :         (void) DUMMY_VAR__;  // suppress unused var warning
 189 : 
 190 : 
 191 :         // initialize transformed variables to avoid seg fault on val access
 192 :         stan::math::fill(Y,DUMMY_VAR__);
 193 :         stan::math::fill(dN,DUMMY_VAR__);
 194 : 
 195 :         try {
 196 :             current_statement_begin__ = 22;
 197 :             for (int i = 1; i <= Nsubj; ++i) {
 198 :                 current_statement_begin__ = 23;
 199 :                 for (int j = 1; j <= T; ++j) {
 200 :                     current_statement_begin__ = 25;
 201 :                     stan::math::assign(get_base1_lhs(get_base1_lhs(Y,i,"Y",1),j,"Y",2), int_step((get_base1(obs_t,i,"obs_t",1) - get_base1(t,j,"t",1))));
 202 :                     current_statement_begin__ = 27;
 203 :                     stan::math::assign(get_base1_lhs(get_base1_lhs(dN,i,"dN",1),j,"dN",2), ((get_base1(get_base1(Y,i,"Y",1),j,"Y",2) * int_step((get_base1(t,(j + 1),"t",1) - get_base1(obs_t,i,"obs_t",1)))) * get_base1(FAIL,i,"FAIL",1)));
 204 :                 }
 205 :             }
 206 :         } catch (const std::exception& e) {
 207 :             stan::lang::rethrow_located(e,current_statement_begin__);
 208 :             // Next line prevents compiler griping about no return
 209 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 210 :         }
 211 : 
 212 :         // validate transformed data
 213 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 214 :             for (int k1__ = 0; k1__ < T; ++k1__) {
 215 :                 check_greater_or_equal(function__,"Y[k0__][k1__]",Y[k0__][k1__],0);
 216 :             }
 217 :         }
 218 :         for (int k0__ = 0; k0__ < Nsubj; ++k0__) {
 219 :             for (int k1__ = 0; k1__ < T; ++k1__) {
 220 :                 check_greater_or_equal(function__,"dN[k0__][k1__]",dN[k0__][k1__],0);
 221 :             }
 222 :         }
 223 : 
 224 :         // set parameter ranges
 225 :         num_params_r__ = 0U;
 226 :         param_ranges_i__.clear();
 227 :         num_params_r__ += 7;
 228 :         ++num_params_r__;
 229 :         ++num_params_r__;
 230 :         num_params_r__ += T;
 231 :     }
 232 : 
 233 :     ~model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5() { }
 234 : 
 235 : 
 236 :     void transform_inits(const stan::io::var_context& context__,
 237 :                          std::vector<int>& params_i__,
 238 :                          std::vector<double>& params_r__,
 239 :                          std::ostream* pstream__) const {
 240 :         stan::io::writer<double> writer__(params_r__,params_i__);
 241 :         size_t pos__;
 242 :         (void) pos__; // dummy call to supress warning
 243 :         std::vector<double> vals_r__;
 244 :         std::vector<int> vals_i__;
 245 : 
 246 :         if (!(context__.contains_r("beta")))
 247 :             throw std::runtime_error("variable beta missing");
 248 :         vals_r__ = context__.vals_r("beta");
 249 :         pos__ = 0U;
 250 :         context__.validate_dims("initialization", "beta", "vector_d", context__.to_vec(7));
 251 :         vector_d beta(7);
 252 :         for (int j1__ = 0U; j1__ < 7; ++j1__)
 253 :             beta(j1__) = vals_r__[pos__++];
 254 :         try {
 255 :             writer__.vector_unconstrain(beta);
 256 :         } catch (const std::exception& e) { 
 257 :             throw std::runtime_error(std::string("Error transforming variable beta: ") + e.what());
 258 :         }
 259 : 
 260 :         if (!(context__.contains_r("c")))
 261 :             throw std::runtime_error("variable c missing");
 262 :         vals_r__ = context__.vals_r("c");
 263 :         pos__ = 0U;
 264 :         context__.validate_dims("initialization", "c", "double", context__.to_vec());
 265 :         double c(0);
 266 :         c = vals_r__[pos__++];
 267 :         try {
 268 :             writer__.scalar_lb_unconstrain(0,c);
 269 :         } catch (const std::exception& e) { 
 270 :             throw std::runtime_error(std::string("Error transforming variable c: ") + e.what());
 271 :         }
 272 : 
 273 :         if (!(context__.contains_r("r")))
 274 :             throw std::runtime_error("variable r missing");
 275 :         vals_r__ = context__.vals_r("r");
 276 :         pos__ = 0U;
 277 :         context__.validate_dims("initialization", "r", "double", context__.to_vec());
 278 :         double r(0);
 279 :         r = vals_r__[pos__++];
 280 :         try {
 281 :             writer__.scalar_lb_unconstrain(0,r);
 282 :         } catch (const std::exception& e) { 
 283 :             throw std::runtime_error(std::string("Error transforming variable r: ") + e.what());
 284 :         }
 285 : 
 286 :         if (!(context__.contains_r("dL0")))
 287 :             throw std::runtime_error("variable dL0 missing");
 288 :         vals_r__ = context__.vals_r("dL0");
 289 :         pos__ = 0U;
 290 :         context__.validate_dims("initialization", "dL0", "vector_d", context__.to_vec(T));
 291 :         vector_d dL0(T);
 292 :         for (int j1__ = 0U; j1__ < T; ++j1__)
 293 :             dL0(j1__) = vals_r__[pos__++];
 294 :         try {
 295 :             writer__.vector_unconstrain(dL0);
 296 :         } catch (const std::exception& e) { 
 297 :             throw std::runtime_error(std::string("Error transforming variable dL0: ") + e.what());
 298 :         }
 299 : 
 300 :         params_r__ = writer__.data_r();
 301 :         params_i__ = writer__.data_i();
 302 :     }
 303 : 
 304 :     void transform_inits(const stan::io::var_context& context,
 305 :                          Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 306 :                          std::ostream* pstream__) const {
 307 :       std::vector<double> params_r_vec;
 308 :       std::vector<int> params_i_vec;
 309 :       transform_inits(context, params_i_vec, params_r_vec, pstream__);
 310 :       params_r.resize(params_r_vec.size());
 311 :       for (int i = 0; i < params_r.size(); ++i)
 312 :         params_r(i) = params_r_vec[i];
 313 :     }
 314 : 
 315 : 
 316 :     template <bool propto__, bool jacobian__, typename T__>
 317 :     T__ log_prob(vector<T__>& params_r__,
 318 :                  vector<int>& params_i__,
 319 :                  std::ostream* pstream__ = 0) const {
 320 : 
 321 :         T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 322 :         (void) DUMMY_VAR__;  // suppress unused var warning
 323 : 
 324 :         T__ lp__(0.0);
 325 :         stan::math::accumulator<T__> lp_accum__;
 326 : 
 327 :         // model parameters
 328 :         stan::io::reader<T__> in__(params_r__,params_i__);
 329 : 
 330 :         Eigen::Matrix<T__,Eigen::Dynamic,1>  beta;
 331 :         (void) beta;   // dummy to suppress unused var warning
 332 :         if (jacobian__)
 333 :             beta = in__.vector_constrain(7,lp__);
 334 :         else
 335 :             beta = in__.vector_constrain(7);
 336 : 
 337 :         T__ c;
 338 :         (void) c;   // dummy to suppress unused var warning
 339 :         if (jacobian__)
 340 :             c = in__.scalar_lb_constrain(0,lp__);
 341 :         else
 342 :             c = in__.scalar_lb_constrain(0);
 343 : 
 344 :         T__ r;
 345 :         (void) r;   // dummy to suppress unused var warning
 346 :         if (jacobian__)
 347 :             r = in__.scalar_lb_constrain(0,lp__);
 348 :         else
 349 :             r = in__.scalar_lb_constrain(0);
 350 : 
 351 :         Eigen::Matrix<T__,Eigen::Dynamic,1>  dL0;
 352 :         (void) dL0;   // dummy to suppress unused var warning
 353 :         if (jacobian__)
 354 :             dL0 = in__.vector_constrain(T,lp__);
 355 :         else
 356 :             dL0 = in__.vector_constrain(T);
 357 : 
 358 : 
 359 :         // transformed parameters
 360 :         Eigen::Matrix<T__,Eigen::Dynamic,1>  mu(T);
 361 :         (void) mu;  // dummy to suppress unused var warning
 362 :         stan::math::fill(mu,DUMMY_VAR__);
 363 :         Eigen::Matrix<T__,Eigen::Dynamic,Eigen::Dynamic>  Idt(Nsubj,T);
 364 :         (void) Idt;  // dummy to suppress unused var warning
 365 :         stan::math::fill(Idt,DUMMY_VAR__);
 366 :         Eigen::Matrix<T__,Eigen::Dynamic,1>  dL0_star(T);
 367 :         (void) dL0_star;  // dummy to suppress unused var warning
 368 :         stan::math::fill(dL0_star,DUMMY_VAR__);
 369 : 
 370 :         // initialize transformed variables to avoid seg fault on val access
 371 :         stan::math::fill(mu,DUMMY_VAR__);
 372 :         stan::math::fill(Idt,DUMMY_VAR__);
 373 :         stan::math::fill(dL0_star,DUMMY_VAR__);
 374 : 
 375 :         try {
 376 :             current_statement_begin__ = 44;
 377 :             for (int j = 1; j <= T; ++j) {
 378 :                 current_statement_begin__ = 45;
 379 :                 for (int i = 1; i <= Nsubj; ++i) {
 380 :                     current_statement_begin__ = 47;
 381 :                     stan::math::assign(get_base1_lhs(Idt,i,j,"Idt",1), ((get_base1(get_base1(Y,i,"Y",1),j,"Y",2) * exp((((((((get_base1(beta,1,"beta",1) * get_base1(pscenter,i,"pscenter",1)) + (get_base1(beta,2,"beta",1) * get_base1(hhcenter,i,"hhcenter",1))) + (get_base1(beta,3,"beta",1) * get_base1(ncomact,i,"ncomact",1))) + (get_base1(beta,4,"beta",1) * get_base1(rleader,i,"rleader",1))) + (get_base1(beta,5,"beta",1) * get_base1(dleader,i,"dleader",1))) + (get_base1(beta,6,"beta",1) * get_base1(inter1,i,"inter1",1))) + (get_base1(beta,7,"beta",1) * get_base1(inter2,i,"inter2",1))))) * get_base1(dL0,j,"dL0",1)));
 382 :                 }
 383 :                 current_statement_begin__ = 51;
 384 :                 stan::math::assign(get_base1_lhs(mu,j,"mu",1), (get_base1(dL0_star,j,"dL0_star",1) * c));
 385 :                 current_statement_begin__ = 53;
 386 :                 stan::math::assign(get_base1_lhs(dL0_star,j,"dL0_star",1), (r * (get_base1(t,(j + 1),"t",1) - get_base1(t,j,"t",1))));
 387 :             }
 388 :         } catch (const std::exception& e) {
 389 :             stan::lang::rethrow_located(e,current_statement_begin__);
 390 :             // Next line prevents compiler griping about no return
 391 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 392 :         }
 393 : 
 394 :         // validate transformed parameters
 395 :         for (int i0__ = 0; i0__ < T; ++i0__) {
 396 :             if (stan::math::is_uninitialized(mu(i0__))) {
 397 :                 std::stringstream msg__;
 398 :                 msg__ << "Undefined transformed parameter: mu" << '[' << i0__ << ']';
 399 :                 throw std::runtime_error(msg__.str());
 400 :             }
 401 :         }
 402 :         for (int i0__ = 0; i0__ < Nsubj; ++i0__) {
 403 :             for (int i1__ = 0; i1__ < T; ++i1__) {
 404 :                 if (stan::math::is_uninitialized(Idt(i0__,i1__))) {
 405 :                     std::stringstream msg__;
 406 :                     msg__ << "Undefined transformed parameter: Idt" << '[' << i0__ << ']' << '[' << i1__ << ']';
 407 :                     throw std::runtime_error(msg__.str());
 408 :                 }
 409 :             }
 410 :         }
 411 :         for (int i0__ = 0; i0__ < T; ++i0__) {
 412 :             if (stan::math::is_uninitialized(dL0_star(i0__))) {
 413 :                 std::stringstream msg__;
 414 :                 msg__ << "Undefined transformed parameter: dL0_star" << '[' << i0__ << ']';
 415 :                 throw std::runtime_error(msg__.str());
 416 :             }
 417 :         }
 418 : 
 419 :         const char* function__ = "validate transformed params";
 420 :         (void) function__; // dummy to suppress unused var warning
 421 : 
 422 :         // model body
 423 :         try {
 424 :             current_statement_begin__ = 59;
 425 :             for (int j = 1; j <= T; ++j) {
 426 :                 current_statement_begin__ = 60;
 427 :                 for (int i = 1; i <= Nsubj; ++i) {
 428 :                     current_statement_begin__ = 62;
 429 :                     lp_accum__.add(poisson_log<propto__>(get_base1(get_base1(dN,i,"dN",1),j,"dN",2), get_base1(Idt,i,j,"Idt",1)));
 430 :                 }
 431 :                 current_statement_begin__ = 64;
 432 :                 lp_accum__.add(gamma_log<propto__>(get_base1(dL0,j,"dL0",1), get_base1(mu,j,"mu",1), c));
 433 :             }
 434 :             current_statement_begin__ = 67;
 435 :             lp_accum__.add(gamma_log<propto__>(c, 0.0001, 1.0000000000000001e-05));
 436 :             current_statement_begin__ = 68;
 437 :             lp_accum__.add(gamma_log<propto__>(r, 0.001, 0.0001));
 438 :             current_statement_begin__ = 70;
 439 :             lp_accum__.add(normal_log<propto__>(beta, 0.0, 100000));
 440 :         } catch (const std::exception& e) {
 441 :             stan::lang::rethrow_located(e,current_statement_begin__);
 442 :             // Next line prevents compiler griping about no return
 443 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 444 :         }
 445 : 
 446 :         lp_accum__.add(lp__);
 447 :         return lp_accum__.sum();
 448 : 
 449 :     } // log_prob()
 450 : 
 451 :     template <bool propto, bool jacobian, typename T_>
 452 :     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
 453 :                std::ostream* pstream = 0) const {
 454 :       std::vector<T_> vec_params_r;
 455 :       vec_params_r.reserve(params_r.size());
 456 :       for (int i = 0; i < params_r.size(); ++i)
 457 :         vec_params_r.push_back(params_r(i));
 458 :       std::vector<int> vec_params_i;
 459 :       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
 460 :     }
 461 : 
 462 : 
 463 :     void get_param_names(std::vector<std::string>& names__) const {
 464 :         names__.resize(0);
 465 :         names__.push_back("beta");
 466 :         names__.push_back("c");
 467 :         names__.push_back("r");
 468 :         names__.push_back("dL0");
 469 :         names__.push_back("mu");
 470 :         names__.push_back("Idt");
 471 :         names__.push_back("dL0_star");
 472 :     }
 473 : 
 474 : 
 475 :     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
 476 :         dimss__.resize(0);
 477 :         std::vector<size_t> dims__;
 478 :         dims__.resize(0);
 479 :         dims__.push_back(7);
 480 :         dimss__.push_back(dims__);
 481 :         dims__.resize(0);
 482 :         dimss__.push_back(dims__);
 483 :         dims__.resize(0);
 484 :         dimss__.push_back(dims__);
 485 :         dims__.resize(0);
 486 :         dims__.push_back(T);
 487 :         dimss__.push_back(dims__);
 488 :         dims__.resize(0);
 489 :         dims__.push_back(T);
 490 :         dimss__.push_back(dims__);
 491 :         dims__.resize(0);
 492 :         dims__.push_back(Nsubj);
 493 :         dims__.push_back(T);
 494 :         dimss__.push_back(dims__);
 495 :         dims__.resize(0);
 496 :         dims__.push_back(T);
 497 :         dimss__.push_back(dims__);
 498 :     }
 499 : 
 500 :     template <typename RNG>
 501 :     void write_array(RNG& base_rng__,
 502 :                      std::vector<double>& params_r__,
 503 :                      std::vector<int>& params_i__,
 504 :                      std::vector<double>& vars__,
 505 :                      bool include_tparams__ = true,
 506 :                      bool include_gqs__ = true,
 507 :                      std::ostream* pstream__ = 0) const {
 508 :         vars__.resize(0);
 509 :         stan::io::reader<double> in__(params_r__,params_i__);
 510 :         static const char* function__ = "model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::write_array";
 511 :         (void) function__; // dummy call to supress warning
 512 :         // read-transform, write parameters
 513 :         vector_d beta = in__.vector_constrain(7);
 514 :         double c = in__.scalar_lb_constrain(0);
 515 :         double r = in__.scalar_lb_constrain(0);
 516 :         vector_d dL0 = in__.vector_constrain(T);
 517 :         for (int k_0__ = 0; k_0__ < 7; ++k_0__) {
 518 :             vars__.push_back(beta[k_0__]);
 519 :         }
 520 :         vars__.push_back(c);
 521 :         vars__.push_back(r);
 522 :         for (int k_0__ = 0; k_0__ < T; ++k_0__) {
 523 :             vars__.push_back(dL0[k_0__]);
 524 :         }
 525 : 
 526 :         if (!include_tparams__) return;
 527 :         // declare and define transformed parameters
 528 :         double lp__ = 0.0;
 529 :         (void) lp__; // dummy call to supress warning
 530 :         stan::math::accumulator<double> lp_accum__;
 531 : 
 532 :         vector_d mu(T);
 533 :         (void) mu;  // dummy to suppress unused var warning
 534 :         matrix_d Idt(Nsubj,T);
 535 :         (void) Idt;  // dummy to suppress unused var warning
 536 :         vector_d dL0_star(T);
 537 :         (void) dL0_star;  // dummy to suppress unused var warning
 538 : 
 539 :         try {
 540 :             current_statement_begin__ = 44;
 541 :             for (int j = 1; j <= T; ++j) {
 542 :                 current_statement_begin__ = 45;
 543 :                 for (int i = 1; i <= Nsubj; ++i) {
 544 :                     current_statement_begin__ = 47;
 545 :                     stan::math::assign(get_base1_lhs(Idt,i,j,"Idt",1), ((get_base1(get_base1(Y,i,"Y",1),j,"Y",2) * exp((((((((get_base1(beta,1,"beta",1) * get_base1(pscenter,i,"pscenter",1)) + (get_base1(beta,2,"beta",1) * get_base1(hhcenter,i,"hhcenter",1))) + (get_base1(beta,3,"beta",1) * get_base1(ncomact,i,"ncomact",1))) + (get_base1(beta,4,"beta",1) * get_base1(rleader,i,"rleader",1))) + (get_base1(beta,5,"beta",1) * get_base1(dleader,i,"dleader",1))) + (get_base1(beta,6,"beta",1) * get_base1(inter1,i,"inter1",1))) + (get_base1(beta,7,"beta",1) * get_base1(inter2,i,"inter2",1))))) * get_base1(dL0,j,"dL0",1)));
 546 :                 }
 547 :                 current_statement_begin__ = 51;
 548 :                 stan::math::assign(get_base1_lhs(mu,j,"mu",1), (get_base1(dL0_star,j,"dL0_star",1) * c));
 549 :                 current_statement_begin__ = 53;
 550 :                 stan::math::assign(get_base1_lhs(dL0_star,j,"dL0_star",1), (r * (get_base1(t,(j + 1),"t",1) - get_base1(t,j,"t",1))));
 551 :             }
 552 :         } catch (const std::exception& e) {
 553 :             stan::lang::rethrow_located(e,current_statement_begin__);
 554 :             // Next line prevents compiler griping about no return
 555 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 556 :         }
 557 : 
 558 :         // validate transformed parameters
 559 : 
 560 :         // write transformed parameters
 561 :         for (int k_0__ = 0; k_0__ < T; ++k_0__) {
 562 :             vars__.push_back(mu[k_0__]);
 563 :         }
 564 :         for (int k_1__ = 0; k_1__ < T; ++k_1__) {
 565 :             for (int k_0__ = 0; k_0__ < Nsubj; ++k_0__) {
 566 :                 vars__.push_back(Idt(k_0__, k_1__));
 567 :             }
 568 :         }
 569 :         for (int k_0__ = 0; k_0__ < T; ++k_0__) {
 570 :             vars__.push_back(dL0_star[k_0__]);
 571 :         }
 572 : 
 573 :         if (!include_gqs__) return;
 574 :         // declare and define generated quantities
 575 : 
 576 :         double DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 577 :         (void) DUMMY_VAR__;  // suppress unused var warning
 578 : 
 579 : 
 580 :         // initialize transformed variables to avoid seg fault on val access
 581 : 
 582 :         try {
 583 :         } catch (const std::exception& e) {
 584 :             stan::lang::rethrow_located(e,current_statement_begin__);
 585 :             // Next line prevents compiler griping about no return
 586 : throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 587 :         }
 588 : 
 589 :         // validate generated quantities
 590 : 
 591 :         // write generated quantities
 592 :     }
 593 : 
 594 :     template <typename RNG>
 595 :     void write_array(RNG& base_rng,
 596 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 597 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
 598 :                      bool include_tparams = true,
 599 :                      bool include_gqs = true,
 600 :                      std::ostream* pstream = 0) const {
 601 :       std::vector<double> params_r_vec(params_r.size());
 602 :       for (int i = 0; i < params_r.size(); ++i)
 603 :         params_r_vec[i] = params_r(i);
 604 :       std::vector<double> vars_vec;
 605 :       std::vector<int> params_i_vec;
 606 :       write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
 607 :       vars.resize(vars_vec.size());
 608 :       for (int i = 0; i < vars.size(); ++i)
 609 :         vars(i) = vars_vec[i];
 610 :     }
 611 : 
 612 :     static std::string model_name() {
 613 :         return "model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5";
 614 :     }
 615 : 
 616 : 
 617 :     void constrained_param_names(std::vector<std::string>& param_names__,
 618 :                                  bool include_tparams__ = true,
 619 :                                  bool include_gqs__ = true) const {
 620 :         std::stringstream param_name_stream__;
 621 :         for (int k_0__ = 1; k_0__ <= 7; ++k_0__) {
 622 :             param_name_stream__.str(std::string());
 623 :             param_name_stream__ << "beta" << '.' << k_0__;
 624 :             param_names__.push_back(param_name_stream__.str());
 625 :         }
 626 :         param_name_stream__.str(std::string());
 627 :         param_name_stream__ << "c";
 628 :         param_names__.push_back(param_name_stream__.str());
 629 :         param_name_stream__.str(std::string());
 630 :         param_name_stream__ << "r";
 631 :         param_names__.push_back(param_name_stream__.str());
 632 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 633 :             param_name_stream__.str(std::string());
 634 :             param_name_stream__ << "dL0" << '.' << k_0__;
 635 :             param_names__.push_back(param_name_stream__.str());
 636 :         }
 637 : 
 638 :         if (!include_gqs__ && !include_tparams__) return;
 639 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 640 :             param_name_stream__.str(std::string());
 641 :             param_name_stream__ << "mu" << '.' << k_0__;
 642 :             param_names__.push_back(param_name_stream__.str());
 643 :         }
 644 :         for (int k_1__ = 1; k_1__ <= T; ++k_1__) {
 645 :             for (int k_0__ = 1; k_0__ <= Nsubj; ++k_0__) {
 646 :                 param_name_stream__.str(std::string());
 647 :                 param_name_stream__ << "Idt" << '.' << k_0__ << '.' << k_1__;
 648 :                 param_names__.push_back(param_name_stream__.str());
 649 :             }
 650 :         }
 651 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 652 :             param_name_stream__.str(std::string());
 653 :             param_name_stream__ << "dL0_star" << '.' << k_0__;
 654 :             param_names__.push_back(param_name_stream__.str());
 655 :         }
 656 : 
 657 :         if (!include_gqs__) return;
 658 :     }
 659 : 
 660 : 
 661 :     void unconstrained_param_names(std::vector<std::string>& param_names__,
 662 :                                    bool include_tparams__ = true,
 663 :                                    bool include_gqs__ = true) const {
 664 :         std::stringstream param_name_stream__;
 665 :         for (int k_0__ = 1; k_0__ <= 7; ++k_0__) {
 666 :             param_name_stream__.str(std::string());
 667 :             param_name_stream__ << "beta" << '.' << k_0__;
 668 :             param_names__.push_back(param_name_stream__.str());
 669 :         }
 670 :         param_name_stream__.str(std::string());
 671 :         param_name_stream__ << "c";
 672 :         param_names__.push_back(param_name_stream__.str());
 673 :         param_name_stream__.str(std::string());
 674 :         param_name_stream__ << "r";
 675 :         param_names__.push_back(param_name_stream__.str());
 676 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 677 :             param_name_stream__.str(std::string());
 678 :             param_name_stream__ << "dL0" << '.' << k_0__;
 679 :             param_names__.push_back(param_name_stream__.str());
 680 :         }
 681 : 
 682 :         if (!include_gqs__ && !include_tparams__) return;
 683 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 684 :             param_name_stream__.str(std::string());
 685 :             param_name_stream__ << "mu" << '.' << k_0__;
 686 :             param_names__.push_back(param_name_stream__.str());
 687 :         }
 688 :         for (int k_1__ = 1; k_1__ <= T; ++k_1__) {
 689 :             for (int k_0__ = 1; k_0__ <= Nsubj; ++k_0__) {
 690 :                 param_name_stream__.str(std::string());
 691 :                 param_name_stream__ << "Idt" << '.' << k_0__ << '.' << k_1__;
 692 :                 param_names__.push_back(param_name_stream__.str());
 693 :             }
 694 :         }
 695 :         for (int k_0__ = 1; k_0__ <= T; ++k_0__) {
 696 :             param_name_stream__.str(std::string());
 697 :             param_name_stream__ << "dL0_star" << '.' << k_0__;
 698 :             param_names__.push_back(param_name_stream__.str());
 699 :         }
 700 : 
 701 :         if (!include_gqs__) return;
 702 :     }
 703 : 
 704 : }; // model
 705 : 
 706 : } // namespace
 707 : 
 708 : typedef model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5 stan_model;
 709 : 
 710 : #include <rstan/rstaninc.hpp>
 711 : /**
 712 :  * Define Rcpp Module to expose stan_fit's functions to R.
 713 :  */
 714 : RCPP_MODULE(stan_fit4model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_mod){
 715 :   Rcpp::class_<rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5,
 716 :                boost::random::ecuyer1988> >("stan_fit4model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5")
 717 :     // .constructor<Rcpp::List>()
 718 :     .constructor<SEXP, SEXP>()
 719 :     // .constructor<SEXP, SEXP>()
 720 :     .method("call_sampler",
 721 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::call_sampler)
 722 :     .method("param_names",
 723 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_names)
 724 :     .method("param_names_oi",
 725 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_names_oi)
 726 :     .method("param_fnames_oi",
 727 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_fnames_oi)
 728 :     .method("param_dims",
 729 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_dims)
 730 :     .method("param_dims_oi",
 731 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_dims_oi)
 732 :     .method("update_param_oi",
 733 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::update_param_oi)
 734 :     .method("param_oi_tidx",
 735 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::param_oi_tidx)
 736 :     .method("grad_log_prob",
 737 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::grad_log_prob)
 738 :     .method("log_prob",
 739 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::log_prob)
 740 :     .method("unconstrain_pars",
 741 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::unconstrain_pars)
 742 :     .method("constrain_pars",
 743 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::constrain_pars)
 744 :     .method("num_pars_unconstrained",
 745 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::num_pars_unconstrained)
 746 :     .method("unconstrained_param_names",
 747 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::unconstrained_param_names)
 748 :     .method("constrained_param_names",
 749 :             &rstan::stan_fit<model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5_namespace::model102d870fa5876_8a9184527d1aaa7826928917a7e1f9f5, boost::random::ecuyer1988>::constrained_param_names)
 750 :     ;
 751 : }
 752 : 
 753 : // declarations
 754 : extern "C" {
 755 : SEXP file102d843c5e4ec( ) ;
 756 : }
 757 : 
 758 : // definition
 759 : 
 760 : SEXP file102d843c5e4ec(  ){
 761 :  return Rcpp::wrap("8a9184527d1aaa7826928917a7e1f9f5");
 762 : }
 763 : 
 764 : 
Compilation argument:
 /usr/local/Cellar/r/3.2.5/R.framework/Resources/bin/R CMD SHLIB file102d843c5e4ec.cpp 2> file102d843c5e4ec.cpp.err.txt 

CHECKING DATA AND PREPROCESSING FOR MODEL '8a9184527d1aaa7826928917a7e1f9f5' NOW.

COMPILING MODEL '8a9184527d1aaa7826928917a7e1f9f5' NOW.

STARTING SAMPLER FOR MODEL '8a9184527d1aaa7826928917a7e1f9f5' NOW.
failed to create the sampler; sampling not done