I want to pull random numbers from a Weibull distribution. The formulas for this use scale and shape parameters (both of which I have), but not a mean parameter. How can I 'build' a Weibull distribution that has a mean of my choosing?

Thank you

  • 1
    $\begingroup$ Please explain what it means to "have" both the scale and shape parameters. I find this statement puzzling here because if these parameters are somehow already determined--which is what "have" would suggest--then the mean is also determined (as its formula attests) and there is nothing you can do to change it. $\endgroup$
    – whuber
    Jun 2, 2014 at 15:57
  • $\begingroup$ @whuber - Yes I probably have a fundamental misunderstanding about how things work. You can see on the wikipedia page you referenced that there are lambda and k parameters. I have both of them, because there is a specific shape that I want the distribution to be. I want to keep that shape but change the average value. Is that what the location parameter is for? Thank you $\endgroup$
    – HorseHair
    Jun 2, 2014 at 16:30

4 Answers 4


You could either

(a) choose your mean and one other quantity (scale, shape), and solve for the two in terms of the available parameters


(b) reparameterize the Weibull to be in terms of the mean and one of the other parameters (essentially doing something like "(a)" for all possible choices of means).

(a) will be relatively easy if you only need to do it a few times. If you need to be able to solve it a potentially very large number of times, it may be worth trying to do (b).

Let's consider some specific examples, for which we'll need some parameterization. I'll use the one in the Wikipedia article on the Weibull:

$$f(x;\lambda,k) =\begin{cases}\frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}e^{-(x/\lambda)^{k}} & x\geq0 ,\\0 & x<0,\end{cases}\,.$$

It has mean $\lambda \Gamma\left(1+\frac{1}{k}\right)\,$.

a) so if you wanted say mean, $\mu= 10$ and shape parameter $k=3$, you'd have to solve $\lambda \Gamma\left(1+\frac{1}{3}\right)\, = 10$ for $\lambda$. Since $\Gamma(\frac{4}{3})\approx 0.893$, $\lambda\approx \frac{10}{0.893}\approx 11.2$.

b) if you wanted mean $\mu= 5$ and scale parameter $\lambda=5.5$ (*), you'd have to solve $\Gamma(1+\frac{1}{k}) = 5/5.5 = 0.9091$. There are two possible values of $k$ for which that's true:

enter image description here

So since $\Gamma(x) = \frac{5}{5.5}$, when $x\approx (1.23739896, 1.70237491)$, we need to solve $1+\frac{1}{k} = x$ for those values of $x$, i.e. $k = \frac{1}{x-1} \approx (0.8081, 0.5874)$.

* beware you don't choose incompatible mean and scale! The minimum of the gamma function, $\Gamma(1.46163..)\approx 0.8856$, so you can't have a scale more than about $1.12917$ times the mean (and this happens at $k\approx 2.166237$).

Note that we can relatively simply reparameterize the Weibull in terms of mean and shape (or very easily solve as above without reparameterizing), but to reparameterize for mean and scale would be considerably more involved (we'd effectively need an inverse of the gamma function or to solve the equation numerically), and we'd have to deal with two sets of solutions.

Edit: I see from comments you want to "keep the shape". That implies you want to specify $k$ and $\mu$. So that's like the first, simpler example - take the $k$ you have for the shape you want, and find

$$\lambda = \frac{\mu}{\Gamma(1+\frac{1}{k})}$$

and the resulting combination of scale $\lambda$ and shape $k$ will have the desired mean $\mu$.

  • $\begingroup$ Somehow I missed this answer yesterday, it's the most helpful. Thanks. $\endgroup$
    – HorseHair
    Jun 4, 2014 at 7:43
  • $\begingroup$ I even explicitly mentioned it to you on your other question - I was puzzled at how it didn't help. $\endgroup$
    – Glen_b
    Jun 4, 2014 at 8:23
  • 1
    $\begingroup$ Yes, your comment on the other question directed me back to here, where I saw this answer, and have just now successfully (I hope) used it to derive what I wanted. Thanks. $\endgroup$
    – HorseHair
    Jun 4, 2014 at 10:03

For simplicity, let's use the Weibull defined as the density whose distribution is: $$ \large F(x) = 1 - e^{-{\left(\frac{x}{\theta}\right)^\tau}} $$

Here $\theta$ is the scale and $\tau$ is the shape. This distribution has mean:$\;\theta\cdot\Gamma\left(1 + \frac{1}{\tau}\right)$ Which means (no pun intended) that there are potentially infinite choices of $(\theta, \tau)$ pairs which give the same mean, as you have one equation and two unknowns. For example, the Weibull distributions using both $(5, \frac{1}{4})$ and $(60, \frac{1}{2})$ have mean 120, but the former has a much higher variance.

To select a specific distribution, you would want to use method of moments to fit to the first two moments. This way, you will have at most one distribution which will match your requirements.


What do you mean by "mean parameter"? Does it "location parameter"?

Does your model look like this?

Then also you get the same CDF as explained in here. Just replace 'x' by '(x-γ)'. Where 'γ' is the location parameter. Then proceed as before.

  • $\begingroup$ Then, does the location parameter specify the mean for the distribution? $\endgroup$
    – HorseHair
    Jun 2, 2014 at 16:29
  • 2
    $\begingroup$ No; $\gamma$ is the minimum; that is explicit in the page cited. $\endgroup$
    – Nick Cox
    Jun 2, 2014 at 16:33

Brute-force search can find these parameters easily. Here's my code (R):

# Find the parameters of a Weibull distribution with a given mean and sd

objective_mean = 8.4
objective_sd = 3.8
objective = function(weibull_params) {
  scale = weibull_params[1]
  shape = weibull_params[2]
  weibull_mean = scale * gamma(1 + 1/shape)
  weibull_sd = sqrt((scale^2) * (gamma(1 + 2/shape) - gamma(1 + 1/shape)^2))
  return((objective_mean - weibull_mean)^2 + (objective_sd - weibull_sd)^2)
opt = nlminb(c(1, 1), objective, lower = c(0, 0), upper = c(1000, 1000))
scale = opt$par[1]
shape = opt$par[2]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.