Title: | Estimates the Parameters of the Best-Fitting JohnsonSU Distribution for a Given Dataset |
---|---|
Description: | Uses least squares optimisation to estimate the parameters of the best-fitting JohnsonSU distribution for a given dataset, with the possibility of the distributions corresponding to the limiting cases of the JohnsonSU distribution. This package has been created as an extension of my Master's thesis. |
Authors: | C.J. Clarke [aut, cre], Andrew Smith [aut] |
Maintainer: | C.J. Clarke <[email protected]> |
License: | GPL (>=3) |
Version: | 1.0.0 |
Built: | 2024-11-01 11:29:25 UTC |
Source: | https://github.com/cjclarke98/jsuparameters |
This function finds the best-fitting JohnsonSU distribution for a given dataset through least squares optimisation.
JSUparameters(dat)
JSUparameters(dat)
dat |
The data you would like to fit a JohnsonSU distribution to. |
This function contains many sub-funtcions. 1. OptimiseGivenZeta(): This function will find the best-fitting JohnsonSU distribution for the given dataset, for a given value of zeta (typically found using a GSS). 2. golden(): Carries out a Golden Section Search (GSS) to find the minimum of a function within a given interval. 3. calculate_ssq(): Calculates the sum of squares (SSQ) for a given value of zeta. 4. Check4Cases(): This function will go through the 4 possible cases (JohnsonSU, shifted lognormal, shifted negative lognormal, constant) and find which is the best-fitting distribution to the given dataset, via least squares optimisation.
The following items will be returned no matter the optimal distribution:
CaseID |
The distribution case in which the given dataset falls; one of JSU, Lognormal, Negative Lognormal or Constant. |
SSQ |
The SSQ associated with the optimal distribution for the given dataset. |
flags |
The values of flag1 and flag2. If flag1 is raised during the algorithm, it signifies multiple local minima may be present within the GSS. If flag2 is raised during the algorithm, it signifies that the fitted distribution has zero density at some observation(s) in the given dataset. Whether these flags indicate problems or not is at the discretion of the user. |
If the optimal distribution is the JSU distribution, the shifted lognormal distribution or the shifted negative lognormal distribution, the following will be returned aswell as CaseID, SSQ and flags:
delta |
The value of delta associated with the optimal distribution. |
xi |
The value of xi associated with the optimal distribution. |
gamma |
The value of gamma associated with the optimal distribution. |
lambda |
The value of lambda associated with the optimal distribution. |
If the optimal distribution is the constant distribution, the following will be returned aswell as CaseID, SSQ and flags:
constant |
The value of constant associated with the optimal distribution. Note: this only occurs in the constant distribution. |
If the optimal distribution is the normal distribution, the following will be returned aswell as CaseID, SSQ and flags:
mean |
The mean of the normal distribution. |
std |
The standard deviation of the normal distribution. |
If the optimal distribution is the degenerate case, the following will be returned aswell as CaseID, SSQ and flags:
smallest |
The smallest observation in the given dataset. |
largest |
The largest observation in the given dataset. |
average |
The average of the interior observations in the given dataset, i.e. excluding the smallest and largest. |
Typically, users of this package need only use the JSUparameters() function directly and all other functions are used in the background.
CJ Clarke
E. Cai, Scripts and Functions: Using R to Implement the Golden Section Search Method for Numerical Optimization, The Chemical Statistician Blog, (2013), available at https://chemicalstatistician.wordpress.com/2013/04/22/using-r-to-implement-the-golden-bisection-method/
### simple example dat = rnorm(500) JSUparameters(dat) ### stock example (taken from my Master's thesis) ## Not run: # go to https://finance.yahoo.com/quote/ # download the csv file # load in the csv file (check your own file path) iseq = read.csv("Downloads/^ISEQ.csv") # only store the closing price (convert from characters) iseq = as.numeric(iseq$Close) # interpolate the missing observation which(is.na(iseq)) # 195 iseq[195] = (iseq[194] + iseq[196])/2 # calculate the log returns returns = log(iseq[2:1247] / iseq[1:1246]) # find the best-fitting JSU distribution to this data JSUparameters(returns) ## End(Not run) ### use your own stock returns data to find the best-fitting JSU distribution
### simple example dat = rnorm(500) JSUparameters(dat) ### stock example (taken from my Master's thesis) ## Not run: # go to https://finance.yahoo.com/quote/ # download the csv file # load in the csv file (check your own file path) iseq = read.csv("Downloads/^ISEQ.csv") # only store the closing price (convert from characters) iseq = as.numeric(iseq$Close) # interpolate the missing observation which(is.na(iseq)) # 195 iseq[195] = (iseq[194] + iseq[196])/2 # calculate the log returns returns = log(iseq[2:1247] / iseq[1:1246]) # find the best-fitting JSU distribution to this data JSUparameters(returns) ## End(Not run) ### use your own stock returns data to find the best-fitting JSU distribution