Thanks Jsocolar
In this analysis I want to show the trend of global early childbirth above 100 countries.
before detailed analysis I want to check by one country. The dependent variable is early childbirth below 15 years (yes or no), The independent variable is the year (2000, 2005, 2011, 2016, and 2019) K=5 categories and the cluster id(v001) is higher level id the total number of cluster is J=650 and the sample size is N=16269.
based on this I organized each block on stan names of “test1.stan”.
Based on my data the dependent variable is binary outcome and the independent variable is multinomial. I want to show hierarchical logistic regression and the first year 2000 is the reference and the other compared based on it I creat my model on the new .stan file extentia by the name of test1.stan see below
data {
int<lower=0> N; // number of observations
int<lower=0> K; // number of catagories
int<lower=0, upper=1> Y[N]; // binary outcome
int<lower=0> X[N]; // predictor variable
int<lower=0> J; //number of groups
int<lower=1, upper=J> JJ[N]; //group indicators
}
parameters {
vector[K] beta; // predictor cofficient
vector[J] gamma; //group cofficient
}
model {
beta ~ normal(0, 10); // uninformative normal prior
gamma ~ normal(0,10); //uninformative normal prior
for (n in 1:N) {
Y[n] ~ bernoulli_logit(beta[X[n]] + gamma[JJ[n]]); //Binomial likelihood dependent on multinomial distribution
}
}
I run it
rstan:::rstudio_stanc(“Desktop/test/test1.stan”)
Desktop/test/test1.stan is syntactically correct.
I creat wd
setwd(“/Users/bayuhasmamaw/Desktop/test”)
after this, I go to in Rscript my R script file
creat the following command
Y<-select(dat, coh15)
X<-select(dat, year)
JJ<-select(dat, v001)
J=650
K=5
N=16269
data1=list(N=N, K=K, J=J, JJ=JJ$v001, Y=Y$coh15, X=X$year)
fit1<-stan('test1.stan', iter=200, chains=4, data=data1)
print(fit1, probs=c(0.25, 0.5, 0.75))
dat is the name of my data file
After run fit1 the response is
R Session Aborted
R encountered a fatal error
The session was terminated
When I run both fit1 and print I got the message
SAMPLING FOR MODEL ‘anon_model’ NOW (CHAIN 1).
in addition to above massage (R session Aborted_