Skip to content

Commit

Permalink
remove model 5 from test code, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jburos committed Nov 22, 2016
1 parent 93f0cff commit c11a8a7
Showing 1 changed file with 0 additions and 84 deletions.
Expand Up @@ -833,90 +833,6 @@
"survivalstan.utils.print_stan_summary([testfit4], pars=['lp__', 'alpha', 'beta'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## model 5: move idx_cens & idx_obs into transformed-data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model_code5 = '''\n",
"functions {\n",
" int count_value(vector a, real val) {\n",
" int s;\n",
" s = 0;\n",
" for (i in 1:num_elements(a)) \n",
" if (a[i] == val) \n",
" s = s + 1;\n",
" return s;\n",
" }\n",
"\n",
" // Defines the log survival\n",
" real surv_gamma_lpdf (vector t, vector d, real shape, vector rate, int num_cens, int num_obs) {\n",
" vector[2] log_lik;\n",
" int idx_obs[num_obs];\n",
" int idx_cens[num_cens];\n",
" real prob;\n",
" int i_cens;\n",
" int i_obs;\n",
" i_cens = 1;\n",
" i_obs = 1;\n",
" for (i in 1:num_elements(t)) {\n",
" if (d[i] == 1) {\n",
" idx_obs[i_obs] = i;\n",
" i_obs = i_obs+1;\n",
" }\n",
" else {\n",
" idx_cens[i_cens] = i;\n",
" i_cens = i_cens+1;\n",
" }\n",
" }\n",
" print(idx_obs);\n",
" log_lik[1] = gamma_lpdf(t[idx_obs] | shape, rate[idx_obs]);\n",
" log_lik[2] = gamma_lccdf(t[idx_cens] | shape, rate[idx_cens]);\n",
" prob = sum(log_lik);\n",
" return prob;\n",
" }\n",
"}\n",
"data {\n",
" int N; // number of observations\n",
" vector<lower=0>[N] y; // observed times\n",
" vector<lower=0,upper=1>[N] event; // censoring indicator (1=observed, 0=censored)\n",
" int M; // number of covariates\n",
" matrix[N, M] x; // matrix of covariates (with n rows and H columns)\n",
"}\n",
"transformed data {\n",
" int num_cens;\n",
" int num_obs;\n",
" num_obs = count_value(event, 1);\n",
" num_cens = N - num_obs;\n",
"}\n",
"parameters {\n",
" vector[M] beta; // Coefficients in the linear predictor (including intercept)\n",
" real<lower=0> alpha; // shape parameter\n",
"}\n",
"transformed parameters {\n",
" vector[N] linpred;\n",
" vector[N] mu;\n",
" linpred = x*beta;\n",
" mu = exp(linpred);\n",
"}\n",
"model {\n",
" alpha ~ gamma(0.01,0.01);\n",
" beta ~ normal(0,5);\n",
" y ~ surv_gamma(event, alpha, mu, num_cens, num_obs);\n",
"}\n",
"'''"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit c11a8a7

Please sign in to comment.