Given a random sample $X_1,X_2,\dots,X_n$ from a density $f(x)$ and cdf $F(x)$, the joint density of the sample minimum and maximum is
$$
f_{X_{(1)},X_{(n)}}(x_1,x_n)=\frac{n!}{(n-2)!}f(x_1)f(x_n)[F(x_n)-F(x_1)]^{n-2}.
$$
Based on the central limit theorem, unless $n$ is small or $\sigma$ large, the distribution of the sample mean $\bar X$ conditional on $X_{(1)}=x_1$ and $X_{(n)}=x_n$ should be well approximated by a normal distribution with the appropriate mean and variance (derived from the mean and variance of the truncated lognormal distribution of the observations in-between the minimum and maximum $x_1$ and $x_n$). The likelihood based on observations $x_{1},x_{n},\bar x$ is then
$$
L(\mu,\sigma) = f_{X_{(1)},X_{(n)}}(x_1,x_n)f_{\bar X|X_{(1)}=x_1,X_{(n)}=x_n}(\bar x)
$$
which you can maximise numerically with respect to $\mu$ and $\sigma$.
R implementation:
lnormpar <- function(x1, xn, xbar, n, start=c(0,1)) {
# negative log likelihood
nll <- function(theta) {
mu <- theta[1]
sigma <- theta[2]
z1 <- (log(x1)-mu)/sigma
z2 <- (log(xn)-mu)/sigma
# mean and variance of (x_1,x_n)-truncated lognormal
mu1.trunc <- exp(mu + sigma^2/2)*
(pnorm(z2 - sigma) - pnorm(z1 - sigma))/
(pnorm(z2) - pnorm(z1))
mu2.trunc <- exp(2*mu + 2*sigma^2)*
(pnorm(z2 - 2*sigma) - pnorm(z1 - 2*sigma))/
(pnorm(z2) - pnorm(z1))
var.trunc <- mu2.trunc - mu1.trunc^2
# joint density of x1, xn, xbar
ll <-
sum(dlnorm(c(x1,xn), mu, sigma, log=TRUE)) +
(n-2)*log(plnorm(xn, mu, sigma) - plnorm(x1, mu,sigma)) +
dnorm(xbar, (x1 + xn + (n-2)*mu1.trunc)/n, sqrt(var.trunc/(n-2)), log=TRUE)
-ll
}
# maximise the log likelihood
opt <- optim(start, nll, hessian=TRUE)
# extract parameter estimates
res <- cbind(opt$par, sqrt(diag(solve(opt$hessian))))
rownames(res) <- c("mu","sigma")
colnames(res) <- c("Estimate","Std. Error")
res
}
The result assuming a sample size of $n=10$:
> lnormpar(x1=100,xn=10000,xbar=1000,n=10)
Estimate Std. Error
mu 6.489252 0.5747346
sigma 1.409383 0.3306496
As you are interested in modeling percentiles, you should have a look at quantile regression methods. Instead of modeling conditional means (as in linear regression), quantile regression allows you to model (conditional) quantiles.
As mentioned in the comments, a good introduction to quantile regression is the vignette to the quantreg R package. One of the examples in the vignette illustrates your use case:
Best Answer
I am not sure if this question belongs to stats.stackexchange. Anyhow you don't need to write any function! Here is how to generate a random sample from a lognormal distribution and then estimate parameters in R.