Skip to content

Instantly share code, notes, and snippets.

View credpath's full-sized avatar

Connor Redpath credpath

View GitHub Profile
# linc_ig = alpha_g + beta_g * educ_i for individual i in cluster g
# want to estimate alpha_g and beta_g for each cluster
male_fit <- map2stan( # create output called male_fit
alist(
linc ~ dnorm( mu , sigma ), # likelihood: log(income) has normal distribution
mu <- alpha_attract[ornt] + # mean mu is linearly related to alpha_clusterName + beta_clusterName * education
beta_attract[ornt]*educ,
c(alpha_attract,beta_attract)[ornt] ~ dmvnorm2( c(alpha,beta) , sigma_attract , Rho ), # alpha_clusterName and beta_clusterName are jointly normaly distributed with means alpha and beta and standard deviations sigma_clusterName and correlation Rho
// 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
}
# 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);
# This is the stan code to implement the model
data
{
int<lower=1> N; // number of observations
int<lower=1> G; // number of clusters
vector[N] y; // the predicted variable (income)
vector[N] x; // the predictor variable (education)
}