Last active
August 31, 2018 23:49
-
-
Save credpath/3e1a7125ce9a643a763a6f8a4aef758e 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 rounding thing | |
functions | |
{ | |
int income_rounding(real log_income) // function to transform latent log income into NSFG categories | |
{ | |
real inc; | |
inc = exp(log_income); | |
if (inc < 5000) | |
return 1; | |
else if (inc < 7500) | |
return 2; | |
else if (inc < 10000) | |
return 3; | |
else if (inc < 12500) | |
return 4; | |
else if (inc < 15000) | |
return 5; | |
else if (inc < 20000) | |
return 6; | |
else if (inc < 25000) | |
return 7; | |
else if (inc < 30000) | |
return 8; | |
else if (inc < 35000) | |
return 9; | |
else if (inc < 40000) | |
return 10; | |
else if (inc < 50000) | |
return 11; | |
else if (inc < 60000) | |
return 12; | |
else if (inc < 75000) | |
return 13; | |
else if (inc < 100000) | |
return 14; | |
else | |
return 15; | |
} | |
} | |
data | |
{ | |
int<lower=2> K; // there are K categories for data y | |
int<lower=0> N; // N obersevations | |
int<lower=1,upper=K> y[N]; // outcome variable | |
int x[N]; // predictor variable | |
//vector[K-1] c; // cutoff points for latent outcome variable | |
} | |
parameters | |
{ | |
// real mu; // mean of log of latent variable | |
real<lower=0> sigma_sq; // variance of log of latent variable | |
vector 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 | |
{ | |
latent_y ~ normal(alpha + beta*x, sigma); // income is log normal | |
// latent_y = alpha + beta*x; // linear model | |
y = income_rounding(latent_y) // relationship between latent log income and NSFG income categories | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment