# How can I determine weibull parameters from data?

I have a histogram of wind speed data which is often represented using a weibull distribution. I would like to calculate the weibull shape and scale factors which give the best fit to the histogram.

I need a numerical solution (as opposed to graphic solutions) because the goal is to determine the weibull form programmatically.

Edit: Samples are collected every 10 minutes, the wind speed is averaged over the 10 minutes. Samples also include the maximum and minimum wind speed recorded during each interval which are ignored at present but I would like to incorporate later. Bin width is 0.5 m/s • when you say you have the histogram - do you mean also have the information about the observations or do you ONLY know the bin width and height? – suncoolsu Mar 30 '11 at 11:10
• @suncoolsu I have all data points. Datasets ranging from 5,000 to 50,000 records. – klonq Mar 30 '11 at 11:12
• Couldn't you take a random sample of the data and perform a MLE of the parameters? – schenectady Mar 30 '11 at 11:30
• What's the purpose of the estimation? To retrospectively characterize past conditions? To predict future power generation at one location? To predict power generation within a grid of turbines? To calibrate a meteorological model? Etc. For this question, determining an appropriate solution depends critically on how it will be used. – whuber Mar 30 '11 at 17:22
• @whuber at present the idea is to summarise wind data sets in a form allowing comparison from period to period and/or site to site. Later the goal will be compare trends and as you say to form judgements as to future production, etc. I am very much a newbie to stats but I have a mountain of data (which I can't share) and would like to extract as much information from it as possible. If you can point me to any reading on this subject it would be much appreciated. – klonq Mar 31 '11 at 7:02

Maximum Likelihood Estimation of Weibull parameters may be a good idea in your case. A form of Weibull distribution looks like this:

$$(\gamma / \theta) (x)^{\gamma-1}\exp(-x^{\gamma}/\theta)$$

Where $\theta, \gamma > 0$ are parameters. Given observations $X_1, \ldots, X_n$, the log-likelihood function is

$$L(\theta, \gamma)=\displaystyle \sum_{i=1}^{n}\log f(X_i| \theta, \gamma)$$

One "programming based" solution would be optimize this function using constrained optimization. Solving for optimum solution:

$$\frac {\partial \log L} {\partial \gamma} = \frac{n}{\gamma} + \sum_1^n \log x_i - \frac{1}{\theta}\sum_1^nx_i^{\gamma}\log x_i = 0$$ $$\frac {\partial \log L} {\partial \theta} = -\frac{n}{\theta} + \frac{1}{\theta^2}\sum_1^nx_i^{\gamma}=0$$

On eliminating $\theta$ we get:

$$\Bigg[ \frac {\sum_1^n x_i^{\gamma} \log x_i}{\sum_1^n x_i^{\gamma}} - \frac {1}{\gamma}\Bigg]=\frac{1}{n}\sum_1^n \log x_i$$

Now this can be solved for ML estimate $\hat \gamma$. This can be accomplished with the aid of standard iterative procedures which solve are used to find the solution of equation such as -- Newton-Raphson or other numerical procedures.

Now $\theta$ can be found in terms of $\hat \gamma$ as:

$$\hat \theta = \frac {\sum_1^n x_i^{\hat \gamma}}{n}$$

• One thing I would be cautious of is that it sounds like we have time-series data here. If the data are sampled over a short time frame, assuming independence could be hazardous. That said, (+1). – cardinal Mar 30 '11 at 13:09
• @cardinal Please explain. The data ranges over the course of a month or up to a year, but sampled regularly (10 minutes). What might this imply? – klonq Mar 30 '11 at 13:48
• @cardinal Thanks for pointing it out. I wasn't sure either if independence assumption is appropriate. – suncoolsu Mar 30 '11 at 13:58
• @klonq, how is the sample taken? Is it the average speed over the ten minutes between recordings? Over one minute prior to recording? The instantaneous speed at the time of recording? Mostly I'd be looking for serial correlations, which could reduce your effective sample size considerably. Using an ML estimate based on an assumption of independent samples may or may not still give you a good estimate in that context, and special care should be taken regarding any inference based on the estimate. Suncoolsu's approach definitely provides a first line of attack, though. – cardinal Mar 30 '11 at 14:06
• @klonq -- If possible, can you please describe how was your sample collected? What does the data look like? – suncoolsu Mar 30 '11 at 14:13

Use fitdistrplus:

Need help identifying a distribution by its histogram

Here's an example of how the Weibull Distribution is fit:

library(fitdistrplus)

#Generate fake data
shape <- 1.9
x <- rweibull(n=1000, shape=shape, scale=1)

#Fit x data with fitdist
fit.w <- fitdist(x, "weibull")
summary(fit.w)
plot(fit.w)

Fitting of the distribution ' weibull ' by maximum likelihood
Parameters :
estimate Std. Error
shape 1.8720133 0.04596699
scale 0.9976703 0.01776794
Loglikelihood:  -636.1181   AIC:  1276.236   BIC:  1286.052
Correlation matrix:
shape     scale
shape 1.0000000 0.3166085
scale 0.3166085 1.0000000 • Thanks, but I am trying to find a solution in Java. – klonq Mar 30 '11 at 14:40
• any pointers in R coding to get shape and scale factors? Thanks. – user56416 Sep 25 '14 at 9:32