Last active
September 5, 2018 21:26
-
-
Save credpath/6d4ce21bac3cf6d1b1dab267eed2120f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trying out a censoring thing | |
data | |
{ | |
int<lower=2> K; // there are K categories for data y | |
int<lower=1> N; // N obersevations | |
int<lower=1,upper=K> y[N]; // outcome variable | |
int<lower=1,upper=11> x[N]; // predictor variable | |
} | |
parameters | |
{ | |
real mu; // mean of log of latent variable | |
real<lower=0> sigma_sq; // variance of log of latent variable | |
real latent_y[N]; // latent variable = log income | |
real beta; // coefficient on predictor variable (slope) | |
real alpha; // intercept | |
} | |
transformed parameters | |
{ | |
real<lower=0> sigma; // standard deviation of log income | |
sigma = sqrt(sigma_sq); // standard deviation of log income | |
} | |
model | |
{ | |
exp(mu) + 12.7 ~ normal(75738,20000); // mean of income is distruted with mean and standard deviation from US Census (technically not normal beause stricty positive) NB: NEED TO ADD LOG JACOBIAN HERE! | |
sigma ~ cauchy(0,10); // weak prior (half cauchy due to restriction) | |
latent_y ~ normal(mu, sigma); // latent_y = log(income) which is normal | |
for(n in 1:N) | |
{ | |
if(y[n] == 1) | |
{ | |
target += normal_lcdf(5000 | mu, sigma); | |
} | |
else if(y[n] == 2) | |
{ | |
target += log_diff_exp(normal_lcdf(7500 | mu, sigma), | |
normal_lcdf(5000 | mu, sigma)); | |
} | |
else if(y[n] == 3) | |
{ | |
target += log_diff_exp(normal_lcdf(10000 | mu, sigma), | |
normal_lcdf(7500 | mu, sigma)); | |
} | |
else if(y[n] == 4) | |
{ | |
target += log_diff_exp(normal_lcdf(12500 | mu, sigma), | |
normal_lcdf(10000 | mu, sigma)); | |
} | |
else if(y[n] == 5) | |
{ | |
target += log_diff_exp(normal_lcdf(15000 | mu, sigma), | |
normal_lcdf(12500 | mu, sigma)); | |
} | |
else if(y[n] == 6) | |
{ | |
target += log_diff_exp(normal_lcdf(20000 | mu, sigma), | |
normal_lcdf(15000 | mu, sigma)); | |
} | |
else if(y[n] == 7) | |
{ | |
target += log_diff_exp(normal_lcdf(25000 | mu, sigma), | |
normal_lcdf(20000 | mu, sigma)); | |
} | |
else if(y[n] == 8) | |
{ | |
target += log_diff_exp(normal_lcdf(30000 | mu, sigma), | |
normal_lcdf(25000 | mu, sigma)); | |
} | |
else if(y[n] == 9) | |
{ | |
target += log_diff_exp(normal_lcdf(35000 | mu, sigma), | |
normal_lcdf(30000 | mu, sigma)); | |
} | |
else if(y[n] == 10) | |
{ | |
target += log_diff_exp(normal_lcdf(40000 | mu, sigma), | |
normal_lcdf(35000 | mu, sigma)); | |
} | |
else if(y[n] == 11) | |
{ | |
target += log_diff_exp(normal_lcdf(50000 | mu, sigma), | |
normal_lcdf(40000 | mu, sigma)); | |
} | |
else if(y[n] == 12) | |
{ | |
target += log_diff_exp(normal_lcdf(60000 | mu, sigma), | |
normal_lcdf(50000 | mu, sigma)); | |
} | |
else if(y[n] == 13) | |
{ | |
target += log_diff_exp(normal_lcdf(75000 | mu, sigma), | |
normal_lcdf(60000 | mu, sigma)); | |
} | |
else if(y[n] == 14) | |
{ | |
target += log_diff_exp(normal_lcdf(100000 | mu, sigma), | |
normal_lcdf(75000 | mu, sigma)); | |
} | |
else if(y[n] == 15) | |
{ | |
target += normal_lccdf(100000 | mu, sigma); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment