Lo 2012 reports an approximation for the difference of two random variables by a shifted lognormal distribution.
Rather than approximating the density of \(y = a - b\), it approximates the density of \(y_s = a - b + s\), where \(s\) is the shift. Hence, one has to subtract \(s\) from provided mean and quantiles. One can can use the variance, and relative error but has to recompute the relative error.
The probability of the zero quantile needs to be larger than a significance level. We can compute it based on the lognormal approximation.
Since Lo12 is only accurate if the expected difference is small compared to the expected sum, the probability of the difference being larger than zero can be estimated by a sampling both terms.
= log(120) mu1 = log(60) mu2 = 0.25 sigma1 = 0.15 sigma2 <- estimateDiffLognormal( mu1,mu2,sigma1,sigma2, corr = -0.8 ) coefDiff
## Warning in estimateDiffLognormal(mu1, mu2, sigma1, sigma2, corr = -0.8): ## Expected S0+/S0- << 1 but this ratio was 0.34219239671082. The Lo 2012 ## approximation becomes inaccurate for small numbers a and b.
<- plnorm(0 + coefDiff["shift"], coefDiff["mu"], coefDiff["sigma"]) pLo <- pDiffLognormalSample(mu1,mu2,sigma1,sigma2, corr = -0.8) pSample
## Loading required namespace: mvtnorm
c(pLo = as.numeric(pLo), pSample = pSample)
## pLo pSample ## 0.04540137 0.03449000
In the example both approaches give a probability of less than 5% so that we conclude that the difference is significant.
The method of Lo12 requires \(\sigma_b < \sigma_a\) and otherwise gives an error.
# generate nSample values of two lognormal random variables = log(110) mu1 = log(100) mu2 = 0.15 sigma1 = 0.25 sigma2 try(coefDiff <- estimateDiffLognormal(mu1,mu2, sigma1,sigma2, 0))
## Error in estimateDiffLognormal(mu1, mu2, sigma1, sigma2, 0) : ## expected sigma_a > sigma_b but got 0.15 <= 0.25. Exchange the terms and negate the resulting quantiles (see vignette('lognormalDiff').
But one can compute the density of \(y_r = -y = b - a\) and plot the density of the shifted and negated distribution.
# note the switch of positions of mu1 and mu2: mu2 - mu1 #(coefDiff <- estimateDiffLognormal(mu1,mu2, sigma1,sigma2, 0) <- estimateDiffLognormal(mu2,mu1, sigma2,sigma1, 0))(coefDiff
## mu sigma shift ## 6.10147970 0.06859943 455.64000921
# note the minus sign in front <- -(getLognormMoments( (expDiff "mu"], coefDiff["sigma"], shift = coefDiff["shift"])[,"mean"])) coefDiff[
## mean ## 8.070146
<- seq(0,1,length.out = 100)[-c(1,100)] p <- data.frame( dsPredY var = "y", q_shifted_neg = qlnorm(p, coefDiff["mu"], coefDiff["sigma"] ) %>% ) mutate( # note the minus sign in front q = -(q_shifted_neg - coefDiff["shift"]), d = dlnorm(q_shifted_neg, coefDiff["mu"], coefDiff["sigma"]) )
Because we subtract a large-variance lognormal variable, the distribution becomes right-skewed.