Lognorm
Functions for the lognormal distribution in R
Install / Use
/learn @bgctw/LognormREADME
Overview
The lognorm package provides support for the univariate lognormal distribution. It helps
- estimating distribution parameters from observations statistics
- computing moments and other statistics
- approximate the sum of several lognormally distributed random variables
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"])))
#> mean sigmaStar
#> 210.000000 1.437293
See the package vignettes (*.md) for further examples.
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
