Learn R Programming

neodistr (version 0.1.2)

stanf_fossep: Stan function of Fernandez-Osiewalski-Steel Skew Exponential Power Distribution

Description

Stan code of fossep distribution for custom distribution in stan

Usage

stanf_fossep(vectorize = TRUE)

Value

fossep_lpdf gives stan's code of the log of density, fossep_cdf gives stan's code of the distribution function, fossep_lcdf gives stan's code of the log of distribution function and fossep_lccdf

gives the stans's code of complement of log distribution function (1-fossep_lcdf)

Arguments

vectorize

logical; if TRUE, Vectorize Stan code of Fernandez-Osiewalski-Steel Skew Exponential Power distribution are given The default value of this parameter is TRUE

Author

Almira Utami and Achmad Syahrul Choir

Details

Fernandez-Osiewalski-Steel Skew Exponential Power Distribution has density: $$f(y |\mu,\sigma,\alpha,\beta) = \frac{c}{\sigma} \exp \left( - \frac{1}{2} \left| v z \right|^\beta \right) \quad \text{if } y < \mu$$ $$f(y |\mu,\sigma,\alpha,\beta) = \frac{c}{\sigma} \exp \left( - \frac{1}{2} \left| \frac{v}{z} \right|^\beta \right) \quad \text{if } y \ge \mu$$ $$ \text{where } -\infty < y < \infty, \ -\infty < \mu < \infty, \ \sigma > 0, \ \alpha > 0, \ \beta > 0$$ $$ z = \frac{y - \mu}{\sigma}$$ $$ c = v \beta \left[ (1 + v^2) 2^{\frac{1}{\beta}} \Gamma \left( \frac{1}{\beta} \right) \right]^{-1}$$

This function gives stan code of log density, cumulative distribution, log of cumulative distribution, log complementary cumulative distribution of Fernandez-Osiewalski-Steel Skew Exponential Power Distribution

References

Fernandez, C., Osiewalski, J., & Steel, M. F. (1995) Modeling and inference with v-spherical distributions. Journal of the American Statistical Association, 90(432), pp 1331-1340

Rigby, R.A. and Stasinopoulos, M.D. and Heller, G.Z. and De Bastiani, F. (2019) Distributions for Modeling Location, Scale, and Shape: Using GAMLSS in R.CRC Press

Examples

Run this code
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