knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "tools/README-"
)

CRAN_Status_Badge Travis-CI Build Status

Overview

The lognorm package provides support for the univariate lognormal distribution. It helps

Installation

# From CRAN
install.packages("lognorm")

# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("bgctw/lognorm")

Usage

A simple example computes the distribution parameters of the sum of two correlated lognormal parameters.

require(lognorm)
means <- c(110,100)
sigmaStar <- c(1.5,1.5)
corr <- setMatrixOffDiagonals(diag(nrow = 2), value = 0.6, isSymmetric = TRUE)
#
# estimate paramters of terms 
coefTerms <- getParmsLognormForExpval(means, sigmaStar)
# approximate sum of the two correlated term
coefSum <- estimateSumLognormal( coefTerms[,"mu"], coefTerms[,"sigma"], corr = corr )
#
# plot statistics of distribution 
x <- seq(50,500,length.out = 100)
density <- dlnorm(x, coefSum["mu"], coefSum["sigma"])
plot(density ~ x, type = "l")
# confidence intervals
abline(v = qlnorm(c(0.025, 0.975), coefSum["mu"], coefSum["sigma"]), lty = "dotted")
# expected value
abline(v = getLognormMoments(coefSum["mu"], coefSum["sigma"])[1,"mean"])
# mode
abline(v = getLognormMode(coefSum["mu"], coefSum["sigma"]), lty = "dashed")
# median
abline(v = getLognormMedian(coefSum["mu"], coefSum["sigma"]), lty = "dotdash")

The sum of the expected values is conserved, while the multiplicative standard deviation decreases during aggregation:

c( 
  mean = unname(getLognormMoments(coefSum["mu"], coefSum["sigma"])[1,"mean"])
  , sigmaStar = unname(exp(coefSum["sigma"])))

See the package vignettes (*.md) for further examples.



bgctw/lognorm documentation built on March 17, 2021, 3:21 a.m.