Title: | Neo-Normal Distribution |
---|---|
Description: | Provides functions for calculating the density, cumulative distribution, quantile, and random number of neo-normal distribution. It also interfaces with the 'brms' package, allowing the use of the neo-normal distribution as a custom family. This integration enables the application of various 'brms' formulas for neo-normal regression. The package implements the following distributions: Modified to be Stable as Normal from Burr (MSNBurr), Modified to be Stable as Normal from Burr-IIa (MSNBurr-IIa), Generalized of MSNBurr (GMSNBurr), and Jones-Faddy Skew-t. References: Choir, A. S. (2020).Unpublished Dissertation. Iriawan, N. (2000).Unpublished Dissertation. Jones, M. C. and Faddy,M. J. (2003).<doi:10.1111/1467-9868.00378>. Rigby, R. A., Stasinopoulos, M. D., Heller, G. Z., & Bastiani, F. D. (2019) <doi:10.1201/9780429298547>. |
Authors: | Achmad Syahrul Choir [aut, cre] , Anisa' Faoziah [aut], Nur Iriawan [aut] |
Maintainer: | Achmad Syahrul Choir <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-22 04:53:59 UTC |
Source: | https://github.com/madsyair/neodistr |
Neo-normal model using brms
bnrm( formula, data, family = msnburr(), prior = NULL, data2 = NULL, sample_prior = "no", knots = NULL, drop_unused_levels = TRUE, stanvars = NULL, fit = NA, save_pars = getOption("brms.save_pars", NULL), init = NULL, chains = 4, iter = 2000, warmup = floor(iter/2), thin = 1, cores = getOption("mc.cores", 1), threads = getOption("brms.threads", NULL), opencl = getOption("brms.opencl", NULL), normalize = getOption("brms.normalize", TRUE), control = list(adapt_delta = 0.9), algorithm = getOption("brms.algorithm", "sampling"), backend = getOption("brms.backend", "rstan"), future = getOption("future", FALSE), silent = 1, seed = NA, save_model = NULL, stan_model_args = list(), file = NULL, file_compress = TRUE, file_refit = getOption("brms.file_refit", "never"), empty = FALSE, rename = TRUE, ... )
bnrm( formula, data, family = msnburr(), prior = NULL, data2 = NULL, sample_prior = "no", knots = NULL, drop_unused_levels = TRUE, stanvars = NULL, fit = NA, save_pars = getOption("brms.save_pars", NULL), init = NULL, chains = 4, iter = 2000, warmup = floor(iter/2), thin = 1, cores = getOption("mc.cores", 1), threads = getOption("brms.threads", NULL), opencl = getOption("brms.opencl", NULL), normalize = getOption("brms.normalize", TRUE), control = list(adapt_delta = 0.9), algorithm = getOption("brms.algorithm", "sampling"), backend = getOption("brms.backend", "rstan"), future = getOption("future", FALSE), silent = 1, seed = NA, save_model = NULL, stan_model_args = list(), file = NULL, file_compress = TRUE, file_refit = getOption("brms.file_refit", "never"), empty = FALSE, rename = TRUE, ... )
formula |
An object of class |
data |
An object of class |
family |
the neo-normal distribution as response in regression:msnburr(),msnburr2a(),gmsnburr(),jfst() default argument in family is vectorize=TRUE. if not vectorize, give argument vectorize=FALSE, example:msnburr(vectorize=FALSE) |
prior |
One or more |
data2 |
A named |
sample_prior |
Indicate if draws from priors should be drawn
additionally to the posterior draws. Options are |
knots |
Optional list containing user specified knot values to be used
for basis construction of smoothing terms. See
|
drop_unused_levels |
Should unused factors levels in the data be
dropped? Defaults to |
stanvars |
An optional |
fit |
An instance of S3 class |
save_pars |
An object generated by |
init |
Initial values for the sampler. If |
chains |
Number of Markov chains (defaults to 4). |
iter |
Number of total iterations per chain (including warmup; defaults to 2000). |
warmup |
A positive integer specifying number of warmup (aka burnin)
iterations. This also specifies the number of iterations used for stepsize
adaptation, so warmup draws should not be used for inference. The number
of warmup should not be larger than |
thin |
Thinning rate. Must be a positive integer. Set |
cores |
Number of cores to use when executing the chains in parallel,
which defaults to 1 but we recommend setting the |
threads |
Number of threads to use in within-chain parallelization. For
more control over the threading process, |
opencl |
The platform and device IDs of the OpenCL device to use for
fitting using GPU support. If you don't know the IDs of your OpenCL device,
|
normalize |
Logical. Indicates whether normalization constants should
be included in the Stan code (defaults to |
control |
A named |
algorithm |
Character string naming the estimation approach to use.
Options are |
backend |
Character string naming the package to use as the backend for
fitting the Stan model. Options are |
future |
Logical; If |
silent |
Verbosity level between |
seed |
The seed for random number generation to make results
reproducible. If |
save_model |
Either |
stan_model_args |
A |
file |
Either |
file_compress |
Logical or a character string, specifying one of the
compression algorithms supported by |
file_refit |
Modifies when the fit stored via the |
empty |
Logical. If |
rename |
For internal use only. |
... |
Further arguments passed to Stan.
For |
Fit a neo-normal model that using brm function in brms package.All arguments in this functions follow arguments of brm function, except family
An object of class brmsfit
, which contains the posterior
draws along with many other useful information about the model. Use
methods(class = "brmsfit")
for an overview on available methods.
Achmad Syahrul Choir
Buerkner,P-C (2017). brms: An R Package for Bayesian Multilevel
Models Using Stan. Journal of Statistical Software, 80(1), 1-28.
doi:10.18637/jss.v080.i01
Choir, A. S. (2020). The New Neo-Normal Distributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
Iriawan, N. (2000). Computationally Intensive Approaches to Inference in Neo-Normal Linear Models. Curtin University of Technology.
library(neodistr) x<-runif(100) e<-rmsnburr(100,0,1,0.8) y<-0.5+0.8*x+e data<-data.frame(y,x) fit <- bnrm( y ~ x, data = data, family = msnburr()) summary(fit) pp <- posterior_predict(fit) ppe <- posterior_epred(fit) loo(fit)
library(neodistr) x<-runif(100) e<-rmsnburr(100,0,1,0.8) y<-0.5+0.8*x+e data<-data.frame(y,x) fit <- bnrm( y ~ x, data = data, family = msnburr()) summary(fit) pp <- posterior_predict(fit) ppe <- posterior_epred(fit) loo(fit)
Neonormal as custom distribution family in brms
brms_custom_family(family = "msnburr", vectorize = TRUE)
brms_custom_family(family = "msnburr", vectorize = TRUE)
family |
distribution neo-normal option: "msnburr", "msnburr2a", "gmsnburr", and "jfst" |
vectorize |
logical; if TRUE, Stan code of family distribution is vectorize The default value of this parameter is TRUE |
custom_family is an object of class custom family of brms and stanvars_family is stanvars object (the Stan code of function of neo-normal distributions (lpdf,cdf,lcdf,lccdf,quantile and rng))
Achmad Syahrul Choir
library(brms) library(neodistr) x<-runif(100) e<-rmsnburr(100,0,1,0.8) y<-0.5+0.8*x+e data<-data.frame(y,x) msnburr<-brms_custom_family("msnburr") fit <- brm( y ~ x, data = data, family = msnburr$custom_family, stanvars = msnburr$stanvars_family, prior=c(set_prior("cauchy(0,5)",class="alpha"),set_prior("cauchy(0,1)",class="sigma")) ) summary(fit) pp <- posterior_predict(fit) ppe <- posterior_epred(fit) loo(fit)
library(brms) library(neodistr) x<-runif(100) e<-rmsnburr(100,0,1,0.8) y<-0.5+0.8*x+e data<-data.frame(y,x) msnburr<-brms_custom_family("msnburr") fit <- brm( y ~ x, data = data, family = msnburr$custom_family, stanvars = msnburr$stanvars_family, prior=c(set_prior("cauchy(0,5)",class="alpha"),set_prior("cauchy(0,1)",class="sigma")) ) summary(fit) pp <- posterior_predict(fit) ppe <- posterior_epred(fit) loo(fit)
To calculate density function, distribution funcion, quantile function, and build data from random generator function for the GMSNBurr Distribution.
dgmsnburr(x, mu = 0, sigma = 1, alpha = 1, beta = 1, log = FALSE) pgmsnburr( q, mu = 0, sigma = 1, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE ) qgmsnburr( p, mu = 0, sigma = 1, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE ) rgmsnburr(n, mu = 0, sigma = 1, alpha = 1, beta = 1)
dgmsnburr(x, mu = 0, sigma = 1, alpha = 1, beta = 1, log = FALSE) pgmsnburr( q, mu = 0, sigma = 1, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE ) qgmsnburr( p, mu = 0, sigma = 1, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE ) rgmsnburr(n, mu = 0, sigma = 1, alpha = 1, beta = 1)
x , q
|
vector of quantiles. |
mu |
a location parameter. |
sigma |
a scale parameter. |
alpha |
a shape parameter. |
beta |
a shape parameter. |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p) The default value of this parameter is FALSE. |
lower.tail |
logical;if TRUE (default), probabilities are
|
p |
vectors of probabilities. |
n |
number of observations. |
GMSNBurr Distribution
The GMSNBurr distribution with parameters ,
,
, and
has density:
where
and
dgmsnburr
gives the density , pgmasnburr
gives the distribution function,
qgmsnburr
gives quantiles function, rgmsnburr
generates random numbers.
Achmad Syahrul Choir
Choir, A. S. (2020). The New Neo-Normal Distributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
Iriawan, N. (2000). Computationally Intensive Approaches to Inference in Neo-Normal Linear Models. Curtin University of Technology.
library("neodistr") dgmsnburr(0, mu=0, sigma=1, alpha=1,beta=1) pgmsnburr(4, mu=0, sigma=1, alpha=1, beta=1) qgmsnburr(0.4, mu=0, sigma=1, alpha=1, beta=1) r=rgmsnburr(10000, mu=0, sigma=1, alpha=1, beta=1) head(r) hist(r, xlab = 'GMSNBurr random number', ylab = 'Frequency', main = 'Distribution of GMSNBurr Random Number ')
library("neodistr") dgmsnburr(0, mu=0, sigma=1, alpha=1,beta=1) pgmsnburr(4, mu=0, sigma=1, alpha=1, beta=1) qgmsnburr(0.4, mu=0, sigma=1, alpha=1, beta=1) r=rgmsnburr(10000, mu=0, sigma=1, alpha=1, beta=1) head(r) hist(r, xlab = 'GMSNBurr random number', ylab = 'Frequency', main = 'Distribution of GMSNBurr Random Number ')
To calculate density function, distribution funcion, quantile function, and build data from random generator function for the Jones-Faddy's Skew-t Distribution.
djfst(x, mu = 0, sigma = 1, alpha = 2, beta = 2, log = FALSE) pjfst( q, mu = 0, sigma = 1, alpha = 2, beta = 2, lower.tail = TRUE, log.p = FALSE ) qjfst( p, mu = 0, sigma = 1, alpha = 2, beta = 2, lower.tail = TRUE, log.p = FALSE ) rjfst(n, mu = 0, sigma = 1, alpha = 2, beta = 2)
djfst(x, mu = 0, sigma = 1, alpha = 2, beta = 2, log = FALSE) pjfst( q, mu = 0, sigma = 1, alpha = 2, beta = 2, lower.tail = TRUE, log.p = FALSE ) qjfst( p, mu = 0, sigma = 1, alpha = 2, beta = 2, lower.tail = TRUE, log.p = FALSE ) rjfst(n, mu = 0, sigma = 1, alpha = 2, beta = 2)
x , q
|
vector of quantiles. |
mu |
a location parameter. |
sigma |
a scale parameter. |
alpha |
a shape parameter (skewness). |
beta |
a shape parameter (kurtosis). |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p) The default value of this parameter is FALSE |
lower.tail |
logical;if TRUE (default), probabilities are
|
p |
vectors of probabilities. |
n |
number of observations. |
Jones-Faddy's Skew-t Distribution
The Jones-Faddy's Skew-t distribution with parameters ,
,
, and
has density:
where
,
,
djfst
gives the density , pjfst
gives the distribution function,
qjfst
gives quantiles function, rjfst
generates random numbers.
Anisa' Faoziah
Jones, M.C. and Faddy, M. J. (2003) A skew extension of the t distribution, with applications. Journal of the Royal Statistical Society, Series B, 65, pp 159-174
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
djfst(4, mu=0, sigma=1, alpha=2, beta=2) pjfst(4, mu=0, sigma=1, alpha=2, beta=2) qjfst(0.4, mu=0, sigma=1, alpha=2, beta=2) r=rjfst(10000, mu=0, sigma=1, alpha=2, beta=2) head(r) hist(r, xlab = 'jfst random number', ylab = 'Frequency', main = 'Distribution of jfst Random Number ')
djfst(4, mu=0, sigma=1, alpha=2, beta=2) pjfst(4, mu=0, sigma=1, alpha=2, beta=2) qjfst(0.4, mu=0, sigma=1, alpha=2, beta=2) r=rjfst(10000, mu=0, sigma=1, alpha=2, beta=2) head(r) hist(r, xlab = 'jfst random number', ylab = 'Frequency', main = 'Distribution of jfst Random Number ')
To calculate density function, distribution funcion, quantile function, and build data from random generator function for the MSNBurr Distribution.
dmsnburr(x, mu = 0, sigma = 1, alpha = 1, log = FALSE) pmsnburr(q, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) qmsnburr(p, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) rmsnburr(n, mu = 0, sigma = 1, alpha = 1)
dmsnburr(x, mu = 0, sigma = 1, alpha = 1, log = FALSE) pmsnburr(q, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) qmsnburr(p, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) rmsnburr(n, mu = 0, sigma = 1, alpha = 1)
x , q
|
vector of quantiles. |
mu |
a location parameter. |
sigma |
a scale parameter. |
alpha |
a shape parameter. |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p) The default value of this parameter is FALSE. |
lower.tail |
logical;if TRUE (default), probabilities are
|
p |
vectors of probabilities. |
n |
number of observations. |
MSNBurr Distribution
The MSNBurr distribution with parameters ,
,and
has density:
where
dmsnburr
gives the density , pmsnburr
gives the distribution function,
qmsnburr
gives quantiles function, rmsnburr
generates random numbers.
Achmad Syahrul Choir and Nur Iriawan
Iriawan, N. (2000). Computationally Intensive Approaches to Inference in Neo-Normal Linear Models. Curtin University of Technology.
Choir, A. S. (2020). The New Neo-Normal Distributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
library("neodistr") dmsnburr(0, mu=0, sigma=1, alpha=0.1) plot(function(x) dmsnburr(x, alpha=0.1), -20, 3, main = "Left Skew MSNBurr Density ",ylab="density") pmsnburr(7, mu=0, sigma=1, alpha=1) qmsnburr(0.6, mu=0, sigma=1, alpha=1) r<- rmsnburr(10000, mu=0, sigma=1, alpha=1) head(r) hist(r, xlab = 'MSNBurr random number', ylab = 'Frequency', main = 'Distribution of MSNBurr Random Number ')
library("neodistr") dmsnburr(0, mu=0, sigma=1, alpha=0.1) plot(function(x) dmsnburr(x, alpha=0.1), -20, 3, main = "Left Skew MSNBurr Density ",ylab="density") pmsnburr(7, mu=0, sigma=1, alpha=1) qmsnburr(0.6, mu=0, sigma=1, alpha=1) r<- rmsnburr(10000, mu=0, sigma=1, alpha=1) head(r) hist(r, xlab = 'MSNBurr random number', ylab = 'Frequency', main = 'Distribution of MSNBurr Random Number ')
To calculate density function, distribution funcion, quantile function, and build data from random generator function for the MSNBurr distribution.
dmsnburr2a(x, mu = 0, sigma = 1, alpha = 1, log = FALSE) pmsnburr2a(q, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) qmsnburr2a(p, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) rmsnburr2a(n, mu = 0, sigma = 1, alpha = 1)
dmsnburr2a(x, mu = 0, sigma = 1, alpha = 1, log = FALSE) pmsnburr2a(q, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) qmsnburr2a(p, mu = 0, sigma = 1, alpha = 1, lower.tail = TRUE, log.p = FALSE) rmsnburr2a(n, mu = 0, sigma = 1, alpha = 1)
x , q
|
vector of quantiles. |
mu |
a location parameter. |
sigma |
a scale parameter. |
alpha |
a shape parameter |
log , log.p
|
logical; if TRUE, probabilities p are given as log(p), The default value of this parameter is FALSE. |
lower.tail |
logical;if TRUE (default), probabilities are
|
p |
vectors of probabilities. |
n |
number of observations. |
MSNBurr-IIa Distribution
The MSNBurr-IIa distribution with parameters ,
, and
has density:
where
dmsnburr2a
gives the density, pmsnburr2a
gives the distribution
function, qmsnburr2a
gives the quantile function and rmsnburr2a
generates
random numbers.
Achmad Syahrul Choir and Nur Iriawan
Choir, A. S. (2020). The New Neo-Normal DDistributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
library("neodistr") dmsnburr2a(7, mu=0, sigma=1, alpha=0.1) plot(function(x) dmsnburr2a(x, alpha=0.1), -3, 20, main = "Right Skew MSNBurr-IIa Density ",ylab="density") p=pmsnburr2a(4, mu=0, sigma=1, alpha=1) p q=qmsnburr2a(p, mu=0, sigma=1, alpha=1) q qmsnburr2a(0.5, mu=0, sigma=1, alpha=1) r=rmsnburr2a(10000, mu=0, sigma=1, alpha=0.1) head(r) hist(r, xlab = 'MSNBurr random number', ylab = 'Frequency', main = 'Distribution of MSNBurr-IIa Random Number ')
library("neodistr") dmsnburr2a(7, mu=0, sigma=1, alpha=0.1) plot(function(x) dmsnburr2a(x, alpha=0.1), -3, 20, main = "Right Skew MSNBurr-IIa Density ",ylab="density") p=pmsnburr2a(4, mu=0, sigma=1, alpha=1) p q=qmsnburr2a(p, mu=0, sigma=1, alpha=1) q qmsnburr2a(0.5, mu=0, sigma=1, alpha=1) r=rmsnburr2a(10000, mu=0, sigma=1, alpha=0.1) head(r) hist(r, xlab = 'MSNBurr random number', ylab = 'Frequency', main = 'Distribution of MSNBurr-IIa Random Number ')
Starts shiny application for the neodistr package
neoshiny()
neoshiny()
Starts shiny application for the neodistr package.
Anisa' Faoziah and Achmad Syahrul Choir
if (interactive()) { suppressMessages(library(neodistr)) neoshiny() }
if (interactive()) { suppressMessages(library(neodistr)) neoshiny() }
Stan code of GMSNBurr distribution for custom distribution in stan
stanf_gmsnburr(vectorize = TRUE, rng = TRUE)
stanf_gmsnburr(vectorize = TRUE, rng = TRUE)
vectorize |
logical; if TRUE, Vectorize Stan code of GMSNBurr distribution are given The default value of this parameter is TRUE |
rng |
logical; if TRUE, Stan code of quantile and random number generation of GMSNBurr distribution are given The default value of this parameter is TRUE |
GMSNBurr Distribution has density:
where
and
This function gives stan code of log density, cumulative distribution, log of cumulatif distribution, log complementary cumulative distribution, quantile, random number of GMSNBurr distribution
msnburr_lpdf
gives the stans's code of log of density, msnburr_cdf
gives the stans's code of distribution
function, gmsnburr_lcdf
gives the stans's code of log of distribution function, gmsnburr_lccdf
gives the stans's code of complement of log ditribution function (1-gmsnburr_lcdf),
and gmsnburr_rng
the stans's code of generates random numbers.
Achmad Syahrul Choir
Choir, A. S. (2020). The New Neo-Normal DDistributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
library(neodistr) library(rstan) #inputting data set.seed(136) dt <- rgmsnburr(100,0,1,0.5,0.5) # random generating MSNBurr-IIA data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_gmsnburr(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { for(i in 1:n){ y[i]~gmsnburr(mu,sigma,alpha,beta); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); beta~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2, # number of cores (could use one per chain) control = list( #control samplers behavior adapt_delta=0.9 ) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "beta","lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_gmsnburr(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { y~gmsnburr(rep_vector(mu,n),sigma,alpha,beta); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); beta~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2, # number of cores (could use one per chain) control = list( #control samplers behavior adapt_delta=0.9 ) ) # Showing the estimation results of the parameters print(fit2, pars=c("mu", "sigma", "alpha","beta", "lp__"), probs=c(.025,.5,.975))
library(neodistr) library(rstan) #inputting data set.seed(136) dt <- rgmsnburr(100,0,1,0.5,0.5) # random generating MSNBurr-IIA data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_gmsnburr(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { for(i in 1:n){ y[i]~gmsnburr(mu,sigma,alpha,beta); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); beta~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2, # number of cores (could use one per chain) control = list( #control samplers behavior adapt_delta=0.9 ) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "beta","lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_gmsnburr(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { y~gmsnburr(rep_vector(mu,n),sigma,alpha,beta); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); beta~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2, # number of cores (could use one per chain) control = list( #control samplers behavior adapt_delta=0.9 ) ) # Showing the estimation results of the parameters print(fit2, pars=c("mu", "sigma", "alpha","beta", "lp__"), probs=c(.025,.5,.975))
Stan code of JFST distribution for custom distribution in stan
stanf_jfst(vectorize = TRUE, rng = TRUE)
stanf_jfst(vectorize = TRUE, rng = TRUE)
vectorize |
logical; if TRUE, Vectorize Stan code of Jones and faddy distribution are given The default value of this parameter is TRUE |
rng |
logical; if TRUE, Stan code of quantile and random number generation of Jones and faddy distribution are given The default value of this parameter is TRUE |
Jones-Faddy’s Skew-t distribution has density:
where
,
,
This function gives stan code of log density, cumulative distribution, log of cumulatif distribution, log complementary cumulative distribution, quantile, random number of Jones-Faddy's Skew-t distribution
jfst_lpdf
gives stan's code of the log of density, jfst_cdf
gives stan's code of the distribution
function, jfst_lcdf
gives stan's code of the log of distribution function and jfst_rng
gives stan's code of generates
random numbers.
Anisa' Faoziah and Achmad Syahrul Choir
Jones, M.C. and Faddy, M. J. (2003) A skew extension of the t distribution, with applications. Journal of the Royal Statistical Society, Series B, 65, pp 159-174
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
library (neodistr) library (rstan) # inputting data set.seed(400) dt <- neodistr::rjfst(100,mu=0, sigma=1, alpha = 2, beta = 2) # random generating JFST data dataf <- list( n = 100, y = dt ) #### not vector ## Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_jfst(vectorize=FALSE),"}"),collapse="\n") # Define Stan Model Code model <-" data{ int<lower=1> n; vector[n] y; } parameters{ real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { for(i in 1 : n){ y[i] ~ jfst(mu,sigma, alpha, beta); } mu ~ cauchy(0,1); sigma ~ cauchy(0, 2.5); alpha ~ lognormal(0,5); beta ~ lognormal(0,5); } " # Merge stan model code and selected neo-normal stan function fit_code <- paste (c(func_code,model,"\n"), collapse = "\n") # Create the model using Stan Function fit1 <- stan( model_code = fit_code, # 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(fit1, pars = c("mu", "sigma", "alpha", "beta", "lp__"), probs=c(.025,.5,.975)) #### Vector ## Calling the function of the neonormal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_jfst(vectorize=TRUE),"}"),collapse="\n") # Define Stan Model Code model_vector <-" data{ int<lower=1> n; vector[n] y; } parameters{ real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0>beta; } model { y ~ jfst(rep_vector(mu,n),sigma, alpha, beta); mu ~ cauchy (0,1); sigma ~ cauchy (0, 2.5); alpha ~ lognormal(0,5); beta ~ lognormal(0,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))
library (neodistr) library (rstan) # inputting data set.seed(400) dt <- neodistr::rjfst(100,mu=0, sigma=1, alpha = 2, beta = 2) # random generating JFST data dataf <- list( n = 100, y = dt ) #### not vector ## Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_jfst(vectorize=FALSE),"}"),collapse="\n") # Define Stan Model Code model <-" data{ int<lower=1> n; vector[n] y; } parameters{ real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0> beta; } model { for(i in 1 : n){ y[i] ~ jfst(mu,sigma, alpha, beta); } mu ~ cauchy(0,1); sigma ~ cauchy(0, 2.5); alpha ~ lognormal(0,5); beta ~ lognormal(0,5); } " # Merge stan model code and selected neo-normal stan function fit_code <- paste (c(func_code,model,"\n"), collapse = "\n") # Create the model using Stan Function fit1 <- stan( model_code = fit_code, # 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(fit1, pars = c("mu", "sigma", "alpha", "beta", "lp__"), probs=c(.025,.5,.975)) #### Vector ## Calling the function of the neonormal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_jfst(vectorize=TRUE),"}"),collapse="\n") # Define Stan Model Code model_vector <-" data{ int<lower=1> n; vector[n] y; } parameters{ real mu; real <lower=0> sigma; real <lower=0> alpha; real <lower=0>beta; } model { y ~ jfst(rep_vector(mu,n),sigma, alpha, beta); mu ~ cauchy (0,1); sigma ~ cauchy (0, 2.5); alpha ~ lognormal(0,5); beta ~ lognormal(0,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))
Stan code of MSNBurr distribution for custom distribution in stan
stanf_msnburr(vectorize = TRUE, rng = TRUE)
stanf_msnburr(vectorize = TRUE, rng = TRUE)
vectorize |
logical; if TRUE, Vectorize Stan code of MSNBurr distribution are given The default value of this parameter is TRUE |
rng |
logical; if TRUE, Stan code of quantile and random number generation of MSNBurr distribution are given The default value of this parameter is TRUE |
MSNBurr Distribution has density:
where
This function gives stan code of log density, cumulative distribution, log of cumulatif distribution, log complementary cumulative distribution, quantile, random number of MSNBurr distribution
msnburr_lpdf
gives the log of density, msnburr_cdf
gives the distribution
function, msnburr_lcdf
gives the log of distribution function, msnburr_lccdf
gives the complement of log ditribution function (1-msnburr_lcdf),
and msnburr_rng
generates
random deviates.
Achmad Syahrul Choir and Nur Iriawan
Iriawan, N. (2000). Computationally Intensive Approaches to Inference in Neo-Normal Linear Models. Curtin University of Technology. Choir, A. S. (2020). The New Neo-Normal DDistributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
library (neodistr) library(rstan) #inputting data set.seed(136) dt <- neodistr::rmsnburr(100,0,1,0.5) # random generating MSNBurr data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_msnburr(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { for(i in 1:n){ y[i]~msnburr(mu,sigma,alpha); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_msnburr(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { y~msnburr(rep_vector(mu,n),sigma,alpha); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit2, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975))
library (neodistr) library(rstan) #inputting data set.seed(136) dt <- neodistr::rmsnburr(100,0,1,0.5) # random generating MSNBurr data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_msnburr(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { for(i in 1:n){ y[i]~msnburr(mu,sigma,alpha); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_msnburr(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { y~msnburr(rep_vector(mu,n),sigma,alpha); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit2, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975))
Stan code of MSNBurr-IIa distribution for custom distribution in stan
stanf_msnburr2a(vectorize = TRUE, rng = TRUE)
stanf_msnburr2a(vectorize = TRUE, rng = TRUE)
vectorize |
logical; if TRUE, Vectorize Stan code of MSNBurr-IIa distribution are given The default value of this parameter is TRUE |
rng |
logical; if TRUE, Stan code of quantile and random number generation of MSNBurr-IIa distribution are given The default value of this parameter is TRUE |
MSNBurr-IIa Distribution has density function:
where
This function gives stan code of log density, cumulative distribution, log of cumulatif distribution, log complementary cumulative distribution, quantile, random number of MSNBurr-IIa distribution
msnburr_lpdf
gives the log of density, msnburr_cdf
gives the distribution
function, msnburr_lcdf
gives the log of distribution function, msnburr_lccdf
gives the complement of log ditribution function (1-msnburr_lcdf),
and msnburr_rng
generates
random deviates.
Achmad Syahrul Choir and Nur Iriawan
Choir, A. S. (2020). The New Neo-Normal DDistributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember.
library (neodistr) library(rstan) #inputting data set.seed(136) dt <- neodistr::rmsnburr2a(100,0,1,0.5) # random generating MSNBurr-IIA data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_msnburr2a(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { for(i in 1:n){ y[i]~msnburr2a(mu,sigma,alpha); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_msnburr2a(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real alpha; } model { y~msnburr2a(rep_vector(mu,n),sigma,alpha); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit2, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975))
library (neodistr) library(rstan) #inputting data set.seed(136) dt <- neodistr::rmsnburr2a(100,0,1,0.5) # random generating MSNBurr-IIA data dataf <- list( n = 100, y = dt ) #### not vector ##Calling the function of the neo-normal distribution that is available in the package. func_code<-paste(c("functions{",neodistr::stanf_msnburr2a(vectorize=FALSE),"}"),collapse="\n") #define stan model code model<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real <lower=0> alpha; } model { for(i in 1:n){ y[i]~msnburr2a(mu,sigma,alpha); } mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #merge stan model code and selected neo-normal stan function fit_code<-paste(c(func_code,model,"\n"),collapse="\n") # Create the model using stan function fit1 <- stan( model_code = fit_code, # Stan program data = dataf, # named list of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit1, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975)) # Vector ##Calling the function of the neo-normal distribution that is available in the package. func_code_vector<-paste(c("functions{",neodistr::stanf_msnburr2a(vectorize=TRUE),"}"),collapse="\n") # define stan model as vector model_vector<-" data { int<lower=1> n; vector[n] y; } parameters { real mu; real <lower=0> sigma; real alpha; } model { y~msnburr2a(rep_vector(mu,n),sigma,alpha); mu~cauchy(0,1); sigma~cauchy(0,2.5); alpha~cauchy(0,1); } " #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 of data chains = 2, # number of Markov chains #warmup = 5000, # number of warmup iterations per chain iter = 10000, # total number of iterations per chain cores = 2 # number of cores (could use one per chain) ) # Showing the estimation results of the parameters that were executed using the Stan file print(fit2, pars=c("mu", "sigma", "alpha", "lp__"), probs=c(.025,.5,.975))
To display a summary of calculations for a specific neo-normal distribution, including the mean,median, mode, variance, skewness, and excess.kurtosis.
summary_dist(family = "msnburr", par = c(mu = 0, sigma = 1, alpha = 1))
summary_dist(family = "msnburr", par = c(mu = 0, sigma = 1, alpha = 1))
family |
identify the type of Neo-normal distribution to be used. There are four categories of neo-normal distributions, which encompass "msnburr" for MSNBurr , "msnburr2a" for MSNBurr-IIa, "gmsnburr" for GMSNBurr, and "jfst" for Jones-Faddy's Skew-t Distribution. The default value of this parameter is "msnburr" |
par |
list values of each parameter, based on the chosen distribution. The default value is "par=c(alpha=1,mu=0,sigma=1)" for MSNBurr parameter parameter of MSNBurr and MSNBurr-IIa are mu, sigma, alpha parameter of GMSNBurr and JFST are mu, sigma, alpha, beta |
media, mean, mode, variance, skewness, and excess kurtosis of neo-normal distributions
Achmad Syahrul Choir
Choir, A. S. (2020). The New Neo-Normal Distributions and their Properties. Disertation. Institut Teknologi Sepuluh Nopember. Jones, M.C. and Faddy, M. J. (2003) A skew extension of the t distribution, with applications. Journal of the Royal Statistical Society, Series B, 65, pp 159-174 Rigby, R.A. and Stasinopoulos, M.D. and Heller, G.Z. and De Bastiani, F. (2020) Distributions for Modeling Location, Scale, and Shape: Using GAMLSS in R.CRC Press
summary_dist (family="msnburr2a", par=c(mu=0,sigma=1,alpha=4))
summary_dist (family="msnburr2a", par=c(mu=0,sigma=1,alpha=4))