I am trying to numerically solve for parameters characterizing a lognormal distribution truncated from above with first moment = mean
, second moment = moment_2
, and upper
= 99th percentile of the untruncated distibution. This involves solving a constrained non-linear system of 2 equations and 2 unknowns. Currently I am having issues solving these equations numerically, and would appreciate any suggestions on the best solving technique to use.
I am trying to do this in R, and hence have expressed the equations as R functions. The desired parameters logmean
and logstd
can be recovered by solving the following system of 2 equations and 2 unknowns, which relate the first and second moments of the truncated distribution to the parameters logmean
and logstd
. Note that these equations have the PDF and CDF for a standard normal random variable in them written as dnorm
and pnorm
respectively.
mean_fun <-function(mean, logmean, logstd, upper = .99){
upper_lim <- qlnorm(upper, logmean, logstd)
b_0 <- (log(upper_lim) - logmean)/logstd
return(mean - exp(logmean+logstd^2/2)*pnorm(-logstd+b_0)/pnorm(b_0))
}
second_moment_fun <-function(moment_2, logmean, logstd, upper = .99){
upper_lim <- qlnorm(upper, logmean, logstd)
b_0 <- (log(upper_lim) - logmean)/logstd
return(moment_2 -exp(2*logmean+2*logstd^2)*pnorm(-2*logstd+b_0)/pnorm(b_0))
}
UPDATE: This can be consistently solved using R's nleqslv and by providing the jacobian. These equations and their derivation can also be found at this paper by searching for Example 21.75.