pub struct LogNormal { /* private fields */ }
Expand description
§The Log Normal Distribution
§Description
Density, distribution function, quantile function and random generation for the log normal distribution whose logarithm has mean equal to meanlog and standard deviation equal to sdlog.
§Arguments
- meanlog, sdlog: mean and standard deviation of the distribution on the log scale with default values of 0 and 1 respectively.
§Details
The log normal distribution has density
$ f(x) = 1/(\sqrt(2 \pi) \sigma x) e^-((log x - \mu)^2 / (2 \mu^2)) $
where $ \mu $ and $ \sigma $ are the mean and standard deviation of the logarithm. The mean is $ E(X) = exp(\mu + 1/2 \sigma^2) $, the median is $ med(X) = exp(\mu) $, and the variance $ Var(X) = exp(2*\mu + \sigma^2)*(exp(\sigma^2) - 1) $ and hence the coefficient of variation is $ \sqrt(exp(\sigma^2) - 1) $ which is approximately $ \sigma $ when that is small (e.g., $ \sigma < 1/2 $).
§Density Plot
let lnorm = LogNormalBuilder::new().build();
let x = <[f64]>::sequence(-1.0, 8.0, 1000);
let y = x
.iter()
.map(|x| lnorm.density(x).unwrap())
.collect::<Vec<_>>();
let root = SVGBackend::new("density.svg", (1024, 768)).into_drawing_area();
Plot::new()
.with_options(PlotOptions {
x_axis_label: "x".to_string(),
y_axis_label: "density".to_string(),
..Default::default()
})
.with_plottable(Line {
x,
y,
color: BLACK,
..Default::default()
})
.plot(&root)
.unwrap();
§Note
The cumulative hazard $ H(t) = - \log(1 - F(t)) $ is $ -plnorm(t, r, lower = FALSE, log = TRUE) $.
§Source
dlnorm is calculated from the definition (in ‘Details’). [pqr]lnorm are based on the relationship to the normal.
Consequently, they model a single point mass at exp(meanlog) for the boundary case sdlog = 0.
§References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Johnson, N. L., Kotz, S. and Balakrishnan, N. (1995) Continuous Univariate Distributions, volume 1, chapter 14. Wiley, New York.
§See Also
Distributions for other standard distributions, including dnorm for the normal distribution.
§Examples
let norm = NormalBuilder::new().build();
println!("{}", norm.density(0));
let lnorm = LogNormalBuilder::new().build();
println!("{}", lnorm.density(1));
Trait Implementations§
Source§impl Distribution for LogNormal
impl Distribution for LogNormal
Source§fn log_density<R>(&self, x: R) -> NonNan<f64>
fn log_density<R>(&self, x: R) -> NonNan<f64>
Source§fn probability<R>(
&self,
q: R,
lower_tail: bool,
) -> GreaterThanEqualZero<LessThanEqualOne<NonNan<f64>>>
fn probability<R>( &self, q: R, lower_tail: bool, ) -> GreaterThanEqualZero<LessThanEqualOne<NonNan<f64>>>
Source§fn log_probability<R>(
&self,
q: R,
lower_tail: bool,
) -> LessThanEqualZero<NonNan<f64>>
fn log_probability<R>( &self, q: R, lower_tail: bool, ) -> LessThanEqualZero<NonNan<f64>>
Source§fn quantile<P>(&self, p: P, lower_tail: bool) -> NonNan<f64>
fn quantile<P>(&self, p: P, lower_tail: bool) -> NonNan<f64>
Auto Trait Implementations§
impl Freeze for LogNormal
impl RefUnwindSafe for LogNormal
impl Send for LogNormal
impl Sync for LogNormal
impl Unpin for LogNormal
impl UnwindSafe for LogNormal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.