Brighton Webs Ltd.
Data & Analysis Services for Industry & Education
Home
Index
Feedback

Weibull Distribution (Two Parameter)

The Weibull distribution is a special case of the Generalized Extreme Value distribution.  It has been extensively used as a model of time to failure of manufactured items and has become one of the principal tools of reliability engineering.  The applications of the Weibull distribution have expanded and include finance and climatology.

The distribution is named after the Swedish engineer Wallodi Weibull.

Profile

Parameters

Parameter Description Characteristics
scale defines the range and practical maximum.  Also known as the characteristic life. A float > -∞ and < ∞
shape Determines the profile of the distribution. A float > 0

Range

The range is from greater than zero to positive infinity.  However, in practice the right tail is classed as thin/light or bounded.

Functions

Properties

Random Number Generation

Random number generation (referred to as r) for a Weibull distribution can be performed by transforming a continuous uniform variable in the range 0 to 1 (referred to as u) with the distribution's inverse probability function:

r=g(u)

which can be reduced to:

Using Basic style code, the function would be similar to:

r = scale * (-log(rnd))^(1/shape)

and in VB.net style:

r = scale * Math.Pow(-Math.Log(Rnd()), 1 / Shape)

Parameter Estimation

The maximum likelihood equations can be expressed in the form:

These can be solved to obtain the shape and scale factors.  The vb.net code below uses successive bisection to solve the equation for shape factor which is plugged into the formula for scale.  Anyone considering using this code, should first determine if it is fit for purpose, especially with regard to convergence, over-flow and computing efficiency:

Some test code is included which generates an array of random numbers according to the scale and shape factors, weibullML is then called to estimate the parameters from the array of random numbers:

Test Code:

'Declarations - Loop counter

Dim intI As Integer = 0

'Declarations - Shape and Scale to test data

Dim dblScale As Double = 100
Dim dblShape As Double = 2.0

'Array for random numbers

Dim dblX(999) As Double

'Randomize

Randomize()

'Random Numbers

For intI = 0 To dblX.GetUpperBound(0)

dblX(intI) = dblScale * Math.Pow(-Math.Log(Rnd()), 1 / dblShape)

Next

'Successive Bisection

If WeibullML(dblX, dblShape, dblScale) Then

'The equation for shape converged

Else

'The equation for shape did NOT converge

End If

Solution of Equations

Private Function WeibullML(ByRef dblX() As Double, _
                                         ByRef dblShape As Double, _
                                         ByRef dblScale As Double) As Boolean

'Returns true if the equation for shape factor converges
'within the number of iterations set by IMax.

'Declarations - Loops,

Dim intI As Integer = 0 'Interation Counter

Dim intIMax As Integer = 20 'Maximum Interations

Dim intJ As Integer = 0

'Declarations - Initial estimates of shape factor

Dim dblL As Double = 0

Dim dblR As Double = 100

'Declarations - Tolerance

Dim dblF As Double

Dim dblTol As Double = 0.01

'Declarations - Intermediate variables

Dim dblA As Double

Dim dblB As Double

Dim dblC As Double = 0

Dim dblP As Double

'Evaluate the term which does not depend on shape

For intJ = 0 To dblX.GetUpperBound(0)

dblC = dblC + Math.Log(dblX(intJ))

Next

'Successive Bisection

Do While intI < intIMax

'Initialise

dblA = 0

dblB = 0

'Estimate of Shape

dblShape = (dblL + dblR) / 2

'Intermediates

For intJ = 0 To dblX.GetUpperBound(0)

dblP = Math.Pow(dblX(intJ), dblShape)

dblA = dblA + dblP

dblB = dblB + dblP * Math.Log(dblX(intJ))

Next

'Evaluate function

dblF = (dblB / dblA - dblC / (dblX.GetUpperBound(0) + 1) - 1 / dblShape)

'Swap

If dblF > dblTol Then

dblR = dblShape

ElseIf dblF < -dblTol Then

dblL = dblShape

Else

'the equation for scale has converged, calculate scale and exit

dblScale = Math.Pow(dblA / (dblX.GetUpperBound(0) + 1), 1 / dblShape)

Return True

End If

'increment counter

intI = intI + 1

Loop

'Convergence did not take place

Return False

End function

Page Updated: 12-May-2008

 

For more information: info@brighton-webs.co.uk