stable/0000755000176200001440000000000014207537472011537 5ustar liggesusersstable/NAMESPACE0000755000176200001440000000113114207447606012754 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(disp_g) export(disp_h) export(dstable) export(hstable) export(loc_g) export(loc_h) export(pm0_to_pm1) export(pm1_to_pm0) export(pstable) export(qstable) export(rstable) export(s2sd) export(sd2s) export(skew_g) export(skew_h) export(stable.mode) export(stablereg) export(tail_g) export(tail_h) import(rmutil) importFrom(stats,dcauchy) importFrom(stats,dnorm) importFrom(stats,nlm) importFrom(stats,pcauchy) importFrom(stats,pnorm) importFrom(stats,qcauchy) importFrom(stats,qnorm) importFrom(stats,runif) importFrom(stats,uniroot) useDynLib(stable) stable/README.md0000644000176200001440000002717514207450174013023 0ustar liggesusers [![Travis-CI Build Status](https://travis-ci.org/swihart/stable.svg?branch=master)](https://travis-ci.org/swihart/stable) [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/stable)](https://cran.r-project.org/package=stable) ![downloads](https://cranlogs.r-pkg.org/badges/grand-total/stable) `stable` R package ================== This package is intended to be the developmental version to the CRAN version of [Jim Lindsey's stable](https://www.commanster.eu/rcode.html). The .zip files listed on his homepage have been listed as version 1.0 since 2005. For the subsequent maintenance on this github and CRAN, we will start at 1.1. To compare this version with the static v1.0 files on [Jim Lindsey's Homepage](https://www.commanster.eu/rcode.html), it may be useful to use [the compare page for this repo's two branches](https://github.com/swihart/stable/compare/jim-lindsey-homepage-version-1.0...master?diff=split&name=master). comparisons with `stabledist` R package ======================================= In brief, the parameters have different names and are transformations for each other. First, the names: | stabledist | stable | |------------|--------| | alpha | tail | | beta | skew | | gamma | disp | | delta | loc | If you read the Lambert and Lindsey (1999 JRSS-C) PDF in this repo, be aware that location is given the greek letter gamma and scale is given the greek letter delta. The Nolan PDF does the opposite and is used for `stabledist`. [Swihart 2022 update, see references in `?dstable`:] In this README we detail how to make equivalent calls to those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization as detailed in Nolan (2020)). See github for Lambert and Lindsey 1999 JRSS-C journal article, which details the parameterization of the Buck (1995) stable distribution which allowed a Fourier inversion to arrive at a form similar to but not exactly the $g_d$ function as detailed in Nolan (2020), Abdul-Hamid and Nolan (1998) and Nolan (1997). The Nolan (2020) reference is a textbook that provides an accessible and comprehensive summary of stable distributions in the 25 years or so since the core of this R package was made and put on CRAN. The Buck (1995) parameterization most closely resembles the Zolotarev B parameterization outlined in Definition 3.6 on page 93 of Nolan (2020) -- except that Buck (1995) did not allow the scale parameter to multiply with the location parameter. This explains why the `Zolotarev B` entry in Table 3.1 on page 97 of Nolan (2020) has the location parameter being multiplied by the scale parameter whereas in converting the Lindsey and Lambert (1999) to Nolan 1-parameterization the location parameter stays the same. To be clear, \code{stable::dstable} and \code{stable::pstable} are evaluated by numerically integrating the inverse Fourier transform. The code works reasonably for small and moderate values of x, but will have numerical issues in some cases large x(such as values from \code{stable::pstable} being greater than 1 or or not being monotonic). The arguments \code{npt}, \code{up}, \code{integration}, and \code{eps} can be adjusted to improve accuracy at the cost of speed, but will still have limitations. Functions that avoid these problems are available in other packages (such as \code{stabledist} and \code{stable}) that use an alternative method (as detailed in Nolan 1997) distinct from directly numerically integrating the Fourier inverse transform. See last example in this README. For some values for some distributions things match up nicely, as we see with Normal and Cauchy: normal distribution ------------------- ``` r q <- 3 stable::pstable(q, tail =2, skew=0, disp =1, loc =0) #> [1] 0.9830526 stabledist::pstable(q, alpha=2, beta=0, gamma=1, delta=0) #> [1] 0.9830526 ``` cauchy distribution ------------------- ``` r q <- 3 stable::pstable(q, tail =1, skew=0, disp =1, loc =0) #> [1] 0.8975836 stabledist::pstable(q, alpha=1, beta=0, gamma=1, delta=0) #> [1] 0.8975836 ``` However, to make `stable` equivalent to `stabledist` in general, some transformations are needed. Please see the following examples. Between `stabledist` and `stable`, the `alpha` is equivalent to `tail` and the `delta` is equivalent to `loc` with no transformation. For the `beta` (`skew`) and `gamma` (`disp`) parameters, a transformation is needed to get equivalent calls. Note differences still may exist to numerical accuracy. levy cdf -------- ``` r q <- 0.9 # nolan pm=1 parameters: a <- 0.5 b <- 1 c <- .25 d <- 0.8 # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- 2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) stable::pstable(q, tail =a, skew=b3, disp =c3, loc =d) #> [1] 0.1154242 stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> [1] 0.1138462 rmutil::plevy(q, m=d, s=c) #> [1] 0.1138463 # more accuracy!!!!?! stable::pstable(q, tail =a, skew=b3, disp =c3, loc =d, eps = 0.13*1e-7) #> [1] 0.1138786 ``` levy pdf -------- ``` r q <- 0.9 # nolan pm=1 parameters: a <- 0.5 b <- 1 c <- .25 d <- 0.8 # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- 2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) stable::dstable(q, tail =a, skew=b3, disp =c3, loc =d) #> [1] 1.806389 stabledist::dstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> Warning in uniroot(function(th) log(g(th)), lower = l.th, upper = u.th, : - #> Inf replaced by maximally negative value #> Warning in uniroot(function(th) log(g(th)), lower = l.th, upper = u.th, : - #> Inf replaced by maximally negative value #> Warning in .integrate2(g1, lower = a, upper = b, subdivisions = #> subdivisions, : roundoff error is detected in the extrapolation table #> [1] 1.807224 rmutil::dlevy(q, m=d, s=c) #> [1] 1.807224 ``` levy quantile ------------- ``` r p <- .3 # nolan pm=1 parameters: a <- 0.5 b <- 1 c <- .25 d <- 0.8 # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- 2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) stable::qstable(p, tail =a, skew=b3, disp =c3, loc =d) #> [1] 1.031301 stabledist::qstable(p, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> [1] 1.032735 rmutil::qlevy(p, m=d, s=c) #> [1] 1.032733 ``` play with alpha not 2 and not 1 ------------------------------- ``` r q <- -1.97 # nolan pm=1 parameters: a <- 0.8 b <- 0 c <- 1 d <- 0 # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- 2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) stable::pstable(q, tail =a, skew=b3, disp =c3, loc =d) #> [1] 0.1722953 stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d) #> [1] 0.1722945 ``` play with skew -------------- ``` r q <- -1 # nolan pm=1 parameters: a <- 1.3 b <- 0.4 c <- 2 d <- 0.75 # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- -sign(b)*2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) stable::pstable(q, tail =a, skew=b3, disp =c3, loc =d) #> [1] 0.4349168 stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> [1] 0.4348957 stable::dstable(q, tail =a, skew=b3, disp =c3, loc =d) #> [1] 0.1454112 stabledist::dstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> [1] 0.1454111 ``` The example above, but using `sd2s` and `s2sd` ---------------------------------------------- ``` r q <- -1 # nolan pm=1 parameters: a <- 1.3 b <- -0.4 c <- 2 d <- 0.75 # sd2s takes nolan (stabledist) parameters and returns lindsey (stable) s <- stable::sd2s(alpha=a, beta=b, gamma=c, delta=d) stable::pstable(q, tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) #> [1] 0.196531 stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #> [1] 0.1965513 # s2sd takes lindsey (stable) parameters and returns nolan (stabledist) sd <- stable::s2sd(tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) stabledist::pstable(q, alpha=sd$alpha, beta=sd$beta , gamma=sd$gamma , delta=sd$delta, pm=1) #> [1] 0.1965513 ``` pm1\_to\_pm0 ------------ ``` r q <- -1 # nolan pm=1 parameters: a1 <- 1.3 b1 <- -0.4 c1 <- 2 d1 <- 0.75 # for a1 != 1 d0 <- d1 + b1*c1*tan(pi*a1/2) # Calculate d0 by hand or use pm1_to_pm0(): # Convert to nolan pm=0 parameters: pm0 <- stable::pm1_to_pm0(a1,b1,c1,d1) a0 <- pm0$a0 b0 <- pm0$b0 c0 <- pm0$c0 d0 <- pm0$d0 # check: stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #> [1] 0.1965513 # only change delta=d0 for pm=0 stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) #> [1] 0.1965513 stabledist::pstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #> [1] 0.1965513 stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #> [1] 0.0572133 # only change delta=d0 for pm=0 stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) #> [1] 0.0572133 stabledist::dstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #> [1] 0.0572133 ``` mode of a stable distribution ----------------------------- ``` r q <- -1 # nolan pm=1 parameters: # a1 <- 1.3 # b1 <- 0.4 # c1 <- 2 # d1 <- 0.75 a1 <- 1.3 b1 <- .5 c1 <- 1 d1 <- 0 # for a1 != 1 d0 <- d1 + b1*c1*tan(pi*a1/2) s <- stable::sd2s(alpha=a1, beta=b1, gamma=c1, delta=d1) stable::stable.mode(tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc)$ytilde #> [1] -1.13224 c1*stabledist::stableMode(alpha=a1, beta=b1)+d0 #> [1] -1.133257 xran <- seq(-2.5,2.6,0.001) ysd <- stabledist::dstable(xran, alpha=a1, beta=b1, gamma=c1, delta=d1, pm=1) #plot(xran, ysd) xran[ysd == max(ysd)] #> [1] -1.133 ys <- stable::dstable(xran, tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) #points(xran, ys, col="blue") xran[ys == max(ys)] #> [1] -1.133 ``` possible numerical issues for large x ----------------------------- ``` r param_conv <- stable::s2sd(1.5, 0.5, 1/sqrt(2), 0) param_conv head(stable::dstable(q, tail =1.5, skew=0.5, disp =1/sqrt(2), loc = 0)) head(stabledist::dstable(q, alpha=param_conv$alpha, beta=param_conv$beta , gamma=param_conv$gamma , delta=param_conv$delta, pm=1)) plot(q,stable::dstable(q, tail =1.5, skew=0.5, disp =1/sqrt(2), loc = 0), type="s") plot(q,stabledist::dstable(q, alpha=param_conv$alpha, beta=param_conv$beta , gamma=param_conv$gamma , delta=param_conv$delta, pm=1), type="s") param_conv <- stable::s2sd(1.5, 0.5, 1/sqrt(2), 0) param_conv plot(q,stable::pstable(q, tail =1.5, skew=0.5, disp =1/sqrt(2), loc = 0), type="s") plot(q,stabledist::pstable(q, alpha=param_conv$alpha, beta=param_conv$beta , gamma=param_conv$gamma , delta=param_conv$delta, pm=1), type="s") ```stable/man/0000755000176200001440000000000014207465774012317 5ustar liggesusersstable/man/stablereg.Rd0000644000176200001440000002404414203205677014550 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/stable.r \name{stablereg} \alias{stablereg} \alias{fitted.stable} \alias{df.residual.stable} \alias{deviance.stable} \alias{aic.stable} \title{Stable Generalized Regression Models} \usage{ stablereg( y = NULL, loc = 0, disp = 1, skew = 0, tail = 1.5, oloc = TRUE, odisp = TRUE, oskew = TRUE, otail = TRUE, noopt = FALSE, iloc = NULL, idisp = NULL, iskew = NULL, itail = NULL, loc_h = NULL, disp_h = NULL, skew_h = NULL, tail_h = NULL, weights = 1, exact = FALSE, delta = 1, envir = parent.frame(), integration = "Romberg", eps = 1e-06, up = 10, npoint = 501, hessian = TRUE, llik.output = FALSE, print.level = 0, ndigit = 10, steptol = 1e-05, gradtol = 1e-05, fscale = 1, typsize = abs(p0), stepmax = sqrt(p0 \%*\% p0), iterlim = 100 ) } \arguments{ \item{y}{The response vector or a \code{repeated} data object. If the \code{repeated} data object contains more than one response variable, give that object in \code{envir} and give the name of the response variable to be used here. For censored data, two columns with the second being the censoring indicator (1: uncensored, 0: right censored, -1: left censored.)} \item{loc, loc_h, oloc, iloc}{Describe the regression model fitted for the location parameter of the stable distribution, perhaps after transformation by the link function \code{loc_g} (set to the identity by default. The inverse link function is denoted by \code{loc_h}. Note that these functions cannot contain unknown parameters). Two specifications are possible: (1) \code{loc} is a linear or nonlinear language expression beginning with ~ or an R function, describing the regression function for the location parameter (after transformation by \code{loc_g}, the link function). \code{iloc} is a vector of initial conditions for the parameters in the regression for this parameter. \code{oloc} is a boolean indicating if an optimization of the likelihood has to be carried out on these parameters. If \code{oloc} is set to TRUE, a default zero value is considered for the starting values \code{iloc}. But if no optimization is desired on the location parameters, i.e. when the likelihood has to be evaluated or optimized at a fixed location, then \code{iloc} has to be explicitely specified. (2) \code{loc} is a numeric expression (i.e. a scalar or a vector of the same size as the data vector \code{y}, or \code{y[,1]} when censoring is considered). If \code{oloc} is set to TRUE, i.e. when an optimization of the likelihood has to be carried out on the location parameter, then the location parameter (after transformation by the link function loc_g) is set to an unknown parameter with initial value equal to \code{iloc[1]} or \code{loc[1]} when \code{iloc} is not specified. But when \code{oloc} is set to FALSE, i.e. when the likelihood has to be evaluated or optimized at a fixed location, then the transformed location is assumed to be equal to \code{loc} when it is of the same length as the data vector \code{y} (or \code{y[,1]} when censoring is considered), and to \code{loc[1]} otherwise. Specification (1) is especially useful in ANOVA-like situations where the location is assumed to change with the levels of some factor variable.} \item{disp, disp_h, odisp, idisp}{describe the regression model for the dispersion parameter of the fitted stable distribution, after transformation by the link function \code{disp_g} (set to the \code{log} function by default). The inverse link function is denoted by \code{disp_h}. Again these functions cannot contain unknown parameters. The same rules as above apply when specifying the generalized regression model for the dispersion parameter.} \item{skew, skew_h, oskew, iskew}{describe the regression model for the skewness parameter of the fitted stable distribution, after transformation by the link function \code{skew_g} (set to \code{log{(1 + [.])/(1 - [.])}} by default). The inverse link function is denoted by \code{skew_h}. Again these functions cannot contain unknown parameters. The same rules as above apply when specifying the generalized regression model for the skewness parameter.} \item{tail, tail_h, otail, itail}{describe the regression model considered for the tail parameter of the fitted stable distribution, after transformation by the link function \code{tail_g} (set to \code{log{([.] - 1)/(2 - [.])}} by default. The inverse link function is denoted by \code{tail_h}. Again these functions cannot contain unknown parameters). The same rules as above apply when specifying the generalized regression model for the tail parameter.} \item{noopt}{When set to TRUE, it forces \code{oloc}, \code{odisp}, \code{oskew} and \code{otail} to FALSE, whatever the user choice for these last three arguments. It is especially useful when looking for appropriate initial values for the regression model parameters, before undertaking the optimization of the likelihood.} \item{weights}{Weight vector.} \item{exact}{If TRUE, fits the exact likelihood function for continuous data by integration over intervals of observation, i.e. interval censoring.} \item{delta}{Scalar or vector giving the unit of measurement for each response value, set to unity by default. For example, if a response is measured to two decimals, \code{delta=0.01}. If the response is transformed, this must be multiplied by the Jacobian. For example, with a log transformation, \code{delta=1/y}. (The \code{delta} values for the censored response are ignored.) The transformation cannot contain unknown parameters.} \item{envir}{Environment in which model formulae are to be interpreted or a data object of class, \code{repeated}, \code{tccov}, or \code{tvcov}; the name of the response variable should be given in \code{y}. If \code{y} has class \code{repeated}, it is used as the environment.} \item{integration, eps, up, npoint}{\code{integration} indicates which algorithm must be used to evaluate the stable density when the likelihood is computed with \code{exact} set to FALSE. See the man page on \code{stable} for extra information.} \item{hessian}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{llik.output}{is TRUE when the likelihood has to be displayed at each iteration of the optimization.} \item{print.level}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{ndigit}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{steptol}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{gradtol}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{fscale}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{typsize}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{stepmax}{Arguments controlling the optimization procedure \code{\link{nlm}}.} \item{iterlim}{Arguments controlling the optimization procedure \code{\link{nlm}}.} } \value{ A list of class \code{stable} is returned. The printed output includes the -log-likelihood, the corresponding AIC, the maximum likelihood estimates, standard errors, and correlations. It also include all the relevant information calculated, including error codes. } \description{ \code{stablereg} fits user specified generalized linear and nonlinear regression models based on the stable distribution to (uncensored, right and/or left censored) data. This allows the location, the dispersion, the skewness and the tails of the fitted stable distribution to vary with explanatory variables. } \section{Warning}{ Because of the numerical integrations involved, convergence can be very sensitive to the initial parameter values supplied and to the settings of the arguments controlling \code{\link{nlm}}. If nlm feeds extreme parameter values in the tails of the distribution to the likelihood function, the integration may hang for a long time. } \examples{ ## Share return over a 50 day period (see reference above) # shares y <- c(296,296,300,302,300,304,303,299,293,294,294,293,295,287,288,297, 305,307,307,304,303,304,304,309,309,309,307,306,304,300,296,301,298, 295,295,293,292,297,294,293,306,303,301,303,308,305,302,301,297,299) # returns ret <- (y[2:50]-y[1:49])/y[1:49] # hist(ret, breaks=seq(-0.035,0.045,0.01)) day <- seq(0,0.48,by=0.01) # time measured in days/100 x <- seq(1,length(ret))-1 # Classic stationary normal model tail=2 print(z1 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~1, disp= ~1, skew = ~1, tail = tail_g(1.9999999), iloc = 0, idisp = -3, iskew = 0, oskew = FALSE, otail = FALSE)) # Normal model (tail=2) with dispersion=disp_h(b0+b1*day) print(z2 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~day, disp = ~1, skew = ~1, tail = tail_g(1.999999), iloc = c(0.003,0), idisp = -4.5, iskew = 0, oskew = FALSE, otail = FALSE)) # Stable model with loc(ation)=loc_h(b0+b1*day) print(z3 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~day, disp = ~1, skew = ~1, tail = ~1, iloc = c(0.001,-0.004), idisp = -4.8, iskew = 0, itail = 0.6)) # Stable model with disp(ersion)=disp_h(b0+b1*day) print(z4 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~1, disp = ~day, skew = ~1, tail = ~1, iloc = 0.003, idisp = c(-4.8,0), iskew = -0.03, itail = 1.6)) # Stable model with skew(ness)=skew_h(b0+b1*day) # Evaluation at fixed parameter values (because noopt is set to TRUE) print(z5 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~1, disp = ~1, skew = ~day, tail = ~1, iloc = 5.557e-04, idisp = -4.957, iskew = c(2.811,-2.158), itail = 1.57, noopt=TRUE)) # Stable model with tail=tail_h(b0+b1*day) print(z6 <- stablereg(y = ret, delta = 1/y[1:49], loc = ret ~ 1, disp = ~1, skew = ~1, tail = ~day, iloc = 0.002, idisp = -4.8, iskew = -2, itail = c(2.4,-4), hessian=FALSE)) } \references{ Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using regression models based on non-symmetric stable distributions. Applied Statistics 48, 409-424. } \seealso{ \code{\link{lm}}, \code{\link{glm}}, \code{stable} and \code{stable.mode}. } \author{ Philippe Lambert (Catholic University of Louvain, Belgium, \email{phlambert@stat.ucl.ac.be}) and Jim Lindsey. } \keyword{models} stable/man/stable.Rd0000644000176200001440000002034314207447606014054 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/stable.r \name{dstable} \alias{dstable} \alias{pstable} \alias{qstable} \alias{rstable} \alias{hstable} \title{Stable Distribution} \usage{ dstable( x, loc = 0, disp = 1/sqrt(2), skew = 0, tail = 2, npt = 501, up = 10, eps = 1e-06, integration = "Romberg" ) pstable(q, loc = 0, disp = 1/sqrt(2), skew = 0, tail = 2, eps = 1e-06) qstable(p, loc = 0, disp = 1/sqrt(2), skew = 0, tail = 2, eps = 1e-06) rstable(n = 1, loc = 0, disp = 1/sqrt(2), skew = 0, tail = 2, eps = 1e-06) hstable(x, loc = 0, disp = 1/sqrt(2), skew = 0, tail = 2, eps = 1e-06) } \arguments{ \item{x, q}{vector of quantiles.} \item{loc}{vector of (real) location parameters.} \item{disp}{vector of (positive) dispersion parameters.} \item{skew}{vector of skewness parameters (in [-1,1]).} \item{tail}{vector of parameters (in [0,2]) related to the tail thickness.} \item{npt, up, integration}{As detailed herein -- only available when using \code{dstable}.} \item{eps}{scalar giving the required precision in computation.} \item{p}{vector of probabilites.} \item{n}{number of observations.} } \description{ These functions provide information about the stable distribution with the location, the dispersion, the skewness and the tail thickness respectively modelled by the parameters \code{loc}, \code{disp}, \code{skew} and \code{tail}. These differ from those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization as detailed in Nolan (2020)). See the README for how to make equivalent calls to those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization as detailed in Nolan (2020)). } \details{ \code{dstable}, \code{pstable}, \code{qstable} and \code{hstable} compute the density, the distribution, the quantile and the hazard functions of a stable variate. \code{rstable} generates random deviates with the prescribed stable distribution. \code{loc} is a location parameter in the same way as the mean in the normal distribution: it can take any real value. \code{disp} is a dispersion parameter in the same way as the standard deviation in the normal distribution: it can take any positive value. \code{skew} is a skewness parameter: it can take any value in \eqn{(-1,1)}. The distribution is right-skewed, symmetric and left-skewed when \code{skew} is negative, null or positive respectively. \code{tail} is a tail parameter (often named the characteristic exponent): it can take any value in \eqn{(0,2)} (with \code{tail=1} and \code{tail=2} yielding the Cauchy and the normal distributions respectively when symmetry holds). If \code{loc}, \code{disp}, \code{skew}, or \code{tail} are not specified they assume the default values of \eqn{0}, \eqn{1/sqrt(2)}, \eqn{0} and \eqn{2} respectively. This corresponds to a normal variate with mean\eqn{=0} and variance\eqn{=1/2 disp^2}. The stable characteristic function is given by \deqn{greekphi(t) = i loca t - disp {|t|}^{tail} [1+i skew sign(t) greekomega(t,tail)]}{phi(t) = i loc t - disp |t|^tail [1+i skew sign(t) omega(t,tail)]} where \deqn{greekomega(t,tail) = \frac{2}{\pi} LOG(ABS(t))}{omega(t,tail) = (2/pi) log|t|} when \code{tail=1}, and \deqn{greekomega(t,tail) = tan(\frac{\pi tail}{2})}{omega(t,tail) = tan(pi alpha / 2)} otherwise. The characteristic function is inverted using Fourier's transform to obtain the corresponding stable density. This inversion requires the numerical evaluation of an integral from \eqn{0} to \eqn{\infty}{infinity}. Two algorithms are proposed for this. The default is Romberg's method (\code{integration}="Romberg") which is used to evaluate the integral with an error bounded by \code{eps}. The alternative method is Simpson's integration (\code{integration}="Simpson"): it approximates the integral from \eqn{0} to \eqn{\infty}{infinity} by an integral from \eqn{0} to \code{up} with \code{npt} points subdividing \eqn{(O, up)}. These three extra arguments -- \code{integration}, \code{up} and \code{npt} -- are only available when using \code{dstable}. The other functions are all based on Romberg's algorithm. [Swihart 2022 update:] See the README for how to make equivalent calls to those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization as detailed in Nolan (2020)). See github for Lambert and Lindsey 1999 JRSS-C journal article, which details the parameterization of the Buck (1995) stable distribution which allowed a Fourier inversion to arrive at a form similar to but not exactly the $g_d$ function as detailed in Nolan (2020), Abdul-Hamid and Nolan (1998) and Nolan (1997). The Nolan (2020) reference is a textbook that provides an accessible and comprehensive summary of stable distributions in the 25 years or so since the core of this R package was made and put on CRAN. The Buck (1995) parameterization most closely resembles the Zolotarev B parameterization outlined in Definition 3.6 on page 93 of Nolan (2020) -- except that Buck (1995) did not allow the scale parameter to multiply with the location parameter. This explains why the `Zolotarev B` entry in Table 3.1 on page 97 of Nolan (2020) has the location parameter being multiplied by the scale parameter whereas in converting the Lindsey and Lambert (1999) to Nolan 1-parameterization the location parameter stays the same. To be clear, \code{stable::dstable} and \code{stable::pstable} are evaluated by numerically integrating the inverse Fourier transform. The code works reasonably for small and moderate values of x, but will have numerical issues in some cases (such as values from \code{stable::pstable} being greater than 1 or or not being monotonic). The arguments \code{npt}, \code{up}, \code{integration}, and \code{eps} can be adjusted to improve accuracy at the cost of speed, but will still have limitations. Functions that better handle these problems are available in other packages (such as \code{stabledist} and \code{stable}) that use an alternative method (as detailed in Nolan 1997) distinct from directly numerically integrating the Fourier inverse transform. See last example in the README. } \section{Functions}{ \itemize{ \item \code{dstable}: density \item \code{pstable}: cdf \item \code{qstable}: quantiles \item \code{rstable}: random deviates \item \code{hstable}: hazard }} \examples{ par(mfrow=c(2,2)) x <- seq(-5,5,by=0.1) # Influence of loc (location) plot(x,dstable(x,loc=-2,disp=1/sqrt(2),skew=-0.8,tail=1.5), type="l",ylab="",main="Varying LOCation") lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5)) lines(x,dstable(x,loc=2,disp=1/sqrt(2),skew=-0.8,tail=1.5)) # Influence of disp (dispersion) plot(x,dstable(x,loc=0,disp=0.5,skew=0,tail=1.5), type="l",ylab="",main="Varying DISPersion") lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) lines(x,dstable(x,loc=0,disp=0.9,skew=0,tail=1.5)) # Influence of skew (skewness) plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5), type="l",ylab="",main="Varying SKEWness") lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0.8,tail=1.5)) # Influence of tail (tail) plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=0.8), type="l",ylab="",main="Varying TAIL thickness") lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=2)) } \references{ Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using regression models based on non-symmetric stable distributions. Applied Statistics, 48, 409-424. Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. Nolan, John P. "Numerical calculation of stable densities and distribution functions." Communications in statistics. Stochastic models 13.4 (1997): 759-774. Abdul-Hamid, Husein, and John P. Nolan. "Multivariate stable densities as functions of one dimensional projections." Journal of multivariate analysis 67.1 (1998): 80-89. } \seealso{ \code{\link[stable]{stablereg}} to fit generalized nonlinear regression models for the stable distribution parameters. R packages \code{stabledist} and \code{libstableR} provide [dpqr] functions. } \author{ Philippe Lambert (Catholic University of Louvain, Belgium, \email{phlambert@stat.ucl.ac.be}) Jim Lindsey } stable/man/Links.Rd0000644000176200001440000000070313426072710013650 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/stable.r \name{Links} \alias{Links} \alias{loc_g} \alias{loc_h} \alias{disp_g} \alias{disp_h} \alias{skew_g} \alias{skew_h} \alias{tail_g} \alias{tail_h} \title{Links} \usage{ loc_g(x) loc_h(x) disp_g(x) disp_h(x) skew_g(x) skew_h(x) tail_g(x) tail_h(x) } \arguments{ \item{x}{the function argument} } \description{ Link and inverse functions for use in stablereg } stable/man/Parameter_Conversion.Rd0000644000176200001440000000612614203221447016717 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/sd2s_and_s2sd.R \name{Parameter_Conversion} \alias{Parameter_Conversion} \alias{sd2s} \alias{s2sd} \title{Easy conversion of parameters between stabledist (Nolan 1-parameterization) and stable (Lambert and Lindsey 1999)} \usage{ sd2s(alpha, beta, gamma, delta, pm = 1) s2sd(tail, skew, disp, loc, pm = 1) } \arguments{ \item{alpha}{the stabledist 'alpha'} \item{beta}{the stabledist 'beta'} \item{gamma}{the stabledist 'gamma'} \item{delta}{the stabledist 'delta'} \item{pm}{default 1; currently only value supported. the stabledist parameterization 'pm'} \item{tail}{the stable 'tail' analogous to 'alpha'} \item{skew}{the stable 'skew' analogous to 'beta'} \item{disp}{the stable 'disp' analogous to 'gamma'} \item{loc}{the stable 'loc' analogous to 'delta'} } \value{ \code{sd2s} returns stable parameters as put forth in Lambert and Lindsey (1999) and used in this package. \code{s2sd} returns stabledist parameters (Nolan 1-parameterization). } \description{ \code{sd2s} has stabledist parameter (Nolan 1-parameterization) inputs and returns stable parameters as put forth in Lambert and Lindsey (1999) and used in this package. \code{s2sd} has stable parameter (Lambert and Lindsey (1999)) inputs and returns stabledist parameters (Nolan 1-parameterization). See examples and the readme. There's also more context and references in `?stable::dstable`. } \details{ [Swihart 2022 update:] See the examples and README for how to make equivalent calls to those of 'stabledist' (i.e., Nolan's 1-parameterization as detailed in Nolan (2020)) using these functions and this package. See github for Lambert and Lindsey 1999 JRSS-C journal article, which details the parameterization of the Buck (1995) stable distribution which allowed a Fourier inversion to arrive at a form of the $g_d$ function as detailed in Nolan (2020), The Buck (1995) parameterization most closely resembles the Zolotarev B parameterization outlined in Definition 3.6 on page 93 of Nolan (2020) -- except that Buck (1995) did not allow the scale parameter to multiply with the location parameter. This explains why the `Zolotarev B` entry in Table 3.1 on page 97 of Nolan (2020) has the location parameter being multiplied by the scale parameter whereas in converting the Lindsey and Lambert (1999) to Nolan 1-parameterization the location parameter stays the same. } \examples{ \dontrun{ q <- -1 # nolan pm=1 parameters: a <- 1.3 b <- -0.4 c <- 2 d <- 0.75 s <- sd2s(alpha=a, beta=b, gamma=c, delta=d) stable::pstable(q, tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) sd <- s2sd(tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) stabledist::pstable(q, alpha=sd$alpha, beta=sd$beta , gamma=sd$gamma , delta=sd$delta, pm=1)} } \references{ Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using regression models based on non-symmetric stable distributions. Applied Statistics, 48, 409-424. Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. } stable/man/stable.mode.Rd0000644000176200001440000000500313426072710014763 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/stable.r \name{stable.mode} \alias{stable.mode} \title{Mode of a Stable Distribution} \usage{ stable.mode(loc, disp, skew, tail) } \arguments{ \item{loc}{vector of (real) location parameters.} \item{disp}{vector of (positive) dispersion parameters.} \item{skew}{vector of skewness parameters (in [-1,1]).} \item{tail}{vector of parameters (in [1,2]) related to the tail thickness.} } \value{ A list of size 3 giving the mode, \eqn{a} and \eqn{b}. } \description{ This function gives a reliable approximation to the mode of a stable distribution with location, dispersion, skewness and tail thickness specified by the parameters \code{loc}, \code{disp}, \code{skew} and \code{tail}. \code{tail} must be in (1,2). } \details{ \code{loc} is a location parameter in the same way as the mean in the normal distribution: it can take any real value. \code{disp} is a dispersion parameter in the same way as the standard deviation in the normal distribution: it can take any positive value. \code{skew} is a skewness parameter: it can take any value in \eqn{(-1,1)}. The distribution is right-skewed, symmetric and left-skewed when \code{skew} is negative, null or positive respectively. \code{tail} is a tail parameter (often named the characteristic exponent): it can take any value in \eqn{(0,2)} (with \code{tail=1} and \code{tail=2} yielding the Cauchy and the normal distributions respectively when symmetry holds). The simplest empirical formula found to give a satisfactory approximation to the mode for values of \code{tail} in \eqn{(1,2)} is \deqn{ loc+disp*a*skew*exp(-b*abs(skew))} with \deqn{ a = 1.7665114+1.8417675*tail-2.2954390*tail^2+0.4666749*tail^3} and \deqn{ b = -0.003142967+632.4715*tail*exp(-7.106035*tail)}. } \examples{ x <- seq(-5,5,by=0.1) plot(x,dstable(x,loc=0,disp=1,skew=-1,tail=1.5),type="l",ylab="f(x)") xhat <- stable.mode(loc=0,disp=1,skew=-1,tail=1.5)$ytilde fxhat <- dstable(xhat,loc=0,disp=1,skew=-1,tail=1.5) lines(c(xhat,xhat),c(0,fxhat),lty="dotted") } \references{ Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using regression models based on non-symmetric stable distributions. Applied Statistics, 48, 409-424. } \seealso{ \code{stable} for more details on the stable distribution. \code{stablereg} to fit generalized linear models for the stable distribution parameters. } \author{ Philippe Lambert (Catholic University of Louvain, Belgium, \email{phlambert@stat.ucl.ac.be}) and Jim Lindsey. } \keyword{distribution} stable/man/Parameter_Conversion_Nolan_pm1_pm0.Rd0000644000176200001440000000435314203221243021371 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pm1_to_pm0_and_pm0_to_pm1.R \name{Parameter_Conversion_Nolan_pm1_pm0} \alias{Parameter_Conversion_Nolan_pm1_pm0} \alias{pm0_to_pm1} \alias{pm1_to_pm0} \title{Easy conversion of parameters between stabledist Nolan 1-parameterization and 0-parameterization} \usage{ pm0_to_pm1(a0, b0, c0, d0) pm1_to_pm0(a1, b1, c1, d1) } \arguments{ \item{a0}{the stabledist 'alpha' for pm=0 in 'stabledist'} \item{b0}{the stabledist 'beta' for pm=0 in 'stabledist'} \item{c0}{the stabledist 'gamma' for pm=0 in 'stabledist'} \item{d0}{the stabledist 'delta' for pm=0 in 'stabledist'} \item{a1}{the stabledist 'alpha' for pm=1 in 'stabledist'} \item{b1}{the stabledist 'beta' for pm=1 in 'stabledist'} \item{c1}{the stabledist 'gamma' for pm=1 in 'stabledist'} \item{d1}{the stabledist 'delta' for pm=1 in 'stabledist'} } \value{ \code{pm0_to_pm1} has stabledist parameter inputs for pm=0 and returns pm=1 equivalent parameterization. \code{pm1_to_pm0} has stabledist parameter inputs for pm=1 and returns pm=0 equivalent parameterization. } \description{ \code{pm0_to_pm1} has stabledist parameter inputs for pm=0 and returns pm=1 equivalent parameterization. \code{pm1_to_pm0} has stabledist parameter inputs for pm=1 and returns pm=0 equivalent parameterization. } \details{ See table Table 3.1 on page 97 of Nolan (2020). } \examples{ \dontrun{q <- -1 # nolan pm=1 parameters: a1 <- 1.3 b1 <- -0.4 c1 <- 2 d1 <- 0.75 # Convert to nolan pm=0 parameters: pm0 <- pm1_to_pm0(a1,b1,c1,d1) a0 <- pm0$a0 b0 <- pm0$b0 c0 <- pm0$c0 d0 <- pm0$d0 # check: stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #> [1] 0.1965513 # only change delta=d0 for pm=0 stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) stabledist::pstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #> [1] 0.1965513 stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #> [1] 0.0572133 # only change delta=d0 for pm=0 stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) stabledist::dstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #> [1] 0.0572133} } \references{ Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. } stable/DESCRIPTION0000644000176200001440000000302214207537472013242 0ustar liggesusersPackage: stable Version: 1.1.6 Title: Probability Functions and Generalized Regression Models for Stable Distributions Authors@R: c( person("Bruce", "Swihart", email="bruce.swihart@gmail.com", role=c("cre", "aut")), person("Jim" , "Lindsey", email="jlindsey@gen.unimaas.nl", role="aut", comment="Jim created this package, Bruce is maintaining the CRAN version"), person("Philippe", "Lambert", email="phlambert@stat.ucl.ac.be", role="aut") ) Depends: R (>= 1.4), rmutil Description: Density, distribution, quantile and hazard functions of a stable variate; generalized regression models for the parameters of a stable distribution. See the README for how to make equivalent calls to those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization as detailed in Nolan (2020)). See github for Lambert and Lindsey 1999 JRSS-C journal article, which details the parameterization of the Buck (1995) stable. See the Details section of the `?dstable` help file for context and references. License: GPL (>= 2) URL: https://www.commanster.eu/rcode.html BugReports: https://github.com/swihart/stable/issues Encoding: UTF-8 LazyLoad: true RoxygenNote: 7.1.2 NeedsCompilation: yes Packaged: 2022-03-01 18:54:52 UTC; swihartbj Author: Bruce Swihart [cre, aut], Jim Lindsey [aut] (Jim created this package, Bruce is maintaining the CRAN version), Philippe Lambert [aut] Maintainer: Bruce Swihart Repository: CRAN Date/Publication: 2022-03-02 00:50:02 UTC stable/src/0000755000176200001440000000000014207465774012333 5ustar liggesusersstable/src/stable_init.c0000644000176200001440000000113713426072307014762 0ustar liggesusers#include // for NULL #include /* FIXME: Check these declarations against the C/Fortran source code. */ /* .C calls */ extern void pstable_c(void *, void *, void *, void *, void *, void *, void *); extern void stable(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *); static const R_CMethodDef CEntries[] = { {"pstable_c", (DL_FUNC) &pstable_c, 7}, {"stable", (DL_FUNC) &stable, 10}, {NULL, NULL, 0} }; void R_init_stable(DllInfo *dll) { R_registerRoutines(dll, CEntries, NULL, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } stable/src/stable.c0000755000176200001440000001213013426072307013735 0ustar liggesusers/* * stable : A Library of Functions for Stable Distributions * Copyright (C) 1998, 1999, 2000, 2001 P. Lambert and J.K. Lindsey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * SYNOPSIS * * void stable(int *n, double *y, double *beta, double *alpha, int *npt, * double *up, double *eps, int *type, int *err, double *ffy) * void pstable_c(int *n, double *y, double *beta, double *alpha, * double *eps, int *err, double *ffy) * * DESCRIPTION * * Functions to compute the density and cdf of a stable distribution * */ #include #include #include "R.h" static int nn; static double alphai, etai, setai, cetai, yi, yyi; static double fcn1(double s){ double sa; sa=pow(s,alphai); return(cos(-yi*s+sa*setai)*exp(-sa*cetai));} static double fcn2(double s){ double sa; sa=pow(s,-alphai); return(cos(-yi/s+sa*setai)*exp(-sa*cetai)/(s*s));} static double fcn3(double s){ double sa; sa=pow(s,alphai); return((sin(yyi*s-sa*setai)/s)*exp(-sa*cetai));} static double fcn4(double s){ double sa; sa=pow(s,-alphai); return((sin(yyi/s-sa*setai)*s)*exp(-sa*cetai)/(s*s));} /* integration routines: stripped down version of Romberg integration from rmutil library */ static void interp(double x[], double fx[], double *f, double *df) { int i, j, ni=0; double diff1, diff2, tmp1, tmp2, lim1, lim2, tab1[6], tab2[5]; tmp1=fabs(x[0]); for(i=0;i<5;i++){ tmp2=fabs(x[i]); if(tmp2=5){ interp(&x[j1-5],&fx[j1-5],&sum,&errsum); if(fabs(errsum) Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. stable/R/0000755000176200001440000000000013426101216011721 5ustar liggesusersstable/R/sd2s_and_s2sd.R0000644000176200001440000001104514203221443014474 0ustar liggesusers#' Easy conversion of parameters between stabledist (Nolan 1-parameterization) and stable (Lambert and Lindsey 1999) #' #' \code{sd2s} has stabledist parameter (Nolan 1-parameterization) inputs and returns stable parameters as put forth in Lambert and Lindsey (1999) and used in this package. #' \code{s2sd} has stable parameter (Lambert and Lindsey (1999)) inputs and returns stabledist parameters (Nolan 1-parameterization). #' See examples and the readme. There's also more context and references in `?stable::dstable`. #' #' #' [Swihart 2022 update:] See the examples and README for how to make equivalent calls #' to those of 'stabledist' (i.e., Nolan's 1-parameterization #' as detailed in Nolan (2020)) using these functions and this package. #' See github for Lambert and Lindsey 1999 JRSS-C journal article, #' which details the parameterization of the Buck (1995) stable distribution which allowed #' a Fourier inversion to arrive at a form of the $g_d$ function as detailed in Nolan (2020), #' The Buck (1995) parameterization most closely resembles the Zolotarev B parameterization #' outlined in Definition 3.6 on page 93 of Nolan (2020) -- except that Buck (1995) did #' not allow the scale parameter to multiply with the location parameter. #' This explains why the `Zolotarev B` entry in Table 3.1 on page 97 of Nolan (2020) has #' the location parameter being multiplied by the scale parameter whereas in converting the Lindsey and Lambert (1999) #' to Nolan 1-parameterization the location parameter stays the same. #' #' @name Parameter_Conversion #' @aliases sd2s s2sd #' @param alpha the stabledist 'alpha' #' @param beta the stabledist 'beta' #' @param gamma the stabledist 'gamma' #' @param delta the stabledist 'delta' #' @param pm default 1; currently only value supported. the stabledist parameterization 'pm' #' @param tail the stable 'tail' analogous to 'alpha' #' @param skew the stable 'skew' analogous to 'beta' #' @param disp the stable 'disp' analogous to 'gamma' #' @param loc the stable 'loc' analogous to 'delta' #' #' @references Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using #' regression models based on non-symmetric stable distributions. Applied #' Statistics, 48, 409-424. #' #' @references Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. #' #' @return #' \code{sd2s} returns stable parameters as put forth in Lambert and Lindsey (1999) and used in this package. #' \code{s2sd} returns stabledist parameters (Nolan 1-parameterization). #' @export #' @examples #' \dontrun{ #' q <- -1 #' # nolan pm=1 parameters: #' a <- 1.3 #' b <- -0.4 #' c <- 2 #' d <- 0.75 #' s <- sd2s(alpha=a, beta=b, gamma=c, delta=d) #' stable::pstable(q, tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) #' stabledist::pstable(q, alpha=a, beta=b , gamma=c , delta=d, pm=1) #' sd <- s2sd(tail = s$tail, skew=s$skew, disp = s$disp, loc = s$loc) #' stabledist::pstable(q, alpha=sd$alpha, beta=sd$beta , gamma=sd$gamma , delta=sd$delta, pm=1)} sd2s <- function(alpha, beta, gamma, delta, pm=1){ if(pm==1){ a=alpha b=beta c=gamma d=delta # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same a3 <- a d3 <- d # the others require calcs: DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 DEL <- sqrt(DEL2) * sign(1-a) eta_a <- min(a, 2-a) # the lindsey-(3) beta: b3 <- -sign(b)*2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) # the lindsey-(3) scale: c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) } return(list(tail=a3, skew=b3, disp=c3, loc=d3 )) } #' @rdname Parameter_Conversion #' @export s2sd s2sd <- function(tail, skew, disp, loc, pm=1){ if(pm==1){ #a=alpha #b=beta #c=gamma #d=delta # lindsey-(3) page 415 conversion: # tail/alpha and location stay the same #a3 <- a #d3 <- d ## the others require calcs: #DEL2 <- cos(pi/2 * a)^2 + (-b)^2*sin(pi/2 * a)^2 #DEL <- sqrt(DEL2) * sign(1-a) #eta_a <- min(a, 2-a) ## the lindsey-(3) beta: #b3 <- -sign(b)*2/(pi*eta_a)*acos( cos(pi/2 * a) / DEL ) ## the lindsey-(3) scale: #c3 <- ( (DEL*c^a) / cos(pi/2 * a) )^(1/a) ## reverse! a3 <- tail b3 <- skew c3 <- disp d3 <- loc ## solve the above for b, c eta_a <- min(a3, 2-a3) DEL <- cos( pi * a3/2) / cos(b3 * pi * eta_a/2) DEL2 <- DEL^2 b <- -sign(b3) * sqrt( (DEL2 - cos(pi*a3/2)^2) / sin(pi*a3/2)^2 ) c <- c3 * ( cos(pi*a3/2) / DEL )^(1/a3) } return(list(alpha=a3, beta=b, gamma=c, delta=d3)) } stable/R/stable.r0000755000176200001440000016014714207450155013401 0ustar liggesusers#' Stable Distribution #' #'These functions provide information about the stable distribution #'with the location, the dispersion, the skewness and the tail thickness #'respectively modelled by the parameters \code{loc}, \code{disp}, #'\code{skew} and \code{tail}. These differ from those of 'stabledist' (i.e., Nolan's 0-parameterization and #'1-parameterization as detailed in Nolan (2020)). See the README for how to make equivalent calls #'to those of 'stabledist' (i.e., Nolan's 0-parameterization and #'1-parameterization as detailed in Nolan (2020)). #' #'\code{dstable}, \code{pstable}, \code{qstable} and \code{hstable} #'compute the density, the distribution, the quantile and the hazard functions #'of a stable variate. \code{rstable} generates random deviates with #'the prescribed stable distribution. #' #'\code{loc} is a location parameter in the same way as the mean #'in the normal distribution: it can take any real value. #' #'\code{disp} is a dispersion parameter in the same way as the standard #'deviation in the normal distribution: it can take any positive value. #' #'\code{skew} is a skewness parameter: it can take any value in \eqn{(-1,1)}. #'The distribution is right-skewed, symmetric and left-skewed #'when \code{skew} is negative, null or positive respectively. #' #'\code{tail} is a tail parameter (often named the characteristic exponent): #' it can take any value in \eqn{(0,2)} (with \code{tail=1} and \code{tail=2} #' yielding the Cauchy and the normal distributions respectively #' when symmetry holds). #' #'If \code{loc}, \code{disp}, \code{skew}, or \code{tail} are not #'specified they assume the default values of \eqn{0}, \eqn{1/sqrt(2)}, #'\eqn{0} and \eqn{2} respectively. This corresponds to a normal #'variate with mean\eqn{=0} and variance\eqn{=1/2 disp^2}. #' #'The stable characteristic function is given by #'\deqn{greekphi(t) = i loca t - disp {|t|}^{tail} [1+i skew sign(t) greekomega(t,tail)]}{phi(t) = i loc t - disp |t|^tail [1+i skew sign(t) omega(t,tail)]} #'where #'\deqn{greekomega(t,tail) = \frac{2}{\pi} LOG(ABS(t))}{omega(t,tail) = (2/pi) log|t|} #'when \code{tail=1}, and #'\deqn{greekomega(t,tail) = tan(\frac{\pi tail}{2})}{omega(t,tail) = tan(pi alpha / 2)} #'otherwise. #' #'The characteristic function is inverted using Fourier's transform #'to obtain the corresponding stable density. This inversion requires the #'numerical evaluation of an integral from \eqn{0} to \eqn{\infty}{infinity}. #'Two algorithms #'are proposed for this. The default is Romberg's method #'(\code{integration}="Romberg") which is used to evaluate the integral #'with an error bounded by \code{eps}. #'The alternative method is Simpson's integration #'(\code{integration}="Simpson"): it approximates the #'integral from \eqn{0} to \eqn{\infty}{infinity} by an integral #'from \eqn{0} to \code{up} #'with \code{npt} points subdividing \eqn{(O, up)}. #'These three extra arguments -- \code{integration}, \code{up} and #'\code{npt} -- are only available when using \code{dstable}. #'The other functions are all based on Romberg's algorithm. #' #' [Swihart 2022 update:] #' #' #' See the README for how to make equivalent calls #' to those of 'stabledist' (i.e., Nolan's 0-parameterization and 1-parameterization #' as detailed in Nolan (2020)). #' See github for Lambert and Lindsey 1999 JRSS-C journal article, #' which details the parameterization of the Buck (1995) stable distribution which allowed #' a Fourier inversion to arrive at a form similar to but not exactly the $g_d$ #' function as detailed in Nolan (2020), #' Abdul-Hamid and Nolan (1998) and Nolan (1997). #' The Nolan (2020) reference is a textbook that provides #' an accessible and comprehensive summary of stable distributions in the 25 years or so #' since the core of this R package was made and put on CRAN. #' The Buck (1995) parameterization most closely resembles the Zolotarev B parameterization #' outlined in Definition 3.6 on page 93 of Nolan (2020) -- except that Buck (1995) did #' not allow the scale parameter to multiply with the location parameter. #' This explains why the `Zolotarev B` entry in Table 3.1 on page 97 of Nolan (2020) has #' the location parameter being multiplied by the scale parameter whereas in converting the Lindsey and Lambert (1999) #' to Nolan 1-parameterization the location parameter stays the same. #' #' To be clear, \code{stable::dstable} and \code{stable::pstable} are evaluated #' by numerically integrating the inverse Fourier transform. The code works #' reasonably for small and moderate values of x, but will have numerical issues #' in some cases of large x (such as values from \code{stable::pstable} being greater than #' 1 or or not being monotonic). The arguments \code{npt}, \code{up}, #' \code{integration}, and \code{eps} can be adjusted #' to improve accuracy at the cost of speed, but will still have limitations. #' Functions that better handle these problems are available in other packages #' (such as \code{stabledist} and \code{stable}) that use an alternative method #' (as detailed in Nolan 1997) #' distinct from directly numerically integrating the Fourier inverse transform. #' See last example in the README. #' #' @param x,q vector of quantiles. #' @param p vector of probabilites. #' @param n number of observations. #' @param loc vector of (real) location parameters. #' @param disp vector of (positive) dispersion parameters. #' @param skew vector of skewness parameters (in [-1,1]). #' @param tail vector of parameters (in [0,2]) related to the tail thickness. #' @param eps scalar giving the required precision in computation. #' @param npt,up,integration As detailed herein -- only available when using \code{dstable}. #' #' @references Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns using #' regression models based on non-symmetric stable distributions. Applied #' Statistics, 48, 409-424. #' #' @references Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. #' #' @references Nolan, John P. "Numerical calculation of stable densities and distribution functions." Communications in statistics. Stochastic models 13.4 (1997): 759-774. #' #' @references Abdul-Hamid, Husein, and John P. Nolan. "Multivariate stable densities as functions of one dimensional projections." Journal of multivariate analysis 67.1 (1998): 80-89. #' #' @seealso \code{\link[stable]{stablereg}} to fit generalized nonlinear regression models #' for the stable distribution parameters. #' R packages \code{stabledist} and \code{libstableR} provide [dpqr] functions. #' #' @author Philippe Lambert (Catholic University of Louvain, Belgium, \email{phlambert@stat.ucl.ac.be}) #' @author Jim Lindsey #' #' # stable : A Library of Functions for Stable Distributions # Copyright (C) 1998, 1999, 2000, 2001 P. Lambert and J.K. Lindsey # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # SYNOPSIS # # dstable(y, loc=0, disp=1/sqrt(2), skew=0, tail=2, # npt=501, up=10, eps=1.0e-6, integration="Romberg") # dstable2(y, loc, disp, skew, tail, npt=501, up=10, # integration="Romberg") # pstable(y, loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6) # qstable(q, loc=0, disp=1/sqrt(2), skew=0, tail=2, eps=1.0e-6) # rstable(n=1,loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6) # hstable(y, loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6) # stablereg(y=NULL, loc=0, disp=1, skew=0, tail=1.5, # oloc=TRUE, odisp=TRUE, oskew=TRUE, otail=TRUE, noopt=FALSE, # iloc=NULL, idisp=NULL,iskew=NULL, itail=NULL, # loc_h=NULL, disp_h=NULL, skew_h=NULL, tail_h=NULL, # weights=1, exact=FALSE, delta=1, envir=parent.frame(), # integration="Romberg", eps=1e-6, up=10, npoint=501, # hessian=TRUE, llik.output=FALSE, print.level=0, ndigit=10, # steptol=0.00001, gradtol=0.00001, fscale=1, typsize=abs(p0), # stepmax=sqrt(p0%*%p0), iterlim=100) # stable.mode(loc,disp,skew,tail) # # DESCRIPTION # # Functions to obtain information about a stable distribution # and to fit regression models using this distribution. # .First.lib <- function(lib, pkg) # library.dynam("stable", pkg, lib) # require(rmutil) ########################################################################### # Density of a stable distribution # # This function produces the stable density computed at y. # Note that it is obtained by integrating a function from 0 to Infinity. # This integral is approximated by the finite integral from 0 to UP # using the Simpson's method with npt points or Romberg's integration #' @describeIn stable density #' @export #' @examples #' par(mfrow=c(2,2)) #' x <- seq(-5,5,by=0.1) #' #' # Influence of loc (location) #' plot(x,dstable(x,loc=-2,disp=1/sqrt(2),skew=-0.8,tail=1.5), #' type="l",ylab="",main="Varying LOCation") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5)) #' lines(x,dstable(x,loc=2,disp=1/sqrt(2),skew=-0.8,tail=1.5)) #' #' # Influence of disp (dispersion) #' plot(x,dstable(x,loc=0,disp=0.5,skew=0,tail=1.5), #' type="l",ylab="",main="Varying DISPersion") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=0.9,skew=0,tail=1.5)) #' #' # Influence of skew (skewness) #' plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5), #' type="l",ylab="",main="Varying SKEWness") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0.8,tail=1.5)) #' #' # Influence of tail (tail) #' plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=0.8), #' type="l",ylab="",main="Varying TAIL thickness") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=2)) #' dstable <- function(x, loc=0, disp=1/sqrt(2), skew=0, tail=2, npt=501, up=10, eps=1.0e-6, integration="Romberg"){ y<-x ly <- max(length(y),length(loc),length(disp),length(skew),length(tail)) if(length(y)!=ly){ if(length(y)==1)y <- rep(y,ly) else stop("length of y incorrect")} if(any(disp<0))stop("disp must be positive") if(any(skew< -1)||any(skew>1))stop("skew must lie in [-1,1]") if(length(skew)!=ly){ if(length(skew)==1)skew <- rep(skew,ly) else stop("length of skew incorrect")} if(any(tail<=0)||any(tail>2))stop("tail must lie in (0,2]") if(length(tail)!=ly){ if(length(tail)==1)tail <- rep(tail,ly) else stop("length of tail incorrect")} yy <- (y-loc)/disp ctail1 <- tail==1&skew==0 ctail2 <- tail==2 res <- vector(mode="numeric",ly) if(any(ctail1)){ res[ctail1] <- dcauchy(yy[ctail1]) ly <- ly-sum(ctail1)} if(any(ctail2)){ res[ctail2] <- dnorm(yy[ctail2],0,sqrt(2)) ly <- ly-sum(ctail2)} if(ly>0)res[!ctail1&!ctail2] <- .C("stable", as.integer(ly), as.double(yy[!ctail1&!ctail2]), as.double(skew[!ctail1&!ctail2]), as.double(tail[!ctail1&!ctail2]), as.integer(npt), as.double(up), as.double(eps), as.integer(if(integration=="Simpson")1 else 2), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy res/disp} ########################################################################### # c.d.f. of a stable distribution # #' @describeIn stable cdf #' @export pstable <- function(q, loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6){ y <- q yy <- (y-loc)/disp ly <- max(length(y),length(loc),length(disp),length(skew),length(tail)) if(length(y)!=ly){ if(length(y)==1)y <- rep(y,ly) else stop("length of y incorrect")} if(any(disp<0))stop("disp must be positive") if(any(skew< -1)||any(skew>1))stop("skew must lie in [-1,1]") if(length(skew)!=ly){ if(length(skew)==1)skew <- rep(skew,ly) else stop("length of skew incorrect")} if(any(tail<=0)||any(tail>2))stop("tail must lie in (0,2]") if(length(tail)!=ly){ if(length(tail)==1)tail <- rep(tail,ly) else stop("length of tail incorrect")} ctail1 <- tail==1&skew==0 ctail2 <- tail==2 res <- vector(mode="numeric",ly) if(any(ctail1)){ res[ctail1] <- pcauchy(yy[ctail1]) ly <- ly-sum(ctail1)} if(any(ctail2)){ res[ctail2] <- pnorm(yy[ctail2],0,sqrt(2)) ly <- ly-sum(ctail2)} if(ly>0)res[!ctail1&!ctail2] <- .C("pstable_c", as.integer(ly), as.double(yy[!ctail1&!ctail2]), as.double(skew[!ctail1&!ctail2]), as.double(tail[!ctail1&!ctail2]), as.double(eps), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy res} ########################################################################### # Quantile function of a stable random variable # #' @describeIn stable quantiles #' @export qstable <- function(p, loc=0, disp=1/sqrt(2), skew=0, tail=2, eps=1.0e-6){ q <- p h <- function(y).C("pstable_c", as.integer(1), as.double((y-loc[i])/disp[i]), as.double(skew[i]), as.double(tail[i]), as.double(eps), err=integer(1), ffy=double(1), PACKAGE="stable")$ffy-q[i] lq <- max(length(q),length(loc),length(disp),length(skew),length(tail)) if(length(q)!=lq){ if(length(q)==1)q <- rep(q,lq) else stop("length of q incorrect")} if(length(loc)!=lq){ if(length(loc)==1)loc <- rep(loc,lq) else stop("length of loc incorrect")} if(any(disp<0))stop("disp must be positive") if(length(disp)!=lq){ if(length(disp)==1)disp <- rep(disp,lq) else stop("length of disp incorrect")} if(any(skew< -1)||any(skew>1))stop("skew must lie in [-1,1]") if(length(skew)!=lq){ if(length(skew)==1)skew <- rep(skew,lq) else stop("length of skew incorrect")} if(any(tail<=0)||any(tail>2))stop("tail must lie in (0,2]") if(length(tail)!=lq){ if(length(tail)==1)tail <- rep(tail,lq) else stop("length of tail incorrect")} tmp <- vector(mode="numeric",lq) for (i in (1:lq)){ if(tail[i]==1&&skew[i]==0)tmp[i] <- qcauchy(q[i],loc[i],disp[i]) else if(tail[i]==2)tmp[i] <- qnorm(q[i],loc[i],disp[i]*sqrt(2)) else { if(tail[i]<1&&abs(skew[i])==1){ interval <- sign(skew[i])*c(0.001,10) while(TRUE){ tmp1 <- h(interval[1]) tmp2 <- h(interval[2]) if(is.na(tmp1*tmp2)||tmp1*tmp2<0)break interval[1] <- 0.5*interval[1] interval[2] <- 2*interval[2]}} else { interval <- loc[i]+disp[i]*c(-5,5) while(TRUE){ tmp1 <- h(interval[1]) tmp2 <- h(interval[2]) if(is.na(tmp1*tmp2)||tmp1*tmp2<0)break interval <- 2*interval}} tmp[i] <- if(is.na(tmp1*tmp2))NA else uniroot(h,interval)$root}} tmp} ########################################################################### # Generation of stable random deviates # #' @describeIn stable random deviates #' @export rstable <- function(n=1,loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6){ tmp1 <- qstable(runif(n),loc=loc,disp=disp,skew=skew,tail=tail,eps=eps) tmp2 <- tmp1[!is.na(tmp1)] n1 <- n while(any(is.na(tmp1))){ n1 <- n1-sum(!is.na(tmp1)) tmp1 <- qstable(runif(n1),loc=loc,disp=disp,skew=skew,tail=tail,eps=eps) tmp2 <- c(tmp2,tmp1[!is.na(tmp1)])} tmp2} ########################################################################### # Stable hazard # #' @describeIn stable hazard #' @export hstable <- function(x, loc=0,disp=1/sqrt(2),skew=0,tail=2,eps=1.0e-6){ y <- x dstable(y,loc=loc,disp=disp,skew=skew,tail=tail,eps=eps)/ (1-pstable(y,loc=loc,disp=disp,skew=skew,tail=tail,eps=eps))} ########################################################################### # Link and inverse link functions for use in stablereg #' Links #' #' Link and inverse functions for use in stablereg #' #' @name Links #' @aliases loc_g loc_h disp_g disp_h skew_g skew_h tail_g tail_h #' @param x the function argument #' @rdname Links #' @export loc_g loc_g <- function(x) x #' @rdname Links #' @export loc_h loc_h <- function(x) x #' @rdname Links #' @export disp_g disp_g <- function(x) log(x) #' @rdname Links #' @export disp_h disp_h <- function(x) exp(x) #' @rdname Links #' @export skew_g skew_g <- function(x) log((1+x)/(1-x)) #' @rdname Links #' @export skew_h skew_h <- function(x) 2/(1+exp(-x))-1 #' @rdname Links #' @export tail_g tail_g <- function(x) log(x/(2-x)) #' @rdname Links #' @export tail_h tail_h <- function(x) 2/(1+exp(-x)) ########################################################################### # Regression models for the four parameters in the stable distribution # Note that the returned optimized parameters are on the normalized # scale, i.e. that they have to be transformed back to the right scale. #' Stable Generalized Regression Models #' #' \code{stablereg} fits user specified generalized linear and nonlinear #' regression models based on the stable distribution to (uncensored, right #' and/or left censored) data. This allows the location, the dispersion, the #' skewness and the tails of the fitted stable distribution to vary with #' explanatory variables. #' #' #' @aliases stablereg fitted.stable df.residual.stable deviance.stable #' aic.stable #' @param y The response vector or a \code{repeated} data object. If the #' \code{repeated} data object contains more than one response variable, give #' that object in \code{envir} and give the name of the response variable to be #' used here. #' #' For censored data, two columns with the second being the censoring indicator #' (1: uncensored, 0: right censored, -1: left censored.) #' @param loc,loc_h,oloc,iloc Describe the regression model fitted for the #' location parameter of the stable distribution, perhaps after transformation #' by the link function \code{loc_g} (set to the identity by default. The #' inverse link function is denoted by \code{loc_h}. Note that these functions #' cannot contain unknown parameters). #' #' Two specifications are possible: #' #' (1) \code{loc} is a linear or nonlinear language expression beginning with ~ #' or an R function, describing the regression function for the location #' parameter (after transformation by \code{loc_g}, the link function). #' #' \code{iloc} is a vector of initial conditions for the parameters in the #' regression for this parameter. #' #' \code{oloc} is a boolean indicating if an optimization of the likelihood has #' to be carried out on these parameters. If \code{oloc} is set to TRUE, a #' default zero value is considered for the starting values \code{iloc}. But if #' no optimization is desired on the location parameters, i.e. when the #' likelihood has to be evaluated or optimized at a fixed location, then #' \code{iloc} has to be explicitely specified. #' #' (2) \code{loc} is a numeric expression (i.e. a scalar or a vector of the #' same size as the data vector \code{y}, or \code{y[,1]} when censoring is #' considered). #' #' If \code{oloc} is set to TRUE, i.e. when an optimization of the likelihood #' has to be carried out on the location parameter, then the location parameter #' (after transformation by the link function loc_g) is set to an unknown #' parameter with initial value equal to \code{iloc[1]} or \code{loc[1]} when #' \code{iloc} is not specified. #' #' But when \code{oloc} is set to FALSE, i.e. when the likelihood has to be #' evaluated or optimized at a fixed location, then the transformed location is #' assumed to be equal to \code{loc} when it is of the same length as the data #' vector \code{y} (or \code{y[,1]} when censoring is considered), and to #' \code{loc[1]} otherwise. #' #' Specification (1) is especially useful in ANOVA-like situations where the #' location is assumed to change with the levels of some factor variable. #' @param disp,disp_h,odisp,idisp describe the regression model for the #' dispersion parameter of the fitted stable distribution, after transformation #' by the link function \code{disp_g} (set to the \code{log} function by #' default). The inverse link function is denoted by \code{disp_h}. Again these #' functions cannot contain unknown parameters. The same rules as above apply #' when specifying the generalized regression model for the dispersion #' parameter. #' @param skew,skew_h,oskew,iskew describe the regression model for the #' skewness parameter of the fitted stable distribution, after transformation #' by the link function \code{skew_g} (set to \code{log{(1 + [.])/(1 - [.])}} #' by default). The inverse link function is denoted by \code{skew_h}. Again #' these functions cannot contain unknown parameters. The same rules as above #' apply when specifying the generalized regression model for the skewness #' parameter. #' @param tail,tail_h,otail,itail describe the regression model considered #' for the tail parameter of the fitted stable distribution, after #' transformation by the link function \code{tail_g} (set to \code{log{([.] - #' 1)/(2 - [.])}} by default. The inverse link function is denoted by #' \code{tail_h}. Again these functions cannot contain unknown parameters). The #' same rules as above apply when specifying the generalized regression model #' for the tail parameter. #' @param noopt When set to TRUE, it forces \code{oloc}, \code{odisp}, #' \code{oskew} and \code{otail} to FALSE, whatever the user choice for these #' last three arguments. It is especially useful when looking for appropriate #' initial values for the regression model parameters, before undertaking the #' optimization of the likelihood. #' @param weights Weight vector. #' @param exact If TRUE, fits the exact likelihood function for continuous data #' by integration over intervals of observation, i.e. interval censoring. #' @param delta Scalar or vector giving the unit of measurement for each #' response value, set to unity by default. For example, if a response is #' measured to two decimals, \code{delta=0.01}. If the response is transformed, #' this must be multiplied by the Jacobian. For example, with a log #' transformation, \code{delta=1/y}. (The \code{delta} values for the censored #' response are ignored.) The transformation cannot contain unknown parameters. #' @param envir Environment in which model formulae are to be interpreted or a #' data object of class, \code{repeated}, \code{tccov}, or \code{tvcov}; the #' name of the response variable should be given in \code{y}. If \code{y} has #' class \code{repeated}, it is used as the environment. #' @param integration,eps,up,npoint \code{integration} indicates which #' algorithm must be used to evaluate the stable density when the likelihood is #' computed with \code{exact} set to FALSE. See the man page on #' \code{stable} for extra information. #' @param llik.output is TRUE when the likelihood has to be displayed at each #' iteration of the optimization. #' @param print.level Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param ndigit Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param steptol Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param gradtol Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param fscale Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param typsize Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param stepmax Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param iterlim Arguments controlling the optimization procedure \code{\link{nlm}}. #' @param hessian Arguments controlling the optimization procedure \code{\link{nlm}}. #' @return A list of class \code{stable} is returned. The printed output #' includes the -log-likelihood, the corresponding AIC, the maximum likelihood #' estimates, standard errors, and correlations. It also include all the #' relevant information calculated, including error codes. #' @section Warning: Because of the numerical integrations involved, #' convergence can be very sensitive to the initial parameter values supplied #' and to the settings of the arguments controlling \code{\link{nlm}}. If nlm #' feeds extreme parameter values in the tails of the distribution to the #' likelihood function, the integration may hang for a long time. #' @author Philippe Lambert (Catholic University of Louvain, Belgium, #' \email{phlambert@@stat.ucl.ac.be}) and Jim Lindsey. #' @seealso \code{\link{lm}}, \code{\link{glm}}, \code{stable} #' and \code{stable.mode}. #' @references Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns #' using regression models based on non-symmetric stable distributions. Applied #' Statistics 48, 409-424. #' @keywords models #' @examples #' #' ## Share return over a 50 day period (see reference above) #' # shares #' y <- c(296,296,300,302,300,304,303,299,293,294,294,293,295,287,288,297, #' 305,307,307,304,303,304,304,309,309,309,307,306,304,300,296,301,298, #' 295,295,293,292,297,294,293,306,303,301,303,308,305,302,301,297,299) #' #' # returns #' ret <- (y[2:50]-y[1:49])/y[1:49] #' # hist(ret, breaks=seq(-0.035,0.045,0.01)) #' #' day <- seq(0,0.48,by=0.01) # time measured in days/100 #' x <- seq(1,length(ret))-1 #' #' # Classic stationary normal model tail=2 #' print(z1 <- stablereg(y = ret, delta = 1/y[1:49], #' loc = ~1, disp= ~1, skew = ~1, tail = tail_g(1.9999999), #' iloc = 0, idisp = -3, iskew = 0, oskew = FALSE, otail = FALSE)) #' #' # Normal model (tail=2) with dispersion=disp_h(b0+b1*day) #' print(z2 <- stablereg(y = ret, delta = 1/y[1:49], loc = ~day, #' disp = ~1, skew = ~1, tail = tail_g(1.999999), iloc = c(0.003,0), #' idisp = -4.5, iskew = 0, oskew = FALSE, otail = FALSE)) #' #' # Stable model with loc(ation)=loc_h(b0+b1*day) #' print(z3 <- stablereg(y = ret, delta = 1/y[1:49], #' loc = ~day, disp = ~1, skew = ~1, tail = ~1, #' iloc = c(0.001,-0.004), idisp = -4.8, iskew = 0, itail = 0.6)) #' #' # Stable model with disp(ersion)=disp_h(b0+b1*day) #' print(z4 <- stablereg(y = ret, delta = 1/y[1:49], #' loc = ~1, disp = ~day, skew = ~1, tail = ~1, #' iloc = 0.003, idisp = c(-4.8,0), iskew = -0.03, itail = 1.6)) #' #' # Stable model with skew(ness)=skew_h(b0+b1*day) #' # Evaluation at fixed parameter values (because noopt is set to TRUE) #' print(z5 <- stablereg(y = ret, delta = 1/y[1:49], #' loc = ~1, disp = ~1, skew = ~day, tail = ~1, #' iloc = 5.557e-04, idisp = -4.957, iskew = c(2.811,-2.158), #' itail = 1.57, noopt=TRUE)) #' #' # Stable model with tail=tail_h(b0+b1*day) #' print(z6 <- stablereg(y = ret, delta = 1/y[1:49], loc = ret ~ 1, #' disp = ~1, skew = ~1, tail = ~day, iloc = 0.002, #' idisp = -4.8, iskew = -2, itail = c(2.4,-4), hessian=FALSE)) #' #' @importFrom stats dcauchy dnorm nlm pcauchy pnorm qcauchy qnorm runif uniroot #' @import rmutil #' @useDynLib stable #' @export stablereg <- function(y=NULL, loc=0, disp=1, skew=0, tail=1.5, oloc=TRUE, odisp=TRUE, oskew=TRUE, otail=TRUE, noopt=FALSE, iloc=NULL, idisp=NULL,iskew=NULL, itail=NULL, loc_h=NULL, disp_h=NULL, skew_h=NULL, tail_h=NULL, weights=1, exact=FALSE, delta=1, envir=parent.frame(), integration="Romberg", eps=1e-6, up=10, npoint=501, hessian=TRUE, llik.output=FALSE, print.level=0, ndigit=10, steptol=0.00001, gradtol=0.00001, fscale=1, typsize=abs(p0), stepmax=sqrt(p0%*%p0), iterlim=100){ call <- sys.call() if(is.null(loc_h))loc_h <- function(x) x else if(!is.function(loc_h))stop("loc_h must be a link function") if(is.null(disp_h))disp_h <- function(x) exp(x) else if(!is.function(disp_h))stop("disp_h must be a link function") if(is.null(skew_h))skew_h <- function(x) 2/(1+exp(-x))-1 else if(!is.function(skew_h))stop("skew_h must be a link function") if(is.null(tail_h))tail_h <- function(x) 2/(1+exp(-x)) else if(!is.function(tail_h))stop("tail_h must be a link function") # If don't want to optimize at all, just set noopt=TRUE if(noopt)oloc <- odisp <- oskew <- otail <- FALSE respenv <- exists(deparse(substitute(y)),envir=parent.frame())&& inherits(y,"repeated")&&!inherits(envir,"repeated") if(respenv){ if(dim(y$response$y)[2]>1) stop("stablereg only handles univariate responses") if(!is.null(y$NAs)&&any(y$NAs)) stop("stablereg does not handle data with NAs")} envname <- if(respenv)deparse(substitute(y)) else if(!is.null(class(envir)))deparse(substitute(envir)) else NULL nploc <- length(iloc) npdisp <- length(idisp) npskew <- length(iskew) nptail <- length(itail) loc1 <- disp1 <- skew1 <- tail1 <- loc3 <- disp3 <- skew3 <- tail3 <- NULL if(respenv||inherits(envir,"repeated")||inherits(envir,"tccov")||inherits(envir,"tvcov")){ if(is.null(envname))envname <- deparse(substitute(envir)) if(inherits(loc,"formula")){ loc3 <- if(respenv)finterp(loc,.envir=y,.name=envname) else finterp(loc,.envir=envir,.name=envname)} else if(is.function(loc)){ if(is.null(attr(loc,"model"))){ tmp <- parse(text=deparse(loc)[-1]) loc <- if(respenv)fnenvir(loc,.envir=y,.name=envname) else fnenvir(loc,.envir=envir,.name=envname) nploc <- length(attr(loc,"parameters")) loc3 <- loc attr(loc3,"model") <- tmp} else loc3 <- loc} if(inherits(disp,"formula")){ disp3 <- if(respenv)finterp(disp,.envir=y,.name=envname) else finterp(disp,.envir=envir,.name=envname)} else if(is.function(disp)){ if(is.null(attr(disp,"model"))){ tmp <- parse(text=deparse(disp)[-1]) disp <- if(respenv)fnenvir(disp,.envir=y,.name=envname) else fnenvir(disp,.envir=envir,.name=envname) npdisp <- length(attr(disp,"parameters")) disp3 <- disp attr(disp3,"model") <- tmp} else disp3 <- disp} if(inherits(skew,"formula")){ skew3 <- if(respenv)finterp(skew,.envir=y,.name=envname) else finterp(skew,.envir=envir,.name=envname)} else if(is.function(skew)){ if(is.null(attr(skew,"model"))){ tmp <- parse(text=deparse(skew)[-1]) skew <- if(respenv)fnenvir(skew,.envir=y,.name=envname) else fnenvir(skew,.envir=envir,.name=envname) npskew <- length(attr(skew,"parameters")) skew3 <- skew attr(skew3,"model") <- tmp} else skew3 <- skew} if(inherits(tail,"formula")){ tail3 <- if(respenv)finterp(tail,.envir=y,.name=envname) else finterp(tail,.envir=envir,.name=envname)} else if(is.function(tail)){ if(is.null(attr(tail,"model"))){ tmp <- parse(text=deparse(tail)[-1]) tail <- if(respenv)fnenvir(tail,.envir=y,.name=envname) else fnenvir(tail,.envir=envir,.name=envname) nptail <- length(attr(tail,"parameters")) tail3 <- tail attr(tail3,"model") <- tmp} else tail3 <- tail}} # # if data object supplied, find response information in it # type <- "unknown" if(respenv){ if(dim(y$response$y)[2]>1) stop("stablereg only handles univariate responses") if(!is.null(y$NAs)&&any(y$NAs)) stop("stablereg does not handle data with NAs") if(inherits(envir,"repeated")&&(length(nobs(y))!=length(nobs(envir))||any(nobs(y)!=nobs(envir)))) stop("y and envir objects are incompatible") if(!is.null(y$response$delta)) delta <- as.vector(y$response$delta) type <- y$response$type y <- response(y) if(dim(y)[2]==1)y <- as.vector(y)} else if(inherits(envir,"repeated")){ if(!is.null(envir$NAs)&&any(envir$NAs)) stop("stablereg does not handle data with NAs") cn <- deparse(substitute(y)) if(length(grep("\"",cn))>0)cn <- y if(length(cn)>1)stop("only one y variable allowed") col <- match(cn,colnames(envir$response$y)) if(is.na(col))stop(paste("response variable",cn,"not found")) type <- envir$response$type[col] y <- envir$response$y[,col] if(!is.null(envir$response$n)&&!all(is.na(envir$response$n[,col]))) y <- cbind(y,envir$response$n[,col]-y) else if(!is.null(envir$response$censor)&&!all(is.na(envir$response$censor[,col]))) y <- cbind(y,envir$response$censor[,col]) if(!is.null(envir$response$wt))wt <- as.vector(envir$response$wt) if(!is.null(envir$response$delta)) delta <- as.vector(envir$response$delta[,col])} else if(inherits(y,"response")){ if(inherits(y,"multivariate")) stop("nordr only handles univariate responses") if(!is.null(y$delta))delta <- as.vector(y$delta) type <- y$type y <- response(y) if(dim(y)[2]==1)y <- as.vector(y)} if(any(is.na(y)))stop("NAs in y - use rmna") if(type!="unknown"&&type!="continuous"&&type!="duration") stop("continuous or duration data required") if(is.matrix(y)){ if(length(dim(y))!=2||dim(y)[2]!=2) stop("Two column matrix required for response\nTimes and censor indicator") else n <- dim(y)[1] censor <- TRUE} else { if(!is.vector(y))stop("y must be a vector") n <- length(y) censor <- FALSE} if(censor){ y[,2] <- as.integer(y[,2]) if(y[,2]!=-1&y[,2]!=0&y[,2]!=1) stop("Censor indicator must be -1s, 0s, and 1s") cc <- if(y[,2]==1)1 else 0 # observed rc <- if(y[,2]==0)1 else { if(y[,2]==-1)-1 else 0} # right censored lc <- if(y[,2]==-1)0 else 1 # left censored if(delta<=0&y[,2]==1) stop("All deltas for uncensored data must be positive")} if(censor)y <- y[,1] if(length(weights)==1)weights <- rep(weights,n) # LOC # From the coming lines, we see that if one does not want to optimize over # loc (ie. oloc=FALSE), then there are 2 alternatives: # (1) set loc equal to a value identical for all units: use loc= # (2) set loc equal to values varying through units: use loc= # and iloc= # Note that we work with the log.g link (identity link by default). # This means that language description of the loc model and # initial conditions are understood on that scale!! if(inherits(loc,"formula")){ nploc <- length(iloc) loc2 <- if(respenv)finterp(loc,.envir=y,.name=envname) else finterp(loc,.envir=envir,.name=envname) npt1 <- length(attr(loc2,"parameters")) if(is.character(attr(loc2,"model"))){ if(length(attr(loc2,"model"))==1){ loc1 <- function(p) loc_h(p[1]*rep(1,n)) attributes(loc1) <- attributes(loc2) loc2 <- NULL}} else { if(nploc!=npt1){ cat("\nParameters are ") cat(attr(loc2,"parameters"),"\n") stop(paste("iloc should have",npt1,"estimates"))} if(is.list(iloc)){ if(!is.null(names(iloc))){ o <- match(attr(loc2,"parameters"),names(iloc)) iloc <- unlist(iloc)[o] if(sum(!is.na(o))!=length(iloc))stop("invalid estimates for loc - probably wrong names")} else iloc <- unlist(iloc)}} if(!is.null(loc2)){ if(inherits(envir,"tccov")){ cv <- covind(y) loc1 <- function(p) loc_h(loc2(p)[cv]) attributes(loc1) <- attributes(loc2)} else loc1 <- function(p) loc_h(loc2(p)) attributes(loc1) <- attributes(loc2)}} else if(is.function(loc))loc1 <- loc if(!is.null(loc1)&&is.null(attr(loc1,"parameters"))){ attributes(loc1) <- if(is.function(loc)){ if(!inherits(loc,"formulafn")){ if(respenv)attributes(fnenvir(loc,.envir=y)) else attributes(fnenvir(loc,.envir=envir))} else attributes(loc)} else { if(respenv)attributes(fnenvir(loc1,.envir=y)) else attributes(fnenvir(loc1,.envir=envir))}} nlp <- if(is.function(loc1))length(attr(loc1,"parameters")) else if(is.null(loc1))NULL else npt1 if(!is.null(nlp)&&nlp!=nploc) stop(paste("iloc should have",nlp,"initial estimates")) if(inherits(loc,"formula")||is.function(loc)){ if(oloc){ if(is.numeric(iloc) && length(iloc)!=nploc) stop(paste("iloc must be of size ",nploc)) if(!is.numeric(iloc)) iloc <- rep(0,nploc) fnloc <- loc1} else { if(!is.numeric(iloc)) stop("Missing initial conditions for loc") else if(length(iloc)!=nploc) stop(paste("iloc must be of size ",nploc)) else fnloc <- function(p) loc1(iloc)}} else if(oloc){ fnloc <- function(p) loc_h(rep(p[1],n)) if(!is.numeric(iloc)){ iloc <- loc[1] nploc <- 1}} else { # IMPORTANT if(length(loc)==n)fnloc <- function(p) loc_h(loc) # IMPORTANT else fnloc <- function(p) rep(loc_h(loc[1]),n) nploc <- 1} # DISP # Note that we work with the disp_g link (log link by default). # This means that language description of the disp model and # initial conditions are understood on that scale!! # Non language description of disp are also understood on the disp_g scale # and specified using disp=, yielding disp_h() for the # parameter disp. npl2 <- if(odisp)nploc*oloc+1 else 1 if(inherits(disp,"formula")){ npdisp <- length(idisp) disp2 <- if(respenv)finterp(disp,.envir=y,.start=npl2,.name=envname) else finterp(disp,.envir=envir,.start=npl2,.name=envname) npt2 <- length(attr(disp2,"parameters")) if(is.character(attr(disp2,"model"))){ if(length(attr(disp2,"model"))==1){ disp1 <- function(p) disp_h(p[npl2]*rep(1,n)) attributes(disp1) <- attributes(disp2) disp2 <- NULL}} else { if(npdisp!=npt2){ cat("\nParameters are ") cat(attr(disp2,"parameters"),"\n") stop(paste("idisp should have",npt2,"estimates"))} if(is.list(idisp)){ if(!is.null(names(idisp))){ o <- match(attr(disp2,"parameters"),names(idisp)) idisp <- unlist(idisp)[o] if(sum(!is.na(o))!=length(idisp))stop("invalid estimates for disp - probably wrong names")} else idisp <- unlist(idisp)}} if(!is.null(disp2)){ if(inherits(envir,"tccov")){ cv <- covind(y) disp1 <- function(p) disp_h(disp2(p)[cv])} else disp1 <- function(p) disp_h(disp2(p)) attributes(disp1) <- attributes(disp2)}} else if(is.function(disp))disp1 <- function(p) disp(p[npl2:(npl2+npdisp-1)]) if(!is.null(disp1)&&is.null(attr(disp1,"parameters"))){ attributes(disp1) <- if(is.function(disp)){ if(!inherits(disp,"formulafn")){ if(respenv)attributes(fnenvir(disp,.envir=y)) else attributes(fnenvir(disp,.envir=envir))} else attributes(disp)} else { if(respenv)attributes(fnenvir(disp1,.envir=y)) else attributes(fnenvir(disp1,.envir=envir))}} nlp <- if(is.function(disp1))length(attr(disp1,"parameters")) else if(is.null(disp1))NULL else npt2 if(!is.null(nlp)&&nlp!=npdisp) stop(paste("idisp should have",nlp,"initial estimates")) if(inherits(disp,"formula")||is.function(disp)){ if(odisp){ if(is.numeric(idisp) && length(idisp)!=npdisp) stop(paste("idisp must be of size ",npdisp)) else if(!is.numeric(idisp)) idisp <- rep(0,npdisp) fndisp <- disp1} else { if(!is.numeric(idisp)) stop("Missing initial conditions for disp") else if(length(idisp)!=npdisp) stop(paste("idisp must be of size ",npdisp)) else fndisp <- function(p) disp1(idisp)}} else if(odisp){ fndisp <- function(p) disp_h(rep(p[npl2],n)) if(!is.numeric(idisp)){ idisp <- disp[1] npdisp <- 1}} else { # IMPORTANT if(length(disp)==n)fndisp <- function(p) disp_h(disp) # IMPORTANT else fndisp <- function(p) rep(disp_h(disp[1]),n) npdisp <- 1} # SKEW # Note that, y default, we work with the skew_g([.])=log{(1+[.])/(1-[.])} link. # This means that language description of the skew model and # the possible initial conditions are understood on that scale!! # Non language description of skew are also understood on the skew_g scale # and specified using skew=, yielding skew_h() for the # parameter skew. npl3 <- if(oskew)nploc*oloc+npdisp*odisp+1 else 1 if(inherits(skew,"formula")){ npskew <- length(iskew) skew2 <- if(respenv)finterp(skew,.envir=y,.start=npl3,.name=envname) else finterp(skew,.envir=envir,.start=npl3,.name=envname) npt3 <- length(attr(skew2,"parameters")) if(is.character(attr(skew2,"model"))){ if(length(attr(skew2,"model"))==1){ skew1 <- function(p) skew_h(p[npl3]*rep(1,n)) attributes(skew1) <- attributes(skew2) skew2 <- NULL}} else { if(npskew!=npt3){ cat("\nParameters are ") cat(attr(skew2,"parameters"),"\n") stop(paste("iskew should have",npt3,"estimates"))} if(is.list(iskew)){ if(!is.null(names(iskew))){ o <- match(attr(skew2,"parameters"),names(iskew)) iskew <- unlist(iskew)[o] if(sum(!is.na(o))!=length(iskew))stop("invalid estimates for skew - probably wrong names")} else iskew <- unlist(iskew)}} if(!is.null(skew2)){ if(inherits(envir,"tccov")){ cv <- covind(y) skew1 <- function(p) skew_h(skew2(p)[cv])} else skew1 <- function(p) skew_h(skew2(p)) attributes(skew1) <- attributes(skew2)}} else if(is.function(skew))skew1 <- function(p) skew(p[npl3:(npl3+npskew-1)]) if(!is.null(skew1)&&is.null(attr(skew1,"parameters"))){ attributes(skew1) <- if(is.function(skew)){ if(!inherits(skew,"formulafn")){ if(respenv)attributes(fnenvir(skew,.envir=y)) else attributes(fnenvir(skew,.envir=envir))} else attributes(skew)} else { if(respenv)attributes(fnenvir(skew1,.envir=y)) else attributes(fnenvir(skew1,.envir=envir))}} nlp <- if(is.function(skew1))length(attr(skew1,"parameters")) else if(is.null(skew1))NULL else npt3 if(!is.null(nlp)&&nlp!=npskew) stop(paste("iskew should have",nlp,"initial estimates")) if(inherits(skew,"formula")||is.function(skew)){ if(oskew){ if(is.numeric(iskew) && length(iskew)!=npskew) stop(paste("iskew must be of size ",npskew)) else if(!is.numeric(iskew)) iskew <- rep(0,npskew) fnskew <- skew1} else { if(!is.numeric(iskew)) stop("Missing initial conditions for skew") else if(length(iskew)!=npskew) stop(paste("iskew must be of size ",npskew)) else fnskew <- function(p) skew1(iskew)}} else if(oskew){ fnskew <- function(p) skew_h(rep(p[npl3],n)) if(!is.numeric(iskew)){ iskew <- skew[1] npskew <- 1}} else { if(length(skew)==n) fnskew <- function(p) skew_h(skew) else fnskew <- function(p) rep(skew_h(skew[1]),n) # IMPORTANT npskew <- 1} # TAIL # Note that we work with the tail_g([.])=log{([.]-1)/(2-[.])} link. # This means that language description of the tail model and # the possible initial conditions are understood on that scale!! # Non language description of tail are also understood on the tail_g scale # and specified using tail=, yielding tail_h() for the # parameter tail. npl4 <- if(otail)nploc*oloc+npdisp*odisp+npskew*oskew+1 else 1 if(inherits(tail,"formula")){ nptail <- length(itail) tail2 <- if(respenv)finterp(tail,.envir=y,.start=npl4,.name=envname) else finterp(tail,.envir=envir,.start=npl4,.name=envname) npt4 <- length(attr(tail2,"parameters")) if(is.character(attr(tail2,"model"))){ if(length(attr(tail2,"model"))==1){ tail1 <- function(p) tail_h(p[npl4]*rep(1,n)) attributes(tail1) <- attributes(tail2) tail2 <- NULL}} else { if(nptail!=npt4){ cat("\nParameters are ") cat(attr(tail2,"parameters"),"\n") stop(paste("itail should have",npt4,"estimates"))} if(is.list(itail)){ if(!is.null(names(itail))){ o <- match(attr(tail2,"parameters"),names(itail)) itail <- unlist(itail)[o] if(sum(!is.na(o))!=length(itail))stop("invalid estimates for tail - probably wrong names")} else itail <- unlist(itail)}} if(!is.null(tail2)){ if(inherits(envir,"tccov")){ cv <- covind(y) tail1 <- function(p) tail_h(tail2(p)[cv])} else tail1 <- function(p) tail_h(tail2(p)) attributes(tail1) <- attributes(tail2)}} else if(is.function(tail))tail1 <- function(p) tail(p[npl4:(npl4+nptail-1)]) if(!is.null(tail1)&&is.null(attr(tail1,"parameters"))){ attributes(tail1) <- if(is.function(tail)){ if(!inherits(tail,"formulafn")){ if(respenv)attributes(fnenvir(tail,.envir=y)) else attributes(fnenvir(tail,.envir=envir))} else attributes(tail)} else { if(respenv)attributes(fnenvir(tail1,.envir=y)) else attributes(fnenvir(tail1,.envir=envir))}} nlp <- if(is.function(tail1))length(attr(tail1,"parameters")) else if(is.null(tail1))NULL else npt4 if(!is.null(nlp)&&nlp!=nptail) stop(paste("itail should have",nlp,"initial estimates")) if(inherits(tail,"formula")||is.function(tail)){ if(otail){ if(is.numeric(itail) && length(itail)!=nptail) stop(paste("itail must be of size ",nptail)) else if(!is.numeric(itail)) itail <- rep(0,nptail) fntail <- tail1} else { if(!is.numeric(itail)) stop("Missing initial conditions for tail") else if(length(itail)!=nptail) stop(paste("itail must be of size ",nptail)) else fntail <- function(p) tail1(itail)}} else if(otail){ fntail <- function(p) tail_h(rep(p[npl4],n)) if(!is.numeric(itail)){ itail <- tail[1] nptail <- 1}} else { if(length(tail)==n)fntail <- function(p) tail_h(tail) else fntail <- function(p) rep(tail_h(tail[1]),n) # IMPORTANT nptail <- 1} # Computation of -log-likelihood ly <- length(y) z0 <- rep(0,ly) llikstable <- function(p){ # ,up=up,integration=integration) { loc <- fnloc(p) disp <- fndisp(p) skew <- fnskew(p) tail <- fntail(p) if(!censor){ if(exact){ tamp <- .C("pstable_c", as.integer(ly), yy=as.double((y+delta/2-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.double(eps), err=integer(1), ffy=double(ly))$ffy- .C("pstable_c", as.integer(ly), yy=as.double((y-delta/2-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.double(eps), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy llikcomp <- -(log(tamp))*weights} else { tamp <- .C("stable", as.integer(ly), yy=as.double((y-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.integer(npoint), as.double(up), as.double(eps), as.integer(if(integration=="Simpson")1 else 2), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy/disp llikcomp <- -(log(tamp)+log(delta))*weights}} else { if(exact){ p1 <- .C("pstable_c", as.integer(ly), yy=as.double((y+delta/2-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.double(eps), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy ps <- .C("pstable_c", as.integer(ly), yy=as.double((y-delta/2-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.double(eps), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy llikcomp <- -weights*(cc*log(p1-ps)+log(lc-rc*ps))} else { tamp <- .C("stable", as.integer(ly), yy=as.double((y-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.integer(npoint), as.double(up), as.double(eps), as.integer(if(integration=="Simpson")1 else 2), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy/disp llikcomp <- -weights*(cc*(log(tamp)+log(delta)) +log(lc-rc* .C("pstable_c", as.integer(ly), yy=as.double((y-loc)/disp), skew=as.double(skew+z0), tail=as.double(tail+z0), as.double(eps), err=integer(1), ffy=double(ly), PACKAGE="stable")$ffy))}} llik <- sum(llikcomp) if(llik.output){ if(length(p)==0)cat("-LogLik: ",sum(llikcomp),"\n") else cat("-LogLik: ",sum(llikcomp)," ",p,"\n")} z <- list( llik=llik, llikcomp=llikcomp, loc=loc, disp=disp, skew=skew, tail=tail) z} # This function returns -llik (and NOT the deviance) to get the # correct s.e's with the hessian returned by nlm (optimization routine). optstable <- function(p){ tamp <- llikstable(p)$llik if(llik.output) cat("-LogLik: ",tamp," (",p,")","\n") if(is.na(tamp))1e20 else tamp} # initial conditions p0 <- c() if(oloc) { p0 <- c(iloc) names(p0) <- c(rep("iloc",length(iloc)))} if(odisp) { tamp <- names(p0) p0 <- c(p0,idisp) names(p0) <- c(tamp,rep("idisp",length(idisp)))} if(oskew) { tamp <- names(p0) p0 <- c(p0,iskew) names(p0) <- c(tamp,rep("iskew",length(iskew)))} if(otail) { tamp <- names(p0) p0 <- c(p0,itail) names(p0) <- c(tamp,rep("itail",length(itail)))} if(llik.output) { cat("No. of parameters: ",nploc,"",npdisp,"",npskew,"",nptail,"\n") if(oloc||odisp||oskew||otail){ cat("Vector of initial conditions on IR^p:","\n") print(p0)}} # -Log-likelihood at p0 llik0 <- llikstable(p=p0) np0 <- length(p0) if(np0>0){ p.opt <- nlm(optstable, p=p0, hessian=hessian, fscale=fscale, typsize=rep(1,length(p0)), print.level=print.level, ndigit=ndigit, gradtol=gradtol, steptol=steptol, iterlim=iterlim, stepmax=stepmax) z <- llikstable(p.opt$estimate)} else z <- llikstable(p0) ytilde.tamp <- stable.mode(z$loc,z$disp,z$skew,z$tail)$ytilde # corresponding mode tamp <- dstable(x=ytilde.tamp, loc=z$loc, disp=z$disp, skew=z$skew, tail=z$tail, npt=npoint, up=up, integration=integration) llik.ytilde <- -(log(tamp)+log(delta))*weights ytilde.tamp <- stable.mode(z$loc,z$disp,z$skew,z$tail)$ytilde np <- nploc+npdisp+npskew+nptail llik <- z$llik aic <- llik+np0 nobs <- sum(as.numeric(weights)) df <- nobs-np0 loc <- as.vector(z$loc) disp <- as.vector(z$disp) skew <- as.vector(z$skew) tail <- as.vector(z$tail) ytilde <- stable.mode(loc,disp,skew,tail)$ytilde # corresponding mode residuals <- as.vector((y-loc)/disp) if(!is.null(loc3))loc1 <- loc3 if(!is.null(disp3))disp1 <- disp3 if(!is.null(skew3))skew1 <- skew3 if(!is.null(tail3))tail1 <- tail3 if(np0>0){ cov <- diag(np0) if(hessian){ if(np0==1)cov <- 1/p.opt$hessian else { a <- if(any(is.na(p.opt$hessian))||any(abs(p.opt$hessian)==Inf))0 else qr(p.opt$hessian)$rank if(a==np0)cov <- solve(p.opt$hessian) else cov <- matrix(NA,ncol=np0,nrow=np0)}} se <- if(hessian)sqrt(diag(cov)) else NA corr <- if(hessian)cov/(se%o%se) else NA coefficients <- p.opt$estimate gradient <- p.opt$gradient error <- p.opt$error code <- p.opt$code iterations <- p.opt$iter} else iterations <- coefficients <- se <- cov <- corr <- gradient <- hessian <- error <- code <- NULL z1 <- list( call=call, y=y, loc=loc, disp=disp, skew=skew, tail=tail, oloc=oloc, odisp=odisp, oskew=oskew, otail=otail, loc1=loc1, disp1=disp1, skew1=skew1, tail1=tail1, ytilde=ytilde, start=p0, weights=weights, llik=llik, llikcomp=z$llikcomp, residuals=residuals, aic=aic, npar=np, nploc=nploc, npdisp=npdisp, npskew=npskew, nptail=nptail, npar.opt=np0, n=nobs, df=df, coefficients=coefficients, se=se, cov=cov, corr=corr, gradient=gradient, hessian=hessian, iterations=iterations, error=error, code=code, integration=integration) class(z1) <- "stable" z1} ########################################################################### # Stable class functions # fitted.stable <- function(z) z$loc df.residual.stable <- function(z) z$df aic <- function (object, ...) UseMethod("aic") aic.stable <- function(z) z$aic deviance.stable <- function(z) 2*z$llik print.stable <- function(z,digits=max(4,.Options$digits-3),correlation=TRUE) { np <- z$npar.opt if(!z$oloc)nploc <- 0 if(!z$odisp)npdisp <- 0 if(!z$oskew)npskew <- 0 if(!z$otail)nptail <- 0 cat("\nCall:",deparse(z$call),sep="\n") cat("\n") if(!is.null(z$code)&&z$code>2) cat("Warning: no convergence - error",z$code,"\n\n") cat("-Log likelihood ",z$llik,"\n") cat("No. of obs ",z$n,"\n") cat("No. of estimated parameters ",np,"\n") cat("No. of parameters ",z$npar,"\n") cat("Degrees of freedom ",z$df,"\n") cat("AIC ",z$aic,"\n") if(!is.null(z$iterations)) cat("Iterations ",z$iterations,"\n") if(z$oloc&&z$nploc>0){ cat("\nLocation parameters\n") if(!is.null(attr(z$loc1,"formula"))) cat(deparse(attr(z$loc1,"formula")),sep="\n") else if(!is.null(attr(z$loc1,"model"))){ t <- deparse(attr(z$loc1,"model")) t[1] <- sub("expression\\(","",t[1]) t[length(t)] <- sub("\\)$","",t[length(t)]) cat(t,sep="\n")} cname <- if(is.character(attr(z$loc1,"model"))) attr(z$loc1,"model") else if(!is.null(attr(z$loc1,"parameters"))) attr(z$loc1,"parameters") else paste(1:z$nploc) coef.table <- cbind(z$coef[1:z$nploc],z$se[1:z$nploc]) colname <- c("estimate","se") dimnames(coef.table) <- list(cname,colname) print.default(coef.table, digits=digits, print.gap=2)} if(z$odisp&&z$npdisp>0){ cat("\nDispersion parameters\n") if(!is.null(attr(z$disp,"formula"))) cat(deparse(attr(z$disp,"formula")),sep="\n") else if(!is.null(attr(z$disp,"model"))){ t <- deparse(attr(z$disp,"model")) t[1] <- sub("expression\\(","",t[1]) t[length(t)] <- sub("\\)$","",t[length(t)]) cat(t,sep="\n")} cname <- if(is.character(attr(z$disp,"model"))) attr(z$disp,"model") else if(!is.null(attr(z$disp,"parameters"))) attr(z$disp,"parameters") else paste(1:z$npdisp) coef.table <- cbind(z$coef[(z$nploc*z$oloc+1):(z$nploc*z$oloc+z$npdisp)],z$se[(z$nploc*z$oloc+1):(z$nploc*z$oloc+z$npdisp)]) colname <- c("estimate","se") dimnames(coef.table) <- list(cname,colname) print.default(coef.table, digits=digits, print.gap=2)} if(z$oskew&&z$npskew>0){ cat("\nSkew parameters\n") if(!is.null(attr(z$skew1,"formula"))) cat(deparse(attr(z$skew1,"formula")),sep="\n") else if(!is.null(attr(z$skew1,"model"))){ t <- deparse(attr(z$skew1,"model")) t[1] <- sub("expression\\(","",t[1]) t[length(t)] <- sub("\\)$","",t[length(t)]) cat(t,sep="\n")} cname <- if(is.character(attr(z$skew1,"model"))) attr(z$skew1,"model") else if(!is.null(attr(z$skew1,"parameters"))) attr(z$skew1,"parameters") else paste(1:z$npskew) coef.table <- cbind(z$coef[(z$nploc*z$oloc+z$npdisp*z$odisp+1):(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew)],z$se[(z$nploc*z$oloc+z$npdisp*z$odisp+1):(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew)]) colname <- c("estimate","se") dimnames(coef.table) <- list(cname,colname) print.default(coef.table, digits=digits, print.gap=2)} if(z$otail&&z$nptail>0){ cat("\nTail parameters\n") if(!is.null(attr(z$tail1,"formula"))) cat(deparse(attr(z$tail1,"formula")),sep="\n") else if(!is.null(attr(z$tail1,"model"))){ t <- deparse(attr(z$tail1,"model")) t[1] <- sub("expression\\(","",t[1]) t[length(t)] <- sub("\\)$","",t[length(t)]) cat(t,sep="\n")} cname <- if(is.character(attr(z$tail1,"model"))) attr(z$tail1,"model") else if(!is.null(attr(z$tail1,"parameters"))) attr(z$tail1,"parameters") else paste(1:z$nptail) coef.table <- cbind(z$coef[(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew*z$oskew+1):(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew*z$oskew+z$nptail)],z$se[(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew*z$oskew+1):(z$nploc*z$oloc+z$npdisp*z$odisp+z$npskew*z$oskew+z$nptail)]) colname <- c("estimate","se") dimnames(coef.table) <- list(cname,colname) print.default(coef.table, digits=digits, print.gap=2)} if(!is.null(z$hessian)&&z$hessian&&np>1&&correlation){ cat("\nCorrelations:\n") dimnames(z$corr) <- list(seq(1,np),seq(1,np)) print.default(z$corr, digits=digits)}} ########################################################################### # Computation of the mode ytilde as a function of (loc,disp,skew,tail) #' Mode of a Stable Distribution #' #' This function gives a reliable approximation to the mode of a stable #' distribution with location, dispersion, skewness and tail thickness #' specified by the parameters \code{loc}, \code{disp}, \code{skew} and #' \code{tail}. \code{tail} must be in (1,2). #' #' \code{loc} is a location parameter in the same way as the mean in the normal #' distribution: it can take any real value. #' #' \code{disp} is a dispersion parameter in the same way as the standard #' deviation in the normal distribution: it can take any positive value. #' #' \code{skew} is a skewness parameter: it can take any value in \eqn{(-1,1)}. #' The distribution is right-skewed, symmetric and left-skewed when \code{skew} #' is negative, null or positive respectively. #' #' \code{tail} is a tail parameter (often named the characteristic exponent): #' it can take any value in \eqn{(0,2)} (with \code{tail=1} and \code{tail=2} #' yielding the Cauchy and the normal distributions respectively when symmetry #' holds). #' #' The simplest empirical formula found to give a satisfactory approximation to #' the mode for values of \code{tail} in \eqn{(1,2)} is \deqn{ #' loc+disp*a*skew*exp(-b*abs(skew))} with \deqn{ a = #' 1.7665114+1.8417675*tail-2.2954390*tail^2+0.4666749*tail^3} and \deqn{ b = #' -0.003142967+632.4715*tail*exp(-7.106035*tail)}. #' #' #' @param loc vector of (real) location parameters. #' @param disp vector of (positive) dispersion parameters. #' @param skew vector of skewness parameters (in [-1,1]). #' @param tail vector of parameters (in [1,2]) related to the tail thickness. #' @return A list of size 3 giving the mode, \eqn{a} and \eqn{b}. #' @author Philippe Lambert (Catholic University of Louvain, Belgium, #' \email{phlambert@@stat.ucl.ac.be}) and Jim Lindsey. #' @seealso \code{stable} for more details on the stable #' distribution. #' #' \code{stablereg} to fit generalized linear models for the #' stable distribution parameters. #' @references Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns #' using regression models based on non-symmetric stable distributions. Applied #' Statistics, 48, 409-424. #' @keywords distribution #' @examples #' #' x <- seq(-5,5,by=0.1) #' plot(x,dstable(x,loc=0,disp=1,skew=-1,tail=1.5),type="l",ylab="f(x)") #' xhat <- stable.mode(loc=0,disp=1,skew=-1,tail=1.5)$ytilde #' fxhat <- dstable(xhat,loc=0,disp=1,skew=-1,tail=1.5) #' lines(c(xhat,xhat),c(0,fxhat),lty="dotted") #' #' @export stable.mode stable.mode <- function(loc, disp, skew, tail){ if(any(tail<1)) warning("stable.mode is only reliable for tail in (1,2)") coef1 <- 1.7665114+1.8417675*tail-2.2954390*tail^2+0.4666749*tail^3 coef2 <- -0.003142967+632.4715*exp(-7.106035*tail)*tail list(ytilde=loc+disp*coef1*exp(-coef2*abs(skew))*skew, c1=coef1,c2=coef2)} stable/R/pm1_to_pm0_and_pm0_to_pm1.R0000644000176200001440000000504214203221240016667 0ustar liggesusers#' Easy conversion of parameters between stabledist Nolan 1-parameterization and 0-parameterization #' #' \code{pm0_to_pm1} has stabledist parameter inputs for pm=0 and returns pm=1 equivalent parameterization. #' \code{pm1_to_pm0} has stabledist parameter inputs for pm=1 and returns pm=0 equivalent parameterization. #' #' See table Table 3.1 on page 97 of Nolan (2020). #' #' @name Parameter_Conversion_Nolan_pm1_pm0 #' @aliases pm1_to_pm0 pm0_to_pm1 #' @param a0 the stabledist 'alpha' for pm=0 in 'stabledist' #' @param b0 the stabledist 'beta' for pm=0 in 'stabledist' #' @param c0 the stabledist 'gamma' for pm=0 in 'stabledist' #' @param d0 the stabledist 'delta' for pm=0 in 'stabledist' #' @param a1 the stabledist 'alpha' for pm=1 in 'stabledist' #' @param b1 the stabledist 'beta' for pm=1 in 'stabledist' #' @param c1 the stabledist 'gamma' for pm=1 in 'stabledist' #' @param d1 the stabledist 'delta' for pm=1 in 'stabledist' #' #' @references Nolan, John P. Univariate stable distributions. Berlin/Heidelberg, Germany: Springer, 2020. #' #' @return #' \code{pm0_to_pm1} has stabledist parameter inputs for pm=0 and returns pm=1 equivalent parameterization. #' \code{pm1_to_pm0} has stabledist parameter inputs for pm=1 and returns pm=0 equivalent parameterization. #' @export #' @examples #' \dontrun{q <- -1 #' # nolan pm=1 parameters: #' a1 <- 1.3 #' b1 <- -0.4 #' c1 <- 2 #' d1 <- 0.75 #' # Convert to nolan pm=0 parameters: #' pm0 <- pm1_to_pm0(a1,b1,c1,d1) #' a0 <- pm0$a0 #' b0 <- pm0$b0 #' c0 <- pm0$c0 #' d0 <- pm0$d0 #' # check: #' stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #' #> [1] 0.1965513 #' # only change delta=d0 for pm=0 #' stabledist::pstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) #' stabledist::pstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #' #> [1] 0.1965513 #' stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d1, pm=1) #' #> [1] 0.0572133 #' # only change delta=d0 for pm=0 #' stabledist::dstable(q, alpha=a1, beta=b1 , gamma=c1 , delta=d0, pm=0) #' stabledist::dstable(q, alpha=a0, beta=b0 , gamma=c0 , delta=d0, pm=0) #' #> [1] 0.0572133} pm0_to_pm1 <- function(a0, b0, c0, d0){ if(a0!=1){ a1 <- a1 b1 <- b1 c1 <- c1 d1 <- d0 - b1*c1*tan(pi*a1/2) } return(list(a1=a1, b1=b1, c1=c1, d1=d1 )) } #' @rdname Parameter_Conversion_Nolan_pm1_pm0 #' @export pm1_to_pm0 pm1_to_pm0 <- function(a1, b1, c1, d1){ if(a1!=1){ a0 <- a1 b0 <- b1 c0 <- c1 d0 <- d1 + b1*c1*tan(pi*a1/2) } return(list(a0=a0, b0=b0, c0=c0, d0=d0)) } stable/R/stable-package.R0000644000176200001440000001156213426072307014724 0ustar liggesusers#' Stable Distribution #' #' These functions provide information about the stable distribution with the #' location, the dispersion, the skewness and the tail thickness respectively #' modelled by the parameters \code{loc}, \code{disp}, \code{skew} and #' \code{tail}. #' #' \code{dstable}, \code{pstable}, \code{qstable} and \code{hstable} compute #' the density, the distribution, the quantile and the hazard functions of a #' stable variate. \code{rstable} generates random deviates with the prescribed #' stable distribution. #' #' \code{loc} is a location parameter in the same way as the mean in the normal #' distribution: it can take any real value. #' #' \code{disp} is a dispersion parameter in the same way as the standard #' deviation in the normal distribution: it can take any positive value. #' #' \code{skew} is a skewness parameter: it can take any value in \eqn{(-1,1)}. #' The distribution is right-skewed, symmetric and left-skewed when \code{skew} #' is negative, null or positive respectively. #' #' \code{tail} is a tail parameter (often named the characteristic exponent): #' it can take any value in \eqn{(0,2)} (with \code{tail=1} and \code{tail=2} #' yielding the Cauchy and the normal distributions respectively when symmetry #' holds). #' #' If \code{loc}, \code{disp}, \code{skew}, or \code{tail} are not specified #' they assume the default values of \eqn{0}, \eqn{1/sqrt(2)}, \eqn{0} and #' \eqn{2} respectively. This corresponds to a normal variate with mean\eqn{=0} #' and variance\eqn{=1/2 disp^2}. #' #' The stable characteristic function is given by \deqn{greekphi(t) = i loca t #' - disp {|t|}^{tail} [1+i skew sign(t) greekomega(t,tail)]}{phi(t) = i loc t #' - disp |t|^tail [1+i skew sign(t) omega(t,tail)]} where #' \deqn{greekomega(t,tail) = \frac{2}{\pi} LOG(ABS(t))}{omega(t,tail) = (2/pi) #' log|t|} when \code{tail=1}, and \deqn{greekomega(t,tail) = tan(\frac{\pi #' tail}{2})}{omega(t,tail) = tan(pi alpha / 2)} otherwise. #' #' The characteristic function is inverted using Fourier's transform to obtain #' the corresponding stable density. This inversion requires the numerical #' evaluation of an integral from \eqn{0} to \eqn{\infty}{infinity}. Two #' algorithms are proposed for this. The default is Romberg's method #' (\code{integration}="Romberg") which is used to evaluate the integral with #' an error bounded by \code{eps}. The alternative method is Simpson's #' integration (\code{integration}="Simpson"): it approximates the integral #' from \eqn{0} to \eqn{\infty}{infinity} by an integral from \eqn{0} to #' \code{up} with \code{npt} points subdividing \eqn{(O, up)}. These three #' extra arguments -- \code{integration}, \code{up} and \code{npt} -- are only #' available when using \code{dstable}. The other functions are all based on #' Romberg's algorithm. #' #' #' @aliases dstable pstable qstable hstable rstable #' @param y,q vector of quantiles. #' @param p vector of probabilites. #' @param n number of observations. #' @param loc vector of (real) location parameters. #' @param disp vector of (positive) dispersion parameters. #' @param skew vector of skewness parameters (in [-1,1]). #' @param tail vector of parameters (in [0,2]) related to the tail thickness. #' @param eps scalar giving the required precision in computation. #' @author Philippe Lambert (Catholic University of Louvain, Belgium, #' \email{phlambert@@stat.ucl.ac.be}) and Jim Lindsey. #' @seealso \code{stablereg} to fit generalized nonlinear #' regression models for the stable distribution parameters. #' #' \code{stable.mode} to compute the mode of a stable #' distribution. #' @references Lambert, P. and Lindsey, J.K. (1999) Analysing financial returns #' using regression models based on non-symmetric stable distributions. Applied #' Statistics, 48, 409-424. #' @keywords distribution #' @examples #' #' par(mfrow=c(2,2)) #' x <- seq(-5,5,by=0.1) #' #' # Influence of loc (location) #' plot(x,dstable(x,loc=-2,disp=1/sqrt(2),skew=-0.8,tail=1.5), #' type="l",ylab="",main="Varying LOCation") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5)) #' lines(x,dstable(x,loc=2,disp=1/sqrt(2),skew=-0.8,tail=1.5)) #' #' # Influence of disp (dispersion) #' plot(x,dstable(x,loc=0,disp=0.5,skew=0,tail=1.5), #' type="l",ylab="",main="Varying DISPersion") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=0.9,skew=0,tail=1.5)) #' #' # Influence of skew (skewness) #' plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=-0.8,tail=1.5), #' type="l",ylab="",main="Varying SKEWness") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0.8,tail=1.5)) #' #' # Influence of tail (tail) #' plot(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=0.8), #' type="l",ylab="",main="Varying TAIL thickness") #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=1.5)) #' lines(x,dstable(x,loc=0,disp=1/sqrt(2),skew=0,tail=2)) #' stable/NEWS.md0000644000176200001440000014763714207464305012651 0ustar liggesusers#------------------------------------------------------------------------------ #version 1.1.6 #------------------------------------------------------------------------------ * refined the previous version's references to contemporary stable distribution literature to help contextualize this package in the /man files and README * add example to bottom of README #------------------------------------------------------------------------------ #version 1.1.5 #------------------------------------------------------------------------------ * http: --> https: where appropriate * added references to contemporary stable distribution literature to help contextualize this package to /man files and README * Removed imports: stabledist from DESCRIPTION #------------------------------------------------------------------------------ #version 1.1.4 #------------------------------------------------------------------------------ * FIXED NOTE: All declared Imports should be used. #------------------------------------------------------------------------------ #version 1.1.3 #------------------------------------------------------------------------------ * Added functions `sd2s()`, `s2sd()`, `pm1_to_pm0`, `pm0_to_pm1` to help with switching between parameterizations * Updated README to detail how to use `sd2s()`, `s2sd()`, `pm1_to_pm0`, `pm0_to_pm1` * Updated README to detail how to locate modes with `stable` and `stabledist` equivalently * FIXED NOTE: Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’. #------------------------------------------------------------------------------ #version 1.1.2 #------------------------------------------------------------------------------ * Updated README to detail how to make `d/p/q/r stable()` calls from `stable` the same as `stabledist` * Fixed memtest / Valgrind error. #------------------------------------------------------------------------------ #version 1.1.1 #------------------------------------------------------------------------------ * Fixed ASAN / UBSAN error. #------------------------------------------------------------------------------ #version 1.1.0 #------------------------------------------------------------------------------ ## Major changes ## Passed CRAN checks and is back on CRAN. Please see github page https://github.com/swihart/stable to see the changes required to pass CRAN checks. I'll try to document the changes henceforth here and at https://github.com/swihart/stable/issues. * loc.g, loc.h, disp.g, disp.h, skew.g, skew.h, tail.g, tail.h are now replaced with loc_g, loc_h, disp_g, disp_h, skew_g, skew_h, tail_g, tail_h respectively. **Above this line will be News/Changes for `stable` only** **Below this line corresponds to [changes.txt](https://www.commanster.eu/rcode/changes.txt), which was Jim Lindsey's file for detailing changes across the v1.0 packages `rmutil`, `repeated`, `gnlm`, `growth`, `event`, `stable` on his homepage** #------------------------------------------------------------------------------ #version 1.0 #------------------------------------------------------------------------------ 30.11.10 (growth) * elliptic: twins option added for model using covfn with covariance matrix diagonal constant 28.11.10 * elliptic: added an error check when covfn used 15.2.10 (rmutil) * changed s<0 to s<=0 in qlaplace & rlaplace (thanks to Peter Ehlers) 18.11.09 (repeated) * removed a redundant line in gausscop.r that now produced an error (thanks to Patrick Lindsey) 7.4.09 * removed extra } in biv.binom.Rd (thanks to Christopher Marcum) 20.10.08 * discrete q functions: changed trunc to round (thanks to Frederic Gosselin) 3.7.08 (gnlm) * fit.dist: corrected check for negative values with Laplace, Cauchy, and Student t plus error in counts (f -> ni) for Laplace (thanks to Michael Anyadike-Danes) 24.10.07 * fnenvir: changed way "=" is handled in gsub() because of error since R2.5.0 8.10.07 (event, gnlm, growth, repeated) * changed typsiz to typsize in nlm() throughout 11.7.07 * romberg.c: added missing R.h (thanks to Olivia Lau) 8.2.07 * print out name of response variable in elliptic, bnlr, gnlr, gnlr3, gnlmm, gnlmm3, and fmr (thanks to Patrick Lindsey) * qsimplex: corrected search interval updates 27.9.06 * qhjorth, qinvgauss, qginvgauss, qboxcox: changed lower limit of search from 0.001 to .Machine$double.xmin (thanks to Franco Mendolia) 8.12.05 (rmutil, repeated, event) * minor modifications to Fortran for F95 compatibility (thanks to Jan de Leeuw) 22.11.05 * finterp, objectrm: added na.action=NULL in calls to model.frame (default is na.omit !!!!!) (thanks to Patrick Lindsey) 30.9.05 * elliptic: corrected calculation of number of parameters for builtin logistic function (thanks to Tom Van Dooren) 1.8.05 * qbetabinom: changed trunc() to round() (thanks to Elias Krainski) * mprofile, iprofile: added check that times are available (thanks to Patrick Lindsey) 6.7.05 * ksurvb, ksurvg, kcountb: added break; after default: in C code to satisfy some compilers (thanks to Patrick Lindsey) 30.6.05 * finterp: correction for change in functioning of match() * gnlm family: added coef.gnlm() and vcov.gnlm() (thanks to Bendix Carstensen) 25.4.05 (stable) * rstable: eliminate production of NAs (thanks to Zhu Wang) 26.1.05 * finterp: fixed a bug when >= or <= is used in a formula (thanks to Eliot McIntire) 1.11.04 * gnlmm3: generalized nonlinear mixed models for three-parameter distributions 28.9.04 * catmiss: removed codes() from example in help (thanks to Kjetil Brinchmann) 21.9.04 * finterp: fixed if test to remove occasional warning (thanks to Ken Knoblauch) 17.9.04 * gnlmix: removed erroneous printing that distribution is censored for binomial (thanks to Ken Knoblauch) 28.7.04 * gnlmix, hnlmix: fixed printing of results when nonlinear function contains a linear part (thanks to Ken Knoblauch) 2.7.04 * tvctomat: fixed warning message on removing tm (thanks to Patrick Lindsey) 1.6.04 * glmm: changed print.summary.glmm to work under R1.9 (thanks to Spencer Graves) 5.4.04 * fnenvir: fixed obscure error when linear used in a function (thanks to Ken Knoblauch) * help: corrected truncation of usage formula for certain functions (thanks to Patrick Lindsey) 9.1.04 * fitdist: fixed typo that stopped geometric distribution from working 6.1.04 * ordglm: changed tapply to capply because of change to former (thanks to Andrew Criswell) 9.12.03 * corgram: start abscissa at 0 for PACF * fnenvir: fixed grep for checking redundant parameters * bnlr, fmr, gnlmm, gnlr, gnlr3, int, nlr, nordr, read.list, stable.mode: fixed if() on vector 14.11.03 * readdna, survkit, glmm, gnlmm, objectrm, readrm: removed obsolete codes() function (thanks to Ken Knoblauch) * carma: give error when ccov=~1 used (thanks to Patrick Lindsey) 21.8.03 * elliptic: corrected print function when the dispersion function depends on the location function (thanks to Gabrielle Kelly) 31.7.03 * hnlmix: corrected options for dnbinom (thanks to Jagat Sheth) 30.6.03 * dftorep: corrected check for ordered times to allow for two levels of nesting 25.5.03 * ordglm: added a data argument (thanks to Kosuke Imai) 13.5.03 * ordglm: corrected order of printing of standard errors (thanks to Kosuke Imai) 25.4.03 * gnlr, gnlr3, gnlmm, fmr, nordr: changed test for environment because the value returned by parent.frame() has a class in R1.7 22.4.03 * cphidden: a function to locate a changepoint in continuous time using a two-state hidden Markov model 9.4.03 * biv.binom: corrected degrees of freedom printed (thanks to Goran Brostrom) 12.2.03 * restovec: fixed handling of delta when the response is a list 16.1.03 * kalsurv: fixed typo in print.kalsurv (thanks to Anthony Gichangi) 4.12.02 * int: changed eps 2.12.02 * fit.dist: added Laplace distribution 1.12.02 * glmm: added error message if (codes of) nesting variable not consecutively numbered (thanks to Renaud Lancelot) 27.11.02 * fit.dist: changed Weibull parametrisation so that mu refers to y and not to y^alpha 22.11.02 * fit.dist: added Cauchy and Student t distributions use (log) density functions instead of writing formulae 18.11.02 * fit.dist: added beta-binomial distribution 16.11.02 * fit.dist: corrected error in calculation of log likelihood when censor=T 14.11.02 * fit.dist: corrected error in calculation of fitted values for zeta distribution 31.10.02 * int2: added default limits (thanks to Patrick Lindsey) 8.9.02 (repeated) * gar: corrected recursive fitted values when binomial (thanks to Patrick Lindsey) 4.9.02 * gausscop: exponential distribution now works (thanks to Patrick Lindsey) 30.8.02 * restovec: modified checks for nesting in lists and allow nesting to be supplied separately when a list is given (thanks to Patrick Lindsey) * gausscop: for positive-valued distributions, returned predicted values without transforming by log link function (thanks to Patrick Lindsey) 18.7.02 * ehr: addition checks of data supplied to this suite of functions * rs3: fixed typo * marg.hom: added checks on data 16.7.02 * chidden.r, hidden.r: corrected negative binomial check so that 0 responses are allowed (thanks to Ben Cooper) 10.7.02 * modified man pages for changed arguments to rgamma function * rmutil: created dist.h file 11.6.02 * hnlmix: corrected AIC for penalty constraint (was too large by one) changed calculation of multiplicative random effects 23.5.02 * rmutil: added [pdqr]twosidedpower distribution added log option to all density (d) functions * gar, gnlr, gnlmix, gnlmm, hnlmix: added two-sided power distribution * gnlr: user-supplied likelihood function works again (thanks to Martin Liermann) * finterp, fnenvir: added option to allow any response to be a covariate 9.5.02 * hnlmix: recursive fitted values available * ordglm: fixed error that PearsRes not defined when individual data are supplied (thanks to Kamal Desai) 6.5.02 * gnlmix, hnlmix: added inverse gamma mixture distribution * gnlmix: handles censored data * gnlmm: finds nesting variable when repeated environment is specified 5.5.02 * finterp: modified so that as.factor(times) works 30.4.02 * hnlmix: nonlinear random effects models using a modified Lee and Nelder h-likelihood * gnlr: modified check on location parameters for Levy distribution added check that double Poisson, multiplicative Poisson, gamma count, and logarithmic data are not censored #------------------------------------------------------------------------------ #version 0.9 #------------------------------------------------------------------------------ 28.4.02 * gnlmix: corrected typo in negative binomial distribution 23.4.02 * carma, chidden, elliptic, hidden, kalseries: give error if censored data supplied (thanks to Troels Ring) 22.4.02 * elliptic: when two levels of nesting, calculate correctly first recursive fitted value in each cluster (was plotted correctly using iprofile) plus corresponding simplification of plot.iprofile (thanks to Troels Ring) 17.4.02 (all packages) * gnlmix: corrected typo in inverse Gauss mixing distribution * print model methods: added option not to print correlations 15.3.02 * restovec, tcctomat, tvctomat: added optional description slot to response, tccov, and tvcov objects 13.3.02 * glmm: convert repeated object to dataframe if supplied as data tcctomat, tvctomat: corrected to detect contrast options when dataframe=F 12.3.02 * tvctomat: corrected problem for list of factors when dataframe=F (thanks to Patrick Lindsey) * finterp.default: give error if members of dataframe named using $ (thanks to Christof Bigler) 28.2.02 * chidden, hidden: added check for correct number of initial estimates when list of functions supplied (thanks to Patrick Lindsey) 22.2.02 * corgram: added option for PACF 19.2.02 * fmr: modified some discrete distributions to avoid overflow with large counts 17.2.02 * elliptic: added as.double for y in call to C code because of change in read.table 12.2.02 * finterp: give error if offset used in W&R formula 31.1.02 * %^%: power of a matrix * elliptic: corrected problem when common parameters in mean and variance functions 20.1.02 * plot.repeated: added selection of profiles to be plotted by using ccov 14.1.02 * gar: added absolute value arch (names of others changed: additive -> square, multiplicative -> exponential) * volatility method for extracting values of nonconstant dispersion parameter * Makefiles: removed . for SHLIB_EXT for R1.4.0 * dist.c, kcountb.c, romberg.c, stable.c: changed malloc to R_alloc 10.1.02 * (dhpqr)ggamma, fmr, gausscop, gnlmix, gnlmm, gnlr, gnlr3, hgamma: changed argument of (dpqr)gamma for compatibility with R1.4.0 modified help to work with R1.4.0 18.12.01 * contr.mean: provides correct labels on mean constraints (corrects contr.sum) 4.12.01 * chidden, hidden: corrected printing out family parameter with AR when there is not one 28.11.01 * qstable: corrected bug when tail<1 and skew=1 (thanks to Alec Stephenson) 23.11.01 * corgram: handles NAs in the series 19.11.01 * cprocess: fixed error in checking for list of events (thanks to Troels Ring) * stablereg: changed alpha to allow parameter to be (0,2) instead of (1,2) 18.11.01 * chidden: added time-discretized Poisson process 17.11.01 * chidden, hidden: added Student t distribution changed Cauchy shape parameter to scale instead of scale^2 15.11.01 * gar: added Student t distribution added ARCH models * elliptic: when AR, take log of determinant returned by dpodi (thanks to Gabrielle Kelly) 13.11.01 * elliptic: when series of independent observations, calculate covariance determinant as sum of log variances instead of log of product (thanks to Gabrielle Kelly) 8.11.01 * cmcre: corrected problems when a covariate is used (thanks to Anthony Gichangi) 6.11.01 * print.response: do not print mean if nominal (but not binary) or ordinal (thanks to Patrick Lindsey) 25.10.01 * hidden.r: corrected check for fixed zeros in transition matrix * relaxed check for rows of transition matrix summing to one * chidden.r: relaxed check for rows of transition matrix summing to zero (all thanks to Patrick Lindsey) 24.10.01 * restovec: weights can be logical 14.10.01 * gar: fixed output printing when shape is a function of location parameter use dnbinom function * changed negative binomial shape parameter to be same as in gnlr 10.10.01 * carma, chidden, gar, hidden, kalcount, kalseries: check for two levels of nesting when serial dependence fitted 9.10.01 * kalseries: corrected error when torder used with tvcov 8.10.01 * hidden, chidden: added observed AR(1) * gnlr, gnlmm, gnlmix: changed parametrization of the shape parameter for the beta distribution (thanks to Goran Arnoldsson) * binnest: duplicate variables in Fortran call * model functions using envir: check that response specified is one in envir when only one present 3.10.01 * plevy, qlevy: use pnorm and qnorm instead of integrating 26.9.01 * elliptic: added second form of asymmetric multivariate Laplace distribution with constant asymmetry parameter 25.9.01 * elliptic: added asymmetric multivariate Laplace distribution 24.9.01 * carma.r: removed unnecessary check that envir is a repeated object (thanks to Troels Ring) 11.9.01 * fit.dist: added checks that grouped frequency data are supplied 10.9.01 * kalsurv: corrected output errors when environment is supplied * gar: use log option in dbinom, dpois * kalcount: set first recursive prediction in series to marginal prediction 6.9.01 gar: added loglog link for binomial data (corrected cloglog which was, in fact, loglog) 20.8.01 * gnlmix: set undefined sh3 to NULL for one parameter distributions 1.8.01 * chidden, gar, gnlr3, hidden: added skew Laplace distribution 27.7.01 * corgram: improved presentation of correlogram 25.7.01 * d,h,p,q,rskewlaplace: probability functions for the skew Laplace distribution 24.7.01 * autointensity.r: plots autointensity function of a point process 12.7.01 * plot.repeated: fixed error of unknown type when plotted time-varying covariate (thanks to Patrick Lindsey) * carma: clearer error message when incorrect environment supplied 10.7.01 * carma: will handle data objects with (one of) multivariate responses * chidden, hidden: handle Jacobian correctly with (one of) multivariate responses 6.7.01 * cprocess.r: recognizes data objects for events and not just for times 5.7.01 * f2c.h included in library for toms614.c (missing in R1.3.0) 27.6.01 * iprofile, mprofile: corrected links to other libraries for html help * plot.cum.pergram: corrected confidence interval * pergram: changed calculation of length for odd-lengthed series 22.6.01 * gar.r: check that times are supplied and, if not, create if possible 19.6.01 * fmr.r, gnlmm.r, gnlr.r, gnlr3.r: linear can be ~1 if mu not supplied 14.6.01 * marg.hom.r: modified to handle factor variables with non-numeric levels 8.6.01 * ordglm.r: corrected fitted values when weighted observations (thanks to Troels Ring) 31.5.01 * elliptic: changed check on initial variance function estimates 16.5.01 * print.response, print.tvcov, print.repeated: added option to print range of numbers of observations per individual instead of vector of numbers (thanks to Markus Jantti) * dmultpois, etc: added additional check on dependence parameter 9.5.01 * gar.r: corrected printout for generalized gamma parameter 26.4.01 * changed F and T to FALSE and TRUE throughout * read.rep: removed col.names option because of changes in read.table 22.4.01 * glmm: corrected typo when dataframe used with no offset 20.4.01 * finterp: detects functions when given as arguments of other functions 19.4.01 * finterp: formulae can be written on several lines, as several instructions (e.g. to assign temporary variables) 11.4.01 * dburr, pburr, qburr, hidden, chidden, gnlr3: changed parametrization of Burr distribution (thanks to Patrick Lindsey) 28.3.01 * chidden, hidden: corrected vector length problem in check for ordered intercepts in ordinal models (thanks to Niko Speybroeck) * several p and d functions: changed check to y>=0 (thanks to Patrick Lindsey) 22.3.01 * glmm: works again with weights and/or offset (thanks to Luc Duchateau) * gnlmix: changed to log dispersion for mixing distribution 21.3.01 * int.c: corrected memory allocation problem * GExtVal: changed man page to agree with functions (both thanks to Patrick Lindsey) 20.3.01 * use log option in d and p functions for h functions 14.3.01 * chidden, hidden: added further checks on ordering of intercepts for ordinal data 13.3.01 * gnlmix: changed dispersion parameter for normal mixing distribution from standard deviation to variance * delta: returns a vector instead of a matrix if only for one variable 11.3.01 * gnlmix: correction to work with unbalanced data 9.3.01 * gar, gnlr3: added power variance function Poisson distribution 8.3.01 * covariates: added expand option * dpvfpois, ppvfpois, qpvfpois, rpvfpois: functions for the overdispersed power variance function Poisson distribution * kalcount: corrected for power variance function 7.3.01 * plot.response: corrected indexing problem 1.3.01 * kalcount, kalseries, kalsurv: removed constraints on family parameter 27.2.01 * chidden, fmr, gar, gausscop, gnlmix, gnlmm, gnlr, gnlr3, hidden, kalseries, kalsurv, nlr: relaxed type checks for continuous and duration data 26.2.01 * kalcount, kalseries, kalsurv: added two-parameter power variance family mixture including gamma and inverse Gauss mixtures (family) for serial dependence 23.2.01 * response: if response is univariate, returns a vector instead of a matrix * covariates: if only one covariate requested, return as a vector * chidden, hidden: improved checks for ordered intercepts with ordinal response improved calculation of ordinal probabilities 22.2.01 * plot(iprofile()): works for models from kalsurv (thanks to Jacob Bowers) 19.2.01 * chidden.r, hidden.r: corrected error in calculating individual profiles when tvmu used (thanks to Jacob Bowers) * ordinal data can be used with multinomial option (thanks to Patrick Lindsey) * work with ordinal data with a list of different formulae (thanks to Niko Speybroeck) 31.1.01 * glmm.r: works if response is a one-column matrix instead of a vector (thanks to Luc Duchateau) * restovec: corrected manual so that arguments section appears (thanks to Patrick Lindsey) 30.1.01 * finterp, fnenvir: further correction to handle decimal numbers (including scientific notation) correctly * finterp: replaced gsub by all.vars 25.1.01 * name of response can be a character string when environment is supplied (thanks to Patrick Lindsey) * hidden, chidden: added description of pintercept to man page * delta: works properly when name is supplied * plot functions: use 6 different line types instead of 4 * gausscop: corrected mean for gamma margin check that only one initial estimate when no dispersion function 18.1.01 * transform.response: works when units is NULL * hidden, chidden: reversed order of categories for proportional odds and continuation ratio * replaced dqrcf with dqrsl * nordr: bug fix to work with data objects 8.1.01 * cutil.c, romberg.c, toms614.c: changed include for call_R (thanks to Dennis Murphy) 7.1.01 * model fitting functions check for correct type of response * dftorep, read.rep: modified to handle new "types" of responses * dftorep: now handles two column binomial response * ehr.r: rewrote to conform to other functions 4.1.01 * restovec: option to add responses to an old response object and types of responses returned in list instead of as a class * resptype: new method to return types of response variable(s) * finterp.repeated: check that binomial and censored responses are not used as covariates 21.12.00 * gar.r: corrected error in printing three-parameter distributions 19.12.00 * finterp, fnenvir: methods for dataframes * gnlm functions: environment can be a dataframe 18.12.00 * changed check for existence of response when environment supplied * bnlr, fmr, gnlmm, gnlr, gnlr3, nordr: fixed calculation of n for null function 17.12.00 * various changes because of new R1.2.0 handling of formulae * finterp: check for + or - before ( (change to R1.2.0) * elliptic: removed check on tvcov, so can accept times and individuals 15.12.00 * bnlr, fmr, gnlr, gnlr3, gnlmm, nordr: nonlinear formula need not contain covariates * changes to cutil.c and coxre for R1.2.0 14.12.00 * restovec, tcctomat, tvctomat: added slot for units of measurement * dftorep, read.rep: id can be a factor variable * carma, elliptic, gar, gausscop, kalcount, kalseries, kalsurv: test if name of response exists when envir contains multivariate responses * stable: corrected man pages 3.12.00 * gnlmix: generalized nonlinear models with one random parameter having arbitrary mixing distribution 30.11.00 * fitdist.r: calculate log probabilities and likelihoods to avoid underflow (thanks to Goran Brostrom) * int2: vectorized two-dimensional Romberg integration 28.11.00 * added d, p, q, and r functions for Consul generalized Poisson distribution * added PACKAGE option to .C and .Fortran calls * bnlr.r: added cloglog and loglog links * changed class of gnlr-type functions from gnlr to gnlm * gar.c: corrected calculation of censored Burr, Pareto, power exponential distributions (thanks to Patrick Lindsey) 24.11.00 * q and r functions: improved calculations and checks 23.11.00 * bnlr, fmr, gnlmm, gnlr, gnlr3, nordr: nonlinear formulae can have a linear part * qgweibull, qggamma, qgextval: corrected arguments to functions and docs (thanks to Patrick Lindsey) 21.11.00 * fmobj: find objects referred to in a formula * elliptic.r, fmr.r, gar.r, gausscop.r, gnlmm.r, gnlr.r, gnlr3.r: models with common parameters in several regression functions can be specified using formulae, not just functions * elliptic.r, gar.r, gausscop.r, gnlmm.r, gnlr.r: models with shape as a function of location can be specified using formulae, not just functions 20.11.00 * finterp.r: formulae can have common parameters and/or depend on functions 16.11.00 * hidden, chidden: added recursive predicted values * added q and r functions for distributions in rmutil 14.11.00 * kalseries: corrected error in inverse Gaussian distribution (thanks to Patrick Lindsey) * bnlr.r: added stable and mixture links * gnlr, gnlmm, gar: added beta and simplex distributions * rmutil: added psimplex and dsimplex 9.11.00 * improved checking for multivariate response and choosing one response when several present in a data object 6.11.00 * fmr.r, printrm.r: corrected so that works with common parameters (thanks to Laura Thompson) 29.10.00 * gnlr3.r: corrected typo in normal and inverse Gauss distributions 19.10.00 * gausscop: multivariate Gaussian copula with arbitrary marginals * elliptic.r: several typing errors corrected #------------------------------------------------------------------------------ #version 0.8 #------------------------------------------------------------------------------ 17.10.00 * carma, elliptic, kalseries: handles NULL delta correctly with multivariate response in repeated object * restovec: gives names correctly to multivariate 3-dim array * covariates.repeated: calculates number of observations correctly when multivariate response 15.10.00 * qstable: corrected bug due to change in uniroot (thanks to Gabrielle Kelly) * dstable, pstable, qstable, rstable: added checks that parameter values are correct 13.9.00 (growth, repeated, rmutil) * restovec: check for NAs in ordinal responses (thanks to Patrick Lindsey) * elliptic, kalseries: check that torder is not larger than number of time points (thanks to Patrick Lindsey) * elliptic: corrected undefined n (thanks to Patrick Lindsey) 12.9.00 * kalseries: constant shape parameter for (log) logistic, Cauchy, and Laplace distributions previously had square root transform * kalseries: added inverse Gauss distribution 7.9.00 * restovec: corrected error (change in R) when censor is all ones (thanks to Troels Ring) 17.8.00 * removed provide() * rmutil: removed det() 14.8.00 * rmna: corrected typo in man page 17.7.00 * nordr.r: corrected minor bugs for weights and data object handling (thanks to Patrick Lindsey) 5.7.00 * as.data.frame.x: added options from default (thanks to Patrick Lindsey) * rmna: removes NAs in weights (thanks to Patrick Lindsey) * restovec: handle correctly option, times=T (thanks to Patrick Lindsey) * covariates.repeated: handle correctly non-repeated observations (thanks to Patrick Lindsey) 21.6.00 * plotrm.r: plot.residuals corrected so ccov works (thanks to Patrick Lindsey) 14.6.00 * carma.r: correction for ccov as one-column matrix (thanks to Patrick Lindsey) 7.6.00 * elliptic.f: fixed crash with more than one covariate in tvcov (thanks to Bruno Genicot) 1.6.00 * elliptic.r: corrected check to allow varfn="identity" or "square" 30.5.00 * bnlr.r: binomial regression with various links 22.5.00 * fnenvir.r: can handle functions without parameters (thanks to Troels Ring) 11.5.00 * fit.dist: corrected exact fit for negative binomial and added default options for main and xlab 6.4.00 * runge.kutta, lin.diff.eqn: functions to solve differential equations 5.4.00 * gar.r: handles censored data correctly when a data object contains more than one response 29.3.00 * runge.kutta.r: solution of differential equations 20.3.00 * nlr: corrected undefined mu1 17.3.00 * print.response: check for NAs in times 15.3.00 * glmm: obtain nest vector from dataframe if supplied 14.3.00 * nordr, ordglm: clearer error message if the response is not a numeric vector with integral values starting at 0 (thanks to Troels Ring) 15.2.00 * ordglm: corrected bug when more than three categories 12.2.00 (repeated, event) * kalcount, kalseries, kalsurv: autoregression with frailty dependence 9.2.00 * kcountb.c, kserieb.c, ksurvb.c, ksurvg.c: changed -log(1-pfn()) to -pfn(,,,0,1) and removed inthaz.c 8.2.00 * all libraries: corrected C code for R0.99 * kalcount: corrected error in recursive predicted values for gamma intensity 1.2.00 * restovec: corrected handling of weights when response is a list * kalsurv.r: corrected plotting of profiles for logged distributions * cutil.c: changed Fortran.h to Rconfig.h and moved to rmutil * cgamma.c: replaced by cutil.c * inthaz.c: changed finite() to R_FINITE() 27.1.00 * gar: three-parameter distributions work with constant dispersion parameter * kalcount, kalseries, kalsurv: if mu contains time-varying covariates, * initial estimates must be in ptvc 24.1.00 * finterp, fnenvir: changed name of .fn to avoid conflicts * most model functions: check that supplied function was not produced by finterp already 20.1.00 * as.data.frame: puts binomial and censored responses as two-column matrices * gnlr, fmr, gnlmm, gar: binary response need only be one column for binomial 17.1.00 * finterp, fnenvir: handle decimal numbers correctly * most model functions: print out regression function correctly when envir supplied 16.1.00 * gar: added Consul generalized Poisson distribution * transform: check for nonpositive and infinite values in Jacobian * carma, elliptic, gar, kalseries: sqrt transformation checks for zero response values 14.1.00 * most model functions: check for NAs in data objects (because of lvna) * gnlr, gnlr3, fmr, gnlmm: possible to fit a model without optimizing any parameters in the regressions if they are functions * restovec, dftorep, read.rep: add additional validity checks for responses * times.default: replaces times.repeated 11.1.00 * hidden, chidden: handle multinomial count data * nlr: modified to handle data objects correctly * most model functions: changed way of detecting multivariate responses * finterp: correct error for length of response when multivariate 10.1.00 * gettvc: works correctly for first observation when ties=FALSE (thanks to Patrick Lindsey) * finterp: can find response variables of formula in repeated objects * for most model functions, one of multiple responses in a repeated data object can be selected for the model 9.1.00 * restovec: handles multivariate matrices, arrays, and lists * dftorep: transform a dataframe to a repeated data object * read.rep: read a rectangular data set from a file and create a repeated data object directly 7.1.00 * logitord.f: reformatted to remove tabs for HP compilers (thanks to Osman Buyukisk) * restovec: responses can have more than one type class #------------------------------------------------------------------------------ #version 0.7 #------------------------------------------------------------------------------ 3.1.2000 * residuals.elliptic: corrected error in calculation of raw residuals 31.12.99 * objectrm.r: can select certain individuals with methods, covariates, delta, nesting, times, weights * transform: handles NAs in response correctly 28.12.99 * restovec: added name of response variable to list returned * objectrm.r: added as.data.frame and as.matrix methods for data objects * wr: works with my data objects * nordr: changed sign of coefficients for continuation ratio and adjacent categories models so comparable with proportional odds 27.12.99 * finterp: with W&R notation, design matrix no longer returned as attribute when ~1 and .envir supplied, returns a function yielding a vector of correct length 26.12.99 * fit.dist: corrected exact fit of negative binomial * gnlr, gnlr3, fmr, gnlmm: improved speed * nordr, ordglm: ordinal categories numbered from 0 instead of 1 * hidden, chidden: multinomial categories numbered from 0 instead of 1 handles ordinal models, thanks to Patrick Lindsey * gettvc: now handles NAs in response variable 25.12.99 * improved documentation for methods to access data objects and functions * int: call C instead of Fortran for TOMS614 23.12.99 * restovec: added additional checks that correct data are supplied (thanks to Troels Ring) * mprofile.carma: corrected bug when no covariates * carma: corrected bug when delta is a scalar * carma, elliptic: added checks for incorrect formulae 21.12.99 * hidden, chidden: improved printout and corrected error in checking number of parameters in lists of formulae 20.12.99 * lvna: creates a repeated object leaving NAs in * hidden, chidden: interactions between time-constant and time-varying covariates allowed 17.12.99 * hidden, chidden: improved printout 16.12.99 * tvctomat: handles lists of factor variables correctly * restovec: value returned has class of type of response as well as "response" added checks * hidden, chidden: can also use formulae if multinomial 12.12.99 * hidden, chidden: can use formulae if not multinomial 7.12.99 * cmcre: corrected memory leak 6.12.99 * cmcre: continuous-time two-state Markov process with random effects 5.12.99 * coxre: corrected several errors 1.12.99 * stable: fixed plot arguments in help examples 29.11.99 * finterp: fixed bug when multiple ('s or ^ before ( when detecting function names * nobs: use method instead of direct access in all functions provide default method * covind: provide default method 25.11.99 * collapse: changed name to capply because of conflict in nlme 23.11.99 * profile: changed to mprofile because of conflict in R0.90 22.11.99 * finterp: properly distinguishes unknown parameters from functions * finterp and fnenvir: when no variables found, changed stop to warning * nobs: corrected for independent observations when length is one 18.11.99 * stablereg: corrected bug when some parameters are not optimized check for NAs in the hessian 17.11.99 * plot.repeated, plot.response: added special call for ordinal responses corrected plot for independent observations (thanks to Patrick Lindsey) 14.11.99 * removed unneeded aliases in man pages * added aliases to plot.profile and plot.iprofile 11.11.99 * added check for Inf (as well as NAs) in hessian to all functions using nlm * kalseries.r: added error message if times not available for Markov dependence changed rep(1,n) to rep(1,nind) when mu function returns scalar * stable.r: moved call to C code into likelihood function for speed * int.r: limits can be specified as -Inf, Inf 4.11.99 * kalcount.r, kalseries.r, kalsurv.r: with time-varying covariates in a function or formula, initial estimates can be in preg or ptvc and changed length(resp$response$y) to n for speed 31.10.99 * gar.r: fixed undefined npt3 for autoregression parameter * finterp.r: fixed bug for : in W&R formulae * kalcount.r, kalseries.r, kalsurv.r: added error message when time-varying covariates 22.10.99 * covind: changed so that it works with carma, elliptic, gar, hidden, kalcount, kalseries, and kalsurv objects 18.10.99 * gar.r: corrected printing of parameter values for three-parameter distributions * gar.c: corrected calculation of lambda in three-parameter distributions 17.10.99 * gar.r: corrected fitted values (due to changes on 12.10.99) 14.10.99 * gar.r: corrected undefined variable, tm (due to changes on 12.10.99) 12.10.99 * stable: stablereg with nonlinear regression replaces stableglm * finterp, fnenvir: check for factor variables instead of not being a numerical or logical vector * gar: allow autoregression parameter to depend on covariates * dist.c, kcountb.c, kserieb.c, ksurvb.c, ksurvg,c, stable.c: added #include "Rconfig.h" 4.10.99 * ordglm.r: added deviance and corrected for zeros in table * nordr.r: corrected typo * potthoff.r: corrected erroneous calculation of standard errors (thanks to Tim Auton) 1.10.99 * finterp, fnenvir: fixed conflict of names by beginning all names with a dot (thanks to Patrick Lindsey) * elliptic.r: changed option and title from elliptic to power exponential 30.9.99 * ordglm.r: generalized linear ordinal regression #------------------------------------------------------------------------------ #version 0.6 #------------------------------------------------------------------------------ 21.9.99 * pkpd.r: changed mu2.1o1cfp to ensure ked>0 20.9.99 * resid.f: correction to work with MS-Windows 7.9.99 * binnest.r, survkit.r: changed NULLs for Fortran to work with R0.65 6.9.99 * ehr.r, kalsurv.r, fmr.r, gnlr.r, gnlr3.r, nlr.r, nordr.r, elliptic.r, gar.r, gnlmm.r, kalcount.r, kalseries.r: changed attributes to work with R0.65 * finterp, fnenvir: variables can be logical as well as numeric 3.9.99 * Makefiles: moved $(FLIBS) to end of line 14.8.99 * print.gnlr: corrected errors in printing fmr, gnlr3, and gnlmm output * fnenvir.tvcov: corrected error for undefined ex1a (-> ex2a) * Pareto, gnlmm, hstudent, kalcount, kalseries, pkpd, read.list, read.surv, tvctomat: corrected examples 18.7.99 * hidden.r, chidden.r: corrected one error message added printout of degrees of freedom 14.7.99 * binnest.f: modified comments to compile with standard Fortran (thanks to Martin Maechler) #------------------------------------------------------------------------------ #version 0.5 #------------------------------------------------------------------------------ 29.6.99 * plot.response: remove NAs when calculating default ylim 28.6.99 * gnlr.r, gnlr3.r, fmr.r, nordr.r, gnlmm.r: check if user gives a nonlinear formula in linear argument and correctly handle it 27.6.99 * finterp: corrected error message when non-numeric vector supplied * restovec: corrected printing of total times when negative times present * added transform methods for response, tccov, and tvcov objects 24.6.99 * gar.r: corrected error in printing shape functions 22.6.99 * binnest.f: modified to compile with g77 8.6.99 * binnest: binary random effects model with two levels of nesting 7.6.99 * restovec: added an additional check for nest variable in lists 6.6.99 * logitord.f: corrected bug in calculation of Hessian (and s.e.) 1.6.99 * elliptic: added multivariate Student t distribution 11.5.99 * finterp.r: functions allowed in W&R formulae * carma.r, elliptic.r, kalseries.r, kalcount.r, kalsurv.r: allow factor variables * finterp: can locate and use indices for individuals and nesting as factor covariates 10.5.99 * tcctomat.r, tvctomat.r: allow factor variables * finterp, fnenvir: changed to check for factor variables 6.5.99 * elliptic.r: allow variance to be a function of the mean function 4.5.99 * gar.c: changed normal distribution shape parameter from sd to variance 3.5.99 * profile and iprofile: fixed to plot correctly with nesting 1.5.99 * tcctomat, tvctomat: allow dataframes 28.4.99 * tvctomat: time-varying covariates can be factors * elliptic.r, gnlr.r, gnlr3.r, fmr.r, gnlmm.r, gar.r: location and shape functions can have common parameters 26.4.99 * restovec: weights allowed for lists * finterp, fnenvir: can find the times when envir is a repeated object * gar.r: allow shape to be a function of the location function 23.4.99 * gnlr.r, gnlr3.r, fmr.r, nordr.r, nlr.r, elliptic.r, gnlmm.r, gar.r, kalseries.r, kalcount.r, kalsurv.r, ehr.r: do not require envir if response has class, repeated * corrected bugs in restovec and plot.response (Lorenz Gygax) 22.4.99 * generalized plot.residuals * tvctomat: allow calculation of more than one interaction with time-constant covariates at a time * finterp and fnenvir: allow variables in environment to have same name as a function 21.4.99 * correction of 18.1.99 by Brian Ripley wrong: dist.c put back in gnlm 20.4.99 * ksurvb.c: corrected bug when time-varying covariates * elliptic.r: added option to ccov and tvcov to give covariate names when response has class, repeated * carma.r: added option to ccov to give covariate names when response has class, repeated 19.4.99 * changed plot.profile to profile and plot.iprofile to iprofile 18.4.99 * elliptic.r: added recursive predicted values when AR(1) and/or random effect 16.4.99 * gnlr.r, gnlr3.r, fmr.r, nordr.r, gnlmm.r, ehr.r: changed order of parameters when function with linear part 15.9.99 * ehr: corrected two errors when lambda function with linear part * nordr.r: n changed to nrows 13.4.99 * carma.r: corrected predicted values when response is transformed * gar.r, kalseries.r: changed handling of transformed responses #------------------------------------------------------------------------------ #version 0.4 #------------------------------------------------------------------------------ 12.4.99 * added dependency on rmutil to DESCRIPTION 11.4.99 * elliptic.f: corrected handling of dose for PKPD model when time-varying covariates are present 6.4.99 * elliptic.r, gnlmm.r, gar.r, kalseries.r, kalcount.r, kalsurv.r, ehr.r, nordr.r, nlr.r: modified to use fnenvir 5.4.99 * gnlr.r, gnlr3.r, fmr.r: modified to use fnenvir 4.4.99 * fnenvir: checks functions for covariates and parameters and modifies them to read from data objects 1.4.99 * elliptic.r: modified to use model formulae with unknowns * finterp.r: added data objects as environment * tvctomat, tcctomat: can combine two data objects 31.3.99 * gar.r: modified to use model formulae with unknowns 30.3.99 * rmna: check if a covariate only has one value after NA removal * fixed examples docs so that they work 29.3.99 * kalcount.r, kalsurv.r, ehr.r: modified to use model formulae with unknowns 28.3.99 * gnlmm.r, kalseries: modified to use model formulae with unknowns * restovec: added coordinates to response class for spatial data 26.3.99 * gnlr.r, gnlr3.r, fmr.r, nordr.r, nlr.r: modified to use model formulae with unknowns 24.3.99 * changed language check to inherits formula in all functions * added methods for extracting elements from data objects * finterp.r: transforms model formulae with unknowns into functions 22.3.99 * restovec: times no longer required for clustered data type attribute added * carma.r, elliptic.r, kalseries.r kalcount.r: check to see if times available 15.3.99 * rmaov.r: wrote documentation * pkpd.r : added two new models and corrected one other 13.3.99 * restovec: allow ties in times 23.2.99 * gar.c: corrected Laplace cdf and allowed negative values 11.2.99 * ehr: corrected for ties * kalsurv.r: prints out "birth process" when applicable instead of renewal process * logitord.r: removed DUP=F from Fortran call 8.2.99 * km.r: fixed bug in plot.dist.km when several groups are plotted (Gareth Ridall) 7.2.99 * improved handling of variable names in tcctomat, tvctomat, and functions calling them * rmaov.r: split-plot aov from Ralf Goertz 6.2.99 * glmm.r: accepts transformed data if dataframe supplied 5.2.99 * km.r: fixed bug for double lines with censored observations (Gareth Ridall) * ehr.r: modified handling of language 4.2.99 * km.r: added print.km to remove attributes * restovec: accepts all response data, not just repeated measurements * tvctomat: added calculation of interactions 2.2.99 * restovec: added adding several column matrices in lists with censoring * kalsurv.r: added delta option 1.2.99 * glmm.r: binary response with binomial handled correctly 30.1.99 * plot.iprofile.carma: corrected nind argument * restovec, carma, elliptic, kalcount, kalseries: added how to handle `times' for clustered data to docs 28.1.99 * bivbinom.r, marghom.r: minor corrections * rs.r: improved printout 26.1.99 * readrm.r: corrected lty specification in plot.response added option to plot points 24.1.99 * gnlr.r, gnlr3.r, fmr.r, gnlmm.r: y can have classes, response or repeated * added DUP=F to all .C and .Fortran calls * pbirth.r: binomial data distributions 22.1.99 * readrm.r: added ... for graphics options in plot.response and plot.repeated 21.1.99 * rmna: added checks that ccov and tvcov have correct class 19.1.99 * dist.c: changed static romberg to romberg2 and added static interp * carma.r, chidden.r, elliptic.r, gar.r, hidden.r, kalcount.r, kalseries.r, kalsurv.r: allow response to have class, repeated * restovec: allow delta to be a dataframe 18.1.99 * corrections by Brian Ripley * gnlm: removed redundant dist.c * enclosed library.dynam in .First.lib * potthoff.r: added matrix dimension checks * util.r: removed orth function * potthoff.r: replaced orth by contr.poly 17.1.99 * carma.r, chidden.r, elliptic.r, gar.r, hidden.r, kalcount.r, kalseries.r, kalsurv.r: copy response vector more efficiently * restovec: added total time for survival data * coxre.r: reorganized for efficiency, eliminating data.frame * cprocess.r: times can have class, response 16.1.99 * gnlr.r, gnlr3.r, fmr.r, gnlmm.r: removed -delta/2 in right censoring calculation * dist.r, gnlr3.r, gar.c, hidden.f: changed parametrization of Burr to agree with kalsurv.r * elliptic.r: use var(y) to get initial estimate of variance #------------------------------------------------------------------------------ #version 0.3 #------------------------------------------------------------------------------ 14.1.99 * kalsurv.r: corrected printing of number of subjects and observations 2.1.99 * cprocess.r: allow event counts with unequal times * added mode="double" to is.vector 29.12.98 * corrected minor bugs in fmr 28.12.98 * corrected abs bug for Laplace in kalman C functions 27.12.98 * restovec: corrected binary totals when given as a vector * gar: added Levy, Pareto, generalized inverse Gauss, and power exponential distributions * hidden and chidden: added various overdispersed and continuous distributions 22.12.98 * hidden and chidden: added filter calculation and plots 21.12.98 * moved Student t from gnlr to gnlr3 * renamed beta as Pareto in kalcount, kalseries, and kalsurv * corrected various minor errors in fmr and gnlr3 20.12.98 * dist.r, gnlr.r, fmr.r: added gamma count and Pareto distributions 18.12.98 * chidden: continuous-time hidden Markov chain models 7.12.98 * dist.r, gnlr.r, fmr.r: added Levy distribution * removed .so from Makefiles and library.dynam 6.12.98 * util.r: added spectral decomposition to mexp 5.12.98 * rmutil: added several p and d functions * gnlr3.r: added censored generalized inverse Gaussian and power exponential distributions 2.12.98 * int.r: vectorized Romberg integration 1.12.98 * int.r: added option for Romberg integration 30.11.98 * updated libraries with Brian Ripley's corrections 25.11.98 * hidden: allow values in the transition matrix to be fixed at 0 or 1 24.11.98 * hidden: added independence model 23.11.98 * inthaz.c: changed header include * bessel: removed function * gnlr3.r: changed to internal bessel function 14.11.98 * hidden: added multinomial distribution 12.11.98 * hidden.f: corrected Poisson and binomial calculations 5.11.98 * carmasub.f and survkit.f: changes for compatibility with g77 #------------------------------------------------------------------------------ #version 0.2 #------------------------------------------------------------------------------ 2.11.98 * ehr.r: corrected printing coefficients with linear and other parameters 1.11.98 * km.r: corrected NaNs in log 29.10.98 * carma.r: corrected printout of mean time * km.r: corrected ylab for cdf 26.10.98 * rmna: handles NAs in time-constant covariates properly * carma.r and elliptic.r: accept ccov of class, tccov * cprocess.r: added plots from counts of events 19.10.98 * changed to inherits() throughout * rationalized printing of gnlr, gnlr3, fmr, gnlmm and moved to rmutil * added delta option to carma and elliptic 18.10.98 * carma.r and elliptic.r: added handling of delta when y has class, response 17.10.98 * gar.r: added cloglog link 12.10.98 * gnlmm.r: corrected handling of delta when y has class, response 11.10.98 * replaced tapply() with collapse() in bivbinom, catmiss, glmm, gnlmm, ehr, coxre 10.10.98 * ehr.r check for singular covariance matrix print names of variables for coefficients when language 8.10.98 * kcountb.c: corrected dplogis call * gnlmm.r: corrected calls to ddp, dmp, ddb, and dmb * coxre.r: removed as.is=T in data.frame * corrected printing shape parameters when language used in gnlr, gnlr3, fmr, gnlmm 7.10.98 * rs.r: put in check that all covariates are positive * gnlmm.r: set censor to F for binomial data * dist.c: changed ddp, dmp, ddb, and dmb to log and introduced weights 6.10.98 * kseries.c: corrected error in serial update * kalseries.r: correcting printing error when there is an interaction * kalsurv: added serial update * inthaz.c: put back ihlogis (disappeared with nmath) * renamed wr.r as util.r * moved det and %**% from repeated and growth to rmutil/R/util.r 5.10.98 * corrected check in carma, elliptic, gar, and kalseries for nonpositive transformed values 4.10.98 * glmm.r: corrected two errors 1.10.98 * extended residual plots to all of class recursive * kalcount, kalseries, kalsurv: return mean profiles in z$pred * plot.profile: accepts z$pred as well as a mean function * nbkal.r: corrections * corrected and updated a lot of docs 30.9.98 * moved kalsurv to event library * renamed rmtools as rmutil * inthaz.c: corrected error from change to nmath 29.8.98 * kalsurv.r: added recursive fitted values * kalseries.r: added recursive fitted values * updated plot.residuals for recursive class 27.9.98 * corrected docs for plot.profile, plot.iprofile * added covind.default * plot.iprofile: corrected default settings 24.9.98 * gettvc.r: allow an option for ties * bessel.r: only calculate one kind of function 20.9.98 * gettvc.r: allow NAs in time-varying covariate corrected for ties between response and covariate * tvctomat: allow tvcov to already have class, "tvcov" * added as.double in all Fortran and C calls 18.9.98 * plotrm.r: corrected bug in plot.iprofile due to new covind() 16.9.98 * pkpd.r: corrected mu2.0o2c and added mu2.0o2cfp 15.9.98 * replaced Bessel, Gauss-Hermite, and integration routines bessel.r: added docs 14.9.98 * moved wr to rmtools and added docs * added covind function to rmtools 12.9.98 * kalserie.r: added delta option * tcctomat.Rd: corrected alias * created new library, rmtools 11.9.98 * dist.r: added beta binomial * dist.c: simplified calls to overdispersion functions * autocor.r: corrected pergram * kalserie.r: corrected error in printing parameters with torder>0 * kserieb.c: corrected error when mu function used 10.9.98 * readlist.r: corrected binomial totals for lists in restovec * fmr.r: removed unnecessary code * gar.r: added overdispersed binomial data * dist.r: allow dispersion to be a scalar when mean is a vector created documentation for p and d functions 9.9.98 * nordr.r: corrected weights for adjacent categories model test for p>1 in proportional odds * gar.r: added checks on times and mu arguments added binomial data * corrected docs for elliptic, gar, kalcount, kalseries, kalsurv, nbkal for z$index * clarified docs for rmna, restovec, tcctomat, and tvctomat 8.9.98 * removed backslash at end of Makefiles for event, gnlm, growth * moved integer declarations to the beginning in carmasub.f, elliptic.f, gettvc.f, survkit.f so that g77 should work 5.9.98 * gar.r Corrected predictions for transformed responses #------------------------------------------------------------------------------ #version 0.1 #------------------------------------------------------------------------------stable/MD50000644000176200001440000000154414207537472012053 0ustar liggesusersad4652e2dcfd4a0ecf91a2c01a7defd5 *COPYING 41e5b77f29e889d51de38b18c67c3560 *DESCRIPTION be32134570b524c1a1d66d80bb2c5fea *NAMESPACE 3f30eb56a2956f91612ec9d8d39b1698 *NEWS.md 8cd5a2f8328c92fc6a29eadd681ba9ee *R/pm1_to_pm0_and_pm0_to_pm1.R 0024faf538d3694c17b5f9f4b55e5309 *R/sd2s_and_s2sd.R edd83ce534eeedbe2771db7f2b2f7f1a *R/stable-package.R bdbaca8d6e4c51d1f5daf26264018a28 *R/stable.r 8200bd105444ed769cf5fbb3417d8307 *README.md abe2e86659a56a6b075f3af93a7610d5 *man/Links.Rd 99d67dae233d31f8bcad71efe9069ee3 *man/Parameter_Conversion.Rd 370fdff3bb1f32198176274c7007d74e *man/Parameter_Conversion_Nolan_pm1_pm0.Rd 4a07ccdd5a9467af3db298457defde59 *man/stable.Rd c68c03a81655a1cd8917226c96c81448 *man/stable.mode.Rd b0d5b24c4eda5618b49fc6d583f68fb8 *man/stablereg.Rd c7e5b532b930e833cc9d131acd5a8923 *src/stable.c 59e990ec59325a9cf961d72c43815aed *src/stable_init.c