diff --git a/DESCRIPTION b/DESCRIPTION index 2dcbdbf..da735b5 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: logitnorm Title: Functions for the Logitnormal Distribution -Version: 0.8.37 +Version: 0.8.38 Author: Thomas Wutzler Maintainer: Thomas Wutzler Description: Density, distribution, quantile and random generation function for the logitnormal distribution. Estimation of the mode and the first two moments. Estimation of distribution parameters. diff --git a/R/logitnorm.R b/R/logitnorm.R index ed1bbd8..c1bc52d 100755 --- a/R/logitnorm.R +++ b/R/logitnorm.R @@ -122,7 +122,7 @@ qlogitnorm <- function( } twCoefLogitnormN <- function( - ### Estimating coefficients from a vector of quantiles and perentiles (non-vectorized). + ### Estimating coefficients from a vector of quantiles and percentiles (non-vectorized). quant ##<< the quantile values ,perc = c(0.5,0.975) ##<< the probabilities for which the quantiles were specified , method = "BFGS" ##<< method of optimization (see \code{\link{optim}}) @@ -385,7 +385,7 @@ twCoefLogitnormE <- function( attr(res,"resOptim") <- resOptim res ### named numeric matrix with estimated parameters of the logitnormal - ### distrubtion. + ### distribution. ### colnames: \code{c("mu","sigma")} } #mtrace(coefLogitnorm) diff --git a/README.Rmd b/README.Rmd index 51b9c6d..6327ac1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,56 +1,56 @@ ---- -output: github_document ---- - - - - -```{r, echo = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "tools/README-" -) -``` - -[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/logitnorm)](http://cran.r-project.org/package=logitnorm) -[![Travis-CI Build Status](https://travis-ci.org/bgctw/logitnorm.svg?branch=master)](https://travis-ci.org/bgctw/logitnorm) - - -## Overview - -`logitnorm` package provides support for the univariate -[logit-normal -distribution](https://en.wikipedia.org/wiki/Logit-normal_distribution). In -addition to the usual random, density, percential, and quantile function, it -helps with estimating distribution parameters from observations statistics. - -## Installation - -```{r, eval = FALSE} -# From CRAN -install.packages("logitnorm") - -# Or the the development version from GitHub: -# install.packages("devtools") -devtools::install_github("bgctw/logitnorm") -``` - -## Usage - -See the package vignette for an introduction. - -A simple example estimates distribution parameters from observation -statistics of mode 0.7 and upper quantile 0.9. Next, the density is -computed and plotted across a range of quantiles. - -```{r example} -(theta <- twCoefLogitnormMLE(0.7,0.9)) -x <- seq(0,1, length.out=81) -d <- dlogitnorm(x, mu=theta[1,"mu"], sigma=theta[1,"sigma"]) -plot(d~x,type="l") -abline(v=c(0.7,0.9), col="grey") -``` +--- +output: github_document +--- + + + + +```{r, echo = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "tools/README-" +) +``` + +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/logitnorm)](http://cran.r-project.org/package=logitnorm) +[![Travis-CI Build Status](https://travis-ci.org/bgctw/logitnorm.svg?branch=master)](https://travis-ci.org/bgctw/logitnorm) + + +## Overview + +`logitnorm` package provides support for the univariate +[logit-normal +distribution](https://en.wikipedia.org/wiki/Logit-normal_distribution). In +addition to the usual random, density, percentile, and quantile function, it +helps with estimating distribution parameters from observations statistics. + +## Installation + +```{r, eval = FALSE} +# From CRAN +install.packages("logitnorm") + +# Or the the development version from GitHub: +# install.packages("devtools") +devtools::install_github("bgctw/logitnorm") +``` + +## Usage + +See the package vignette for an introduction. + +A simple example estimates distribution parameters from observation +statistics of mode 0.7 and upper quantile 0.9. Next, the density is +computed and plotted across a range of quantiles. + +```{r example} +(theta <- twCoefLogitnormMLE(0.7,0.9)) +x <- seq(0,1, length.out=81) +d <- dlogitnorm(x, mu=theta[1,"mu"], sigma=theta[1,"sigma"]) +plot(d~x,type="l") +abline(v=c(0.7,0.9), col="grey") +``` diff --git a/README.md b/README.md index e6dbb33..2ebbeef 100644 --- a/README.md +++ b/README.md @@ -1,56 +1,56 @@ ---- -output: github_document ---- - - - - - - -[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/logitnorm)](http://cran.r-project.org/package=logitnorm) -[![Travis-CI Build Status](https://travis-ci.org/bgctw/logitnorm.svg?branch=master)](https://travis-ci.org/bgctw/logitnorm) - - -## Overview - -`logitnorm` package provides support for the univariate -[logit-normal -distribution](https://en.wikipedia.org/wiki/Logit-normal_distribution). In -addition to the usual random, density, percential, and quantile function, it -helps with estimating distribution parameters from observations statistics. - -## Installation - - -```r -# From CRAN -install.packages("logitnorm") - -# Or the the development version from GitHub: -# install.packages("devtools") -devtools::install_github("bgctw/logitnorm") -``` - -## Usage - -See the package vignette for an introduction. - -A simple example estimates distribution parameters from observation -statistics of mode 0.7 and upper quantile 0.9. Next, the density is -computed and plotted across a range of quantiles. - - -```r -(theta <- twCoefLogitnormMLE(0.7,0.9)) -#> mu sigma -#> [1,] 0.7608886 0.464783 -x <- seq(0,1, length.out=81) -d <- dlogitnorm(x, mu=theta[1,"mu"], sigma=theta[1,"sigma"]) -plot(d~x,type="l") -abline(v=c(0.7,0.9), col="grey") -``` - -![plot of chunk example](tools/README-example-1.png) +--- +output: github_document +--- + + + + + + +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/logitnorm)](http://cran.r-project.org/package=logitnorm) +[![Travis-CI Build Status](https://travis-ci.org/bgctw/logitnorm.svg?branch=master)](https://travis-ci.org/bgctw/logitnorm) + + +## Overview + +`logitnorm` package provides support for the univariate +[logit-normal +distribution](https://en.wikipedia.org/wiki/Logit-normal_distribution). In +addition to the usual random, density, percentile, and quantile function, it +helps with estimating distribution parameters from observations statistics. + +## Installation + + +```r +# From CRAN +install.packages("logitnorm") + +# Or the the development version from GitHub: +# install.packages("devtools") +devtools::install_github("bgctw/logitnorm") +``` + +## Usage + +See the package vignette for an introduction. + +A simple example estimates distribution parameters from observation +statistics of mode 0.7 and upper quantile 0.9. Next, the density is +computed and plotted across a range of quantiles. + + +```r +(theta <- twCoefLogitnormMLE(0.7,0.9)) +#> Error in twCoefLogitnormMLE(0.7, 0.9): could not find function "twCoefLogitnormMLE" +x <- seq(0,1, length.out=81) +d <- dlogitnorm(x, mu=theta[1,"mu"], sigma=theta[1,"sigma"]) +#> Error in dlogitnorm(x, mu = theta[1, "mu"], sigma = theta[1, "sigma"]): could not find function "dlogitnorm" +plot(d~x,type="l") +#> Error in eval(predvars, data, env): object 'd' not found +abline(v=c(0.7,0.9), col="grey") +#> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): plot.new has not been called yet +``` diff --git a/cran-comments.md b/cran-comments.md index b99472b..b04f617 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,10 +1,9 @@ ## Note -Improved consistency with other R distribution methods. +Added random seeds to tests to avoid accidental failing. ## Test environments -* local R 3.4.4 on Mint17 64bit -* Ubuntu 14.04.5 LTS (on travis-ci), 3.5.0 -* win-builder (devel and release) +* local R 4.0.3 on Mint 20 64bit +* r-hub.io ## R CMD check results There were no ERRORs nor WARNINGs nor NOTEs diff --git a/man/dlogitnorm.Rd b/man/dlogitnorm.Rd index d948a97..4039f94 100755 --- a/man/dlogitnorm.Rd +++ b/man/dlogitnorm.Rd @@ -1,34 +1,34 @@ -\name{dlogitnorm} -\alias{dlogitnorm} -\title{dlogitnorm} -\description{Density function of logitnormal distribution } -\usage{dlogitnorm(x, mu = 0, sigma = 1, log = FALSE, - ...)} -\arguments{ - \item{x}{vector of quantiles} - \item{mu}{distribution parameters} - \item{sigma}{ -} - \item{log}{if TRUE, the log-density is returned} - \item{\dots}{further arguments passed to \code{\link{dnorm}}: \code{mean}, -and \code{sd} for mu and sigma respectively. } -} -\details{\describe{\item{Logitnorm distribution}{ -\itemize{ -\item{density function: dlogitnorm } -\item{distribution function: \code{\link{plogitnorm}} } -\item{quantile function: \code{\link{qlogitnorm}} } -\item{random generation function: \code{\link{rlogitnorm}} } -} -}} - -The function is only defined in interval (0,1), but the density -returns 0 outside the support region.} - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} - +\name{dlogitnorm} +\alias{dlogitnorm} +\title{dlogitnorm} +\description{Density function of logitnormal distribution } +\usage{dlogitnorm(x, mu = 0, sigma = 1, log = FALSE, + ...)} +\arguments{ + \item{x}{vector of quantiles} + \item{mu}{distribution parameters} + \item{sigma}{ +} + \item{log}{if TRUE, the log-density is returned} + \item{\dots}{further arguments passed to \code{\link{dnorm}}: \code{mean}, +and \code{sd} for mu and sigma respectively. } +} +\details{\describe{\item{Logitnorm distribution}{ +\itemize{ +\item{density function: dlogitnorm } +\item{distribution function: \code{\link{plogitnorm}} } +\item{quantile function: \code{\link{qlogitnorm}} } +\item{random generation function: \code{\link{rlogitnorm}} } +} +}} + +The function is only defined in interval (0,1), but the density +returns 0 outside the support region.} + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} + diff --git a/man/invlogit.Rd b/man/invlogit.Rd index 8b08c49..458b598 100755 --- a/man/invlogit.Rd +++ b/man/invlogit.Rd @@ -1,22 +1,22 @@ -\name{invlogit} -\alias{invlogit} -\title{invlogit} -\description{Transforming (-Inf,Inf) to original scale (0,1)} -\usage{invlogit(q, ...)} -\arguments{ - \item{q}{ -} - \item{\dots}{ -} -} -\details{function \eqn{f(z) = \frac{e^{z}}{e^{z} + 1} \! = \frac{1}{1 + e^{-z}} \!}} - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logit}} - -\code{\link{logitnorm}}} - +\name{invlogit} +\alias{invlogit} +\title{invlogit} +\description{Transforming (-Inf,Inf) to original scale (0,1)} +\usage{invlogit(q, ...)} +\arguments{ + \item{q}{ +} + \item{\dots}{ +} +} +\details{function \eqn{f(z) = \frac{e^{z}}{e^{z} + 1} \! = \frac{1}{1 + e^{-z}} \!}} + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logit}} + +\code{\link{logitnorm}}} + diff --git a/man/logit.Rd b/man/logit.Rd index da52012..ac062ce 100755 --- a/man/logit.Rd +++ b/man/logit.Rd @@ -1,22 +1,22 @@ -\name{logit} -\alias{logit} -\title{logit} -\description{Transforming (0,1) to normal scale (-Inf Inf)} -\usage{logit(p, ...)} -\arguments{ - \item{p}{ -} - \item{\dots}{ -} -} -\details{function \eqn{logit(p) = log \left( \frac{p}{1-p} \right) = log(p) - log(1-p)}} - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{invlogit}} - -\code{\link{logitnorm}}} - +\name{logit} +\alias{logit} +\title{logit} +\description{Transforming (0,1) to normal scale (-Inf Inf)} +\usage{logit(p, ...)} +\arguments{ + \item{p}{ +} + \item{\dots}{ +} +} +\details{function \eqn{logit(p) = log \left( \frac{p}{1-p} \right) = log(p) - log(1-p)}} + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{invlogit}} + +\code{\link{logitnorm}}} + diff --git a/man/logitnorm-package.Rd b/man/logitnorm-package.Rd index d6d5cae..a941b73 100755 --- a/man/logitnorm-package.Rd +++ b/man/logitnorm-package.Rd @@ -1,55 +1,55 @@ -\name{logitnorm-package} -\alias{logitnorm-package} \alias{logitnorm} -\title{Utilities for the logitnormal distribution in R} -\description{ Utilities for the logitnormal distribution in R -\itemize{ -\item Density, distribution, quantile and random generation function. -\item Estimation of the mode and the first two moments. -\item Estimation of distribution parameters from observations. -} -}%description - - -\details{ -The package provides the main distribution functions: -\itemize{ -\item density \code{\link{dlogitnorm}}, -\item distribution \code{\link{plogitnorm}}, -\item quantile \code{\link{qlogitnorm}}, and -\item random generation function \code{\link{rlogitnorm}}. -}%itemize - -Transformation functions - \itemize{ - \item{ (0,1) -> (-Inf,Inf): \code{\link{logit}} } - \item{ (-Inf,Inf) -> (0,1): \code{\link{invlogit}} } - } - -Moments and mode - \itemize{ - \item{ Expected value and variance: \code{\link{momentsLogitnorm}} } - \item{ Mode: \code{\link{modeLogitnorm}} } - } - -Estimating parameters - \itemize{ - \item{from mode and upper quantile: \code{\link{twCoefLogitnormMLE}} } - \item{from mode and constraint to be unimodal and maximally flat: \code{\link{twCoefLogitnormMLEFlat}} } - \item{from median and upper quantile: \code{\link{twCoefLogitnorm}} } - \item{from expected value, i.e. mean and upper quantile: \code{\link{twCoefLogitnormE}} } - \item{from a confidence interval which is symmetric at normal scale: \code{\link{twCoefLogitnormCi}} } - \item{from prescribed quantiles: \code{\link{twCoefLogitnormN}} } - } - -Have a look at the package vignettes. - }%details - -\references{ -Frederic, P. & Lad, F. (2008) Two Moments of the Logitnormal Distribution. -Communications in Statistics-Simulation and Computation, 37, 1263-1269 -}%references -\author{Thomas Wutzler} - -\keyword{ package } - - +\name{logitnorm-package} +\alias{logitnorm-package} \alias{logitnorm} +\title{Utilities for the logitnormal distribution in R} +\description{ Utilities for the logitnormal distribution in R +\itemize{ +\item Density, distribution, quantile and random generation function. +\item Estimation of the mode and the first two moments. +\item Estimation of distribution parameters from observations. +} +}%description + + +\details{ +The package provides the main distribution functions: +\itemize{ +\item density \code{\link{dlogitnorm}}, +\item distribution \code{\link{plogitnorm}}, +\item quantile \code{\link{qlogitnorm}}, and +\item random generation function \code{\link{rlogitnorm}}. +}%itemize + +Transformation functions + \itemize{ + \item{ (0,1) -> (-Inf,Inf): \code{\link{logit}} } + \item{ (-Inf,Inf) -> (0,1): \code{\link{invlogit}} } + } + +Moments and mode + \itemize{ + \item{ Expected value and variance: \code{\link{momentsLogitnorm}} } + \item{ Mode: \code{\link{modeLogitnorm}} } + } + +Estimating parameters + \itemize{ + \item{from mode and upper quantile: \code{\link{twCoefLogitnormMLE}} } + \item{from mode and constraint to be unimodal and maximally flat: \code{\link{twCoefLogitnormMLEFlat}} } + \item{from median and upper quantile: \code{\link{twCoefLogitnorm}} } + \item{from expected value, i.e. mean and upper quantile: \code{\link{twCoefLogitnormE}} } + \item{from a confidence interval which is symmetric at normal scale: \code{\link{twCoefLogitnormCi}} } + \item{from prescribed quantiles: \code{\link{twCoefLogitnormN}} } + } + +Have a look at the package vignettes. + }%details + +\references{ +Frederic, P. & Lad, F. (2008) Two Moments of the Logitnormal Distribution. +Communications in Statistics-Simulation and Computation, 37, 1263-1269 +}%references +\author{Thomas Wutzler} + +\keyword{ package } + + diff --git a/man/modeLogitnorm.Rd b/man/modeLogitnorm.Rd index ed75f0e..70ae89c 100755 --- a/man/modeLogitnorm.Rd +++ b/man/modeLogitnorm.Rd @@ -1,19 +1,19 @@ -\name{modeLogitnorm} -\alias{modeLogitnorm} -\title{modeLogitnorm} -\description{Mode of the logitnormal distribution by numerical optimization} -\usage{modeLogitnorm(mu, sigma, tol = invlogit(mu)/1000)} -\arguments{ - \item{mu}{parameter mu} - \item{sigma}{parameter sigma} - \item{tol}{precisions of the estimate} -} - - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} - +\name{modeLogitnorm} +\alias{modeLogitnorm} +\title{modeLogitnorm} +\description{Mode of the logitnormal distribution by numerical optimization} +\usage{modeLogitnorm(mu, sigma, tol = invlogit(mu)/1000)} +\arguments{ + \item{mu}{parameter mu} + \item{sigma}{parameter sigma} + \item{tol}{precisions of the estimate} +} + + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} + diff --git a/man/momentsLogitnorm.Rd b/man/momentsLogitnorm.Rd index 03b91f5..db02b1d 100755 --- a/man/momentsLogitnorm.Rd +++ b/man/momentsLogitnorm.Rd @@ -1,27 +1,27 @@ -\name{momentsLogitnorm} -\alias{momentsLogitnorm} -\title{momentsLogitnorm} -\description{First two moments of the logitnormal distribution by numerical integration} -\usage{momentsLogitnorm(mu, sigma, abs.tol = 0, - ...)} -\arguments{ - \item{mu}{parameter mu} - \item{sigma}{parameter sigma} - \item{abs.tol}{changing default to \code{\link{integrate}}} - \item{\dots}{further parameters to the \code{\link{integrate}} function} -} - -\value{named numeric vector with components \itemize{ -\item{ \code{mean}: expected value, i.e. first moment} -\item{ \code{var}: variance, i.e. second moment } -}} - -\author{Thomas Wutzler} - - - - -\examples{ -(res <- momentsLogitnorm(4,1)) -(res <- momentsLogitnorm(5,0.1)) -} +\name{momentsLogitnorm} +\alias{momentsLogitnorm} +\title{momentsLogitnorm} +\description{First two moments of the logitnormal distribution by numerical integration} +\usage{momentsLogitnorm(mu, sigma, abs.tol = 0, + ...)} +\arguments{ + \item{mu}{parameter mu} + \item{sigma}{parameter sigma} + \item{abs.tol}{changing default to \code{\link{integrate}}} + \item{\dots}{further parameters to the \code{\link{integrate}} function} +} + +\value{named numeric vector with components \itemize{ +\item{ \code{mean}: expected value, i.e. first moment} +\item{ \code{var}: variance, i.e. second moment } +}} + +\author{Thomas Wutzler} + + + + +\examples{ +(res <- momentsLogitnorm(4,1)) +(res <- momentsLogitnorm(5,0.1)) +} diff --git a/man/plogitnorm.Rd b/man/plogitnorm.Rd index c2aa959..efbe67a 100755 --- a/man/plogitnorm.Rd +++ b/man/plogitnorm.Rd @@ -1,22 +1,22 @@ -\name{plogitnorm} -\alias{plogitnorm} -\title{plogitnorm} -\description{Distribution function for logitnormal distribution } -\usage{plogitnorm(q, mu = 0, sigma = 1, ...)} -\arguments{ - \item{q}{vector of quantiles} - \item{mu}{distribution parameters} - \item{sigma}{ -} - \item{\dots}{ -} -} - - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} - +\name{plogitnorm} +\alias{plogitnorm} +\title{plogitnorm} +\description{Distribution function for logitnormal distribution } +\usage{plogitnorm(q, mu = 0, sigma = 1, ...)} +\arguments{ + \item{q}{vector of quantiles} + \item{mu}{distribution parameters} + \item{sigma}{ +} + \item{\dots}{ +} +} + + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} + diff --git a/man/qlogitnorm.Rd b/man/qlogitnorm.Rd index 8712bcb..9486513 100755 --- a/man/qlogitnorm.Rd +++ b/man/qlogitnorm.Rd @@ -1,22 +1,22 @@ -\name{qlogitnorm} -\alias{qlogitnorm} -\title{qlogitnorm} -\description{Quantiles of logitnormal distribution. } -\usage{qlogitnorm(p, mu = 0, sigma = 1, ...)} -\arguments{ - \item{p}{vector of probabilities} - \item{mu}{distribution parameters} - \item{sigma}{ -} - \item{\dots}{ -} -} - - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} - +\name{qlogitnorm} +\alias{qlogitnorm} +\title{qlogitnorm} +\description{Quantiles of logitnormal distribution. } +\usage{qlogitnorm(p, mu = 0, sigma = 1, ...)} +\arguments{ + \item{p}{vector of probabilities} + \item{mu}{distribution parameters} + \item{sigma}{ +} + \item{\dots}{ +} +} + + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} + diff --git a/man/rlogitnorm.Rd b/man/rlogitnorm.Rd index 8cda760..0eaa6ca 100755 --- a/man/rlogitnorm.Rd +++ b/man/rlogitnorm.Rd @@ -1,20 +1,20 @@ -\name{rlogitnorm} -\alias{rlogitnorm} -\title{rlogitnorm} -\description{Random number generation for logitnormal distribution} -\usage{rlogitnorm(n, mu = 0, sigma = 1, ...)} -\arguments{ - \item{n}{number of observations} - \item{mu}{distribution parameter} - \item{sigma}{distribution parameter} - \item{\dots}{arguments to \code{\link{rnorm}}} -} - - - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} - +\name{rlogitnorm} +\alias{rlogitnorm} +\title{rlogitnorm} +\description{Random number generation for logitnormal distribution} +\usage{rlogitnorm(n, mu = 0, sigma = 1, ...)} +\arguments{ + \item{n}{number of observations} + \item{mu}{distribution parameter} + \item{sigma}{distribution parameter} + \item{\dots}{arguments to \code{\link{rnorm}}} +} + + + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} + diff --git a/man/twCoefLogitnorm.Rd b/man/twCoefLogitnorm.Rd index dfb6f6d..bdf8b6f 100755 --- a/man/twCoefLogitnorm.Rd +++ b/man/twCoefLogitnorm.Rd @@ -1,45 +1,45 @@ -\name{twCoefLogitnorm} -\alias{twCoefLogitnorm} -\title{twCoefLogitnorm} -\description{Estimating coefficients of logitnormal distribution from median and upper quantile } -\usage{twCoefLogitnorm(median, quant, perc = 0.975, - ...)} -\arguments{ - \item{median}{numeric vector: the median of the density function} - \item{quant}{numeric vector: the upper quantile value} - \item{perc}{numeric vector: the probability for which the quantile was specified} - \item{\dots}{ -} -} - -\value{numeric matrix with columns \code{c("mu","sigma")} -rows correspond to rows in median, quant, and perc} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -# estimate the parameters, with median at 0.7 and upper quantile at 0.9 -med = 0.7; upper = 0.9 -med = 0.2; upper = 0.4 -(theta <- twCoefLogitnorm(med,upper)) - -x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid -px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function -plot(px~x); abline(v = c(med,upper),col = "gray"); abline(h = c(0.5,0.975),col = "gray") - -dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function -plot(dx~x); abline(v = c(med,upper),col = "gray") - -# vectorized -(theta <- twCoefLogitnorm(seq(0.4,0.8,by = 0.1),0.9)) - -.tmp.f <- function(){ - # xr = rlogitnorm(1e5, mu = theta["mu"], sigma = theta["sigma"]) - # median(xr) - invlogit(theta["mu"]) - qlogitnorm(0.975, mu = theta["mu"], sigma = theta["sigma"]) -} -} +\name{twCoefLogitnorm} +\alias{twCoefLogitnorm} +\title{twCoefLogitnorm} +\description{Estimating coefficients of logitnormal distribution from median and upper quantile } +\usage{twCoefLogitnorm(median, quant, perc = 0.975, + ...)} +\arguments{ + \item{median}{numeric vector: the median of the density function} + \item{quant}{numeric vector: the upper quantile value} + \item{perc}{numeric vector: the probability for which the quantile was specified} + \item{\dots}{ +} +} + +\value{numeric matrix with columns \code{c("mu","sigma")} +rows correspond to rows in median, quant, and perc} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +# estimate the parameters, with median at 0.7 and upper quantile at 0.9 +med = 0.7; upper = 0.9 +med = 0.2; upper = 0.4 +(theta <- twCoefLogitnorm(med,upper)) + +x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid +px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function +plot(px~x); abline(v = c(med,upper),col = "gray"); abline(h = c(0.5,0.975),col = "gray") + +dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function +plot(dx~x); abline(v = c(med,upper),col = "gray") + +# vectorized +(theta <- twCoefLogitnorm(seq(0.4,0.8,by = 0.1),0.9)) + +.tmp.f <- function(){ + # xr = rlogitnorm(1e5, mu = theta["mu"], sigma = theta["sigma"]) + # median(xr) + invlogit(theta["mu"]) + qlogitnorm(0.975, mu = theta["mu"], sigma = theta["sigma"]) +} +} diff --git a/man/twCoefLogitnormCi.Rd b/man/twCoefLogitnormCi.Rd index b577c5c..b90fc49 100755 --- a/man/twCoefLogitnormCi.Rd +++ b/man/twCoefLogitnormCi.Rd @@ -1,31 +1,31 @@ -\name{twCoefLogitnormCi} -\alias{twCoefLogitnormCi} -\title{twCoefLogitnormCi} -\description{Calculates mu and sigma of the logitnormal distribution from lower and upper quantile, i.e. confidence interval.} -\usage{twCoefLogitnormCi(lower, upper, perc = 0.975, - sigmaFac = qnorm(perc), isTransScale = FALSE)} -\arguments{ - \item{lower}{value at the lower quantile, i.e. practical minimum} - \item{upper}{value at the upper quantile, i.e. practical maximum} - \item{perc}{numeric vector: the probability for which the quantile was specified} - \item{sigmaFac}{sigmaFac = 2 is 95\% sigmaFac = 2.6 is 99\% interval} - \item{isTransScale}{if true lower and upper are already on logit scale} -} - -\value{named numeric vector: mu and sigma parameter of the logitnormal distribution.} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -mu = 2 -sd = c(1,0.8) -p = 0.99 -lower <- l <- qlogitnorm(1 - p, mu, sd ) # p-confidence interval -upper <- u <- qlogitnorm(p, mu, sd ) # p-confidence interval -cf <- twCoefLogitnormCi(lower,upper, perc = p) -all.equal( cf[,"mu"] , c(mu,mu) ) -all.equal( cf[,"sigma"] , sd ) -} +\name{twCoefLogitnormCi} +\alias{twCoefLogitnormCi} +\title{twCoefLogitnormCi} +\description{Calculates mu and sigma of the logitnormal distribution from lower and upper quantile, i.e. confidence interval.} +\usage{twCoefLogitnormCi(lower, upper, perc = 0.975, + sigmaFac = qnorm(perc), isTransScale = FALSE)} +\arguments{ + \item{lower}{value at the lower quantile, i.e. practical minimum} + \item{upper}{value at the upper quantile, i.e. practical maximum} + \item{perc}{numeric vector: the probability for which the quantile was specified} + \item{sigmaFac}{sigmaFac = 2 is 95\% sigmaFac = 2.6 is 99\% interval} + \item{isTransScale}{if true lower and upper are already on logit scale} +} + +\value{named numeric vector: mu and sigma parameter of the logitnormal distribution.} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +mu = 2 +sd = c(1,0.8) +p = 0.99 +lower <- l <- qlogitnorm(1 - p, mu, sd ) # p-confidence interval +upper <- u <- qlogitnorm(p, mu, sd ) # p-confidence interval +cf <- twCoefLogitnormCi(lower,upper, perc = p) +all.equal( cf[,"mu"] , c(mu,mu) ) +all.equal( cf[,"sigma"] , sd ) +} diff --git a/man/twCoefLogitnormE.Rd b/man/twCoefLogitnormE.Rd index 29afab4..bea8a58 100755 --- a/man/twCoefLogitnormE.Rd +++ b/man/twCoefLogitnormE.Rd @@ -1,45 +1,45 @@ -\name{twCoefLogitnormE} -\alias{twCoefLogitnormE} -\title{twCoefLogitnormE} -\description{Estimating coefficients of logitnormal distribution from expected value, i.e. mean, and upper quantile. } -\usage{twCoefLogitnormE(mean, quant, perc = c(0.975), - method = "BFGS", theta0 = c(mu = 0, sigma = 1), - returnDetails = FALSE, ...)} -\arguments{ - \item{mean}{the expected value of the density function} - \item{quant}{the quantile values} - \item{perc}{the probabilities for which the quantiles were -specified} - \item{method}{method of optimization (see \code{\link{optim}})} - \item{theta0}{starting parameters} - \item{returnDetails}{if TRUE, the full output of optim is returned -with attribute resOptim} - \item{\dots}{ -} -} - -\value{named numeric matrix with estimated parameters of the logitnormal -distrubtion. -colnames: \code{c("mu","sigma")}} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -# estimate the parameters -(thetaE <- twCoefLogitnormE(0.7,0.9)) - -x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid -px <- plogitnorm(x,mu = thetaE[1],sigma = thetaE[2]) #percentiles function -plot(px~x); abline(v = c(0.7,0.9),col = "gray"); abline(h = c(0.5,0.975),col = "gray") -dx <- dlogitnorm(x,mu = thetaE[1],sigma = thetaE[2]) #density function -plot(dx~x); abline(v = c(0.7,0.9),col = "gray") - -z <- rlogitnorm(1e5, mu = thetaE[1],sigma = thetaE[2]) -mean(z) # about 0.7 - -# vectorized -(theta <- twCoefLogitnormE(mean = seq(0.4,0.8,by = 0.1),quant = 0.9)) -} +\name{twCoefLogitnormE} +\alias{twCoefLogitnormE} +\title{twCoefLogitnormE} +\description{Estimating coefficients of logitnormal distribution from expected value, i.e. mean, and upper quantile. } +\usage{twCoefLogitnormE(mean, quant, perc = c(0.975), + method = "BFGS", theta0 = c(mu = 0, sigma = 1), + returnDetails = FALSE, ...)} +\arguments{ + \item{mean}{the expected value of the density function} + \item{quant}{the quantile values} + \item{perc}{the probabilities for which the quantiles were +specified} + \item{method}{method of optimization (see \code{\link{optim}})} + \item{theta0}{starting parameters} + \item{returnDetails}{if TRUE, the full output of optim is returned +with attribute resOptim} + \item{\dots}{ +} +} + +\value{named numeric matrix with estimated parameters of the logitnormal +distribution. +colnames: \code{c("mu","sigma")}} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +# estimate the parameters +(thetaE <- twCoefLogitnormE(0.7,0.9)) + +x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid +px <- plogitnorm(x,mu = thetaE[1],sigma = thetaE[2]) #percentiles function +plot(px~x); abline(v = c(0.7,0.9),col = "gray"); abline(h = c(0.5,0.975),col = "gray") +dx <- dlogitnorm(x,mu = thetaE[1],sigma = thetaE[2]) #density function +plot(dx~x); abline(v = c(0.7,0.9),col = "gray") + +z <- rlogitnorm(1e5, mu = thetaE[1],sigma = thetaE[2]) +mean(z) # about 0.7 + +# vectorized +(theta <- twCoefLogitnormE(mean = seq(0.4,0.8,by = 0.1),quant = 0.9)) +} diff --git a/man/twCoefLogitnormMLE.Rd b/man/twCoefLogitnormMLE.Rd index 507f6fb..0147aba 100755 --- a/man/twCoefLogitnormMLE.Rd +++ b/man/twCoefLogitnormMLE.Rd @@ -1,36 +1,36 @@ -\name{twCoefLogitnormMLE} -\alias{twCoefLogitnormMLE} -\title{twCoefLogitnormMLE} -\description{Estimating coefficients of logitnormal distribution from mode and upper quantile } -\usage{twCoefLogitnormMLE(mle, quant, perc = 0.999)} -\arguments{ - \item{mle}{numeric vector: the mode of the density function} - \item{quant}{numeric vector: the upper quantile value} - \item{perc}{numeric vector: the probability for which the quantile -was specified} -} - -\value{numeric matrix with columns \code{c("mu","sigma")} -rows correspond to rows in \code{mle}, \code{quant}, and \code{perc}} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -# estimate the parameters, with mode 0.7 and upper quantile 0.9 -mode = 0.7; upper = 0.9 -mode = 0.2; upper = 0.7 -#mode = 0.5; upper = 0.9 -(theta <- twCoefLogitnormMLE(mode,upper)) -x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid -px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function -plot(px~x); abline(v = c(mode,upper),col = "gray"); abline(h = c(0.999),col = "gray") -dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function -plot(dx~x); abline(v = c(mode,upper),col = "gray") -# vectorized -(theta <- twCoefLogitnormMLE(mle = seq(0.4,0.8,by = 0.1),quant = upper)) -# flat -(theta <- twCoefLogitnormMLEFlat(mode)) -} +\name{twCoefLogitnormMLE} +\alias{twCoefLogitnormMLE} +\title{twCoefLogitnormMLE} +\description{Estimating coefficients of logitnormal distribution from mode and upper quantile } +\usage{twCoefLogitnormMLE(mle, quant, perc = 0.999)} +\arguments{ + \item{mle}{numeric vector: the mode of the density function} + \item{quant}{numeric vector: the upper quantile value} + \item{perc}{numeric vector: the probability for which the quantile +was specified} +} + +\value{numeric matrix with columns \code{c("mu","sigma")} +rows correspond to rows in \code{mle}, \code{quant}, and \code{perc}} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +# estimate the parameters, with mode 0.7 and upper quantile 0.9 +mode = 0.7; upper = 0.9 +mode = 0.2; upper = 0.7 +#mode = 0.5; upper = 0.9 +(theta <- twCoefLogitnormMLE(mode,upper)) +x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid +px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function +plot(px~x); abline(v = c(mode,upper),col = "gray"); abline(h = c(0.999),col = "gray") +dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function +plot(dx~x); abline(v = c(mode,upper),col = "gray") +# vectorized +(theta <- twCoefLogitnormMLE(mle = seq(0.4,0.8,by = 0.1),quant = upper)) +# flat +(theta <- twCoefLogitnormMLEFlat(mode)) +} diff --git a/man/twCoefLogitnormMLEFlat.Rd b/man/twCoefLogitnormMLEFlat.Rd index fd76846..6f246bb 100644 --- a/man/twCoefLogitnormMLEFlat.Rd +++ b/man/twCoefLogitnormMLEFlat.Rd @@ -1,20 +1,20 @@ -\name{twCoefLogitnormMLEFlat} -\alias{twCoefLogitnormMLEFlat} -\title{twCoefLogitnormMLEFlat} -\description{Estimating coefficients of a maximally flat unimodal logitnormal distribution from mode } -\usage{twCoefLogitnormMLEFlat(mle)} -\arguments{ - \item{mle}{numeric vector: the mode of the density function} -} -\details{When increasing the sigma parameter, the distribution becomes -eventually becomes bi-model, i.e. has two maxima. -This function estimates parameters for given mode, so that the distribution assigns high -density to a maximum range, i.e. is maximally flat, but still is unimodal.} - - -\author{Thomas Wutzler} - - - - - +\name{twCoefLogitnormMLEFlat} +\alias{twCoefLogitnormMLEFlat} +\title{twCoefLogitnormMLEFlat} +\description{Estimating coefficients of a maximally flat unimodal logitnormal distribution from mode } +\usage{twCoefLogitnormMLEFlat(mle)} +\arguments{ + \item{mle}{numeric vector: the mode of the density function} +} +\details{When increasing the sigma parameter, the distribution becomes +eventually becomes bi-model, i.e. has two maxima. +This function estimates parameters for given mode, so that the distribution assigns high +density to a maximum range, i.e. is maximally flat, but still is unimodal.} + + +\author{Thomas Wutzler} + + + + + diff --git a/man/twCoefLogitnormN.Rd b/man/twCoefLogitnormN.Rd index 600af80..2ca5f8c 100755 --- a/man/twCoefLogitnormN.Rd +++ b/man/twCoefLogitnormN.Rd @@ -1,39 +1,39 @@ -\name{twCoefLogitnormN} -\alias{twCoefLogitnormN} -\title{twCoefLogitnormN} -\description{Estimating coefficients from a vector of quantiles and perentiles (non-vectorized). } -\usage{twCoefLogitnormN(quant, perc = c(0.5, 0.975), - method = "BFGS", theta0 = c(mu = 0, sigma = 1), - returnDetails = FALSE, ...)} -\arguments{ - \item{quant}{the quantile values} - \item{perc}{the probabilities for which the quantiles were specified} - \item{method}{method of optimization (see \code{\link{optim}})} - \item{theta0}{starting parameters} - \item{returnDetails}{if TRUE, the full output of optim is returned instead of only entry par} - \item{\dots}{further parameters passed to optim, e.g. \code{control = list(maxit = 1000)}} -} - -\value{named numeric vector with estimated parameters of the logitnormal distribution. -names: \code{c("mu","sigma")}} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -# experiment of re-estimation the parameters from generated observations -thetaTrue <- c(mu = 0.8, sigma = 0.7) -obsTrue <- rlogitnorm(thetaTrue["mu"],thetaTrue["sigma"], n = 500) -obs <- obsTrue + rnorm(100, sd = 0.05) # some observation uncertainty -plot(density(obsTrue),col = "blue"); lines(density(obs)) - -# re-estimate parameters based on the quantiles of the observations -(theta <- twCoefLogitnorm( median(obs), quantile(obs,probs = 0.9), perc = 0.9)) - -# add line of estimated distribution -x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid -dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) -lines( dx ~ x, col = "orange") -} +\name{twCoefLogitnormN} +\alias{twCoefLogitnormN} +\title{twCoefLogitnormN} +\description{Estimating coefficients from a vector of quantiles and percentiles (non-vectorized). } +\usage{twCoefLogitnormN(quant, perc = c(0.5, 0.975), + method = "BFGS", theta0 = c(mu = 0, sigma = 1), + returnDetails = FALSE, ...)} +\arguments{ + \item{quant}{the quantile values} + \item{perc}{the probabilities for which the quantiles were specified} + \item{method}{method of optimization (see \code{\link{optim}})} + \item{theta0}{starting parameters} + \item{returnDetails}{if TRUE, the full output of optim is returned instead of only entry par} + \item{\dots}{further parameters passed to optim, e.g. \code{control = list(maxit = 1000)}} +} + +\value{named numeric vector with estimated parameters of the logitnormal distribution. +names: \code{c("mu","sigma")}} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +# experiment of re-estimation the parameters from generated observations +thetaTrue <- c(mu = 0.8, sigma = 0.7) +obsTrue <- rlogitnorm(thetaTrue["mu"],thetaTrue["sigma"], n = 500) +obs <- obsTrue + rnorm(100, sd = 0.05) # some observation uncertainty +plot(density(obsTrue),col = "blue"); lines(density(obs)) + +# re-estimate parameters based on the quantiles of the observations +(theta <- twCoefLogitnorm( median(obs), quantile(obs,probs = 0.9), perc = 0.9)) + +# add line of estimated distribution +x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid +dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) +lines( dx ~ x, col = "orange") +} diff --git a/man/twSigmaLogitnorm.Rd b/man/twSigmaLogitnorm.Rd index d556e80..ee03c68 100755 --- a/man/twSigmaLogitnorm.Rd +++ b/man/twSigmaLogitnorm.Rd @@ -1,30 +1,30 @@ -\name{twSigmaLogitnorm} -\alias{twSigmaLogitnorm} -\title{twSigmaLogitnorm} -\description{Estimating coefficients of logitnormal distribution from mode and given mu } -\usage{twSigmaLogitnorm(mle, mu = 0)} -\arguments{ - \item{mle}{numeric vector: the mode of the density function} - \item{mu}{for mu = 0 the distribution will be the flattest case (maybe bimodal)} -} -\details{For a mostly flat unimodal distribution use \code{\link{twCoefLogitnormMLE}(mle,0)}} -\value{numeric matrix with columns \code{c("mu","sigma")} -rows correspond to rows in mle and mu} - -\author{Thomas Wutzler} - - - -\seealso{\code{\link{logitnorm}}} -\examples{ -mle <- 0.8 -(theta <- twSigmaLogitnorm(mle)) -# -x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid -px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function -plot(px~x); abline(v = c(mle),col = "gray") -dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function -plot(dx~x); abline(v = c(mle),col = "gray") -# vectorized -(theta <- twSigmaLogitnorm(mle = seq(0.401,0.8,by = 0.1))) -} +\name{twSigmaLogitnorm} +\alias{twSigmaLogitnorm} +\title{twSigmaLogitnorm} +\description{Estimating coefficients of logitnormal distribution from mode and given mu } +\usage{twSigmaLogitnorm(mle, mu = 0)} +\arguments{ + \item{mle}{numeric vector: the mode of the density function} + \item{mu}{for mu = 0 the distribution will be the flattest case (maybe bimodal)} +} +\details{For a mostly flat unimodal distribution use \code{\link{twCoefLogitnormMLE}(mle,0)}} +\value{numeric matrix with columns \code{c("mu","sigma")} +rows correspond to rows in mle and mu} + +\author{Thomas Wutzler} + + + +\seealso{\code{\link{logitnorm}}} +\examples{ +mle <- 0.8 +(theta <- twSigmaLogitnorm(mle)) +# +x <- seq(0,1,length.out = 41)[-c(1,41)] # plotting grid +px <- plogitnorm(x,mu = theta[1],sigma = theta[2]) #percentiles function +plot(px~x); abline(v = c(mle),col = "gray") +dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2]) #density function +plot(dx~x); abline(v = c(mle),col = "gray") +# vectorized +(theta <- twSigmaLogitnorm(mle = seq(0.401,0.8,by = 0.1))) +}