if (FALSE) {
library (neodistr)
library (rstan)
# inputting data
set.seed(400)
dt <- neodistr::rfossep(100,mu=0, sigma=1, alpha = 2, beta = 2) # random generating fossep data
dataf <- list(
n = 100,
y = dt
)
#### Vector
## Calling the function of the neonormal distribution that is available in the package.
func_code_vector<-paste(c("functions{",neodistr::stanf_fossep(vectorize=TRUE),"}"),collapse="\n")
# Define Stan Model Code
model_vector <-"
data{
int n;
vector[n] y;
}
parameters{
real mu;
real sigma;
real alpha;
real beta;
}
model {
y ~ fossep(rep_vector(mu,n),sigma, alpha, beta);
mu ~ cauchy (0,1);
sigma ~ cauchy (0, 1);
alpha ~ lognormal(0,2.5);
beta ~ lognormal(0,2.5);
}
"
# Merge stan model code and selected neo-normal stan function
fit_code_vector <- paste (c(func_code_vector,model_vector,"\n"), collapse = "\n")
# Create the model using Stan Function
fit2 <- stan(
model_code = fit_code_vector, # Stan Program
data = dataf, # named list data
chains = 2, # number of markov chains
warmup = 5000, # total number of warmup iterarions per chain
iter = 10000, # total number of iterations iterarions per chain
cores = 2, # number of cores (could use one per chain)
control = list( # control sampel behavior
adapt_delta = 0.99
),
refresh = 1000 # progress has shown if refresh >=1, else no progress shown
)
# Showing the estimation result of the parameters that were executed using the Stan file
print(fit2, pars = c("mu", "sigma", "alpha", "beta", "lp__"), probs=c(.025,.5,.975))
}
Run the code above in your browser using DataLab