# Analysing wind data with R

Hi i am analaysing wind data for estimating energy from a wind turbine.
I have taken 10 years of wind data and graphed a histogram;
my second stage was to fit a Weibull distribution to the data.
I used R with the package lmom to compute the Weibul shape and scale this is the code i used:

>library(lmom)
wind.moments<-samlmu(as.numeric(pp$WS)) moments<-pelwei(wind.moments) x.wei<-rweibull(n=length(pp$WS), shape=moments["delta"], scale=moments["beta"])
hist(as.numeric(pp\$WS), freq=FALSE)
lines(density(x.wei), col="red", lwd=4)


It seems like there is some lag between the data and the density function; can you help me with this? Another question is can you help me in calculating the anual energy from the density function?

thank you

• About the picture, post to some image hosting and put a link -- I'll convert it into a pasted-in picture. – user88 Feb 13 '11 at 8:35
• +1, interesting question, you might find that soon you will have enough reputation :) – mpiktas Feb 13 '11 at 8:46
• judging from the graph, the problem is not the lag. What you have plotted is roughly goodness of fit. So it seems that Weibull distribution is not apropriate for your data. I see that there is a bunch up near zero, do you have zero values in your data? In that case you will need to model zero values separately. So first suggestion would be to try Weibull for non zero values. Also why Weibull, is there particular reason, some reference from similar work perhaps? – mpiktas Feb 13 '11 at 9:02
• note that 'lag' is a term used mainly in analysis of data in time, referring to one thing occurring after another. This isn't a lag - it's perhaps more accurately called a shift - or maybe an offset - but shift is probably more common for distributions, they shift and scale. – Spacedman Feb 13 '11 at 10:28
• be careful about using as.numeric(x) with factors; you actually want to use as.numeric(as.character(x)) to make sure you get the right number value for the factor. – Andy Clifton Oct 16 '16 at 23:10

lmom function pelwei fits a three parameter Weibull distribution, with location, scale and shape parameters. rweibull generates random numbers for a two-parameter Weibull distribution. You need to subtract the location parameter moments["zeta"]. That should give a better fit, but it doesn't appear it will give a good fit to your particular data.

I notice http://www.reuk.co.uk/Wind-Speed-Distribution-Weibull.htm says "Wind speeds in most of the world can be modelled using the Weibull Distribution.". Perhaps you're just unlucky and live in a part of the world where they can't!

• do you tink you can help me with my second question: calculating wind energy based on the density function? – eliavs Feb 13 '11 at 11:05
• I'm not a physicist and I don't know the necessary equations, but I imagine it will involve a numerical integral over the density. R's integrate() function may be useful for that. – onestop Feb 13 '11 at 12:48
• i know the equation my problam is i want to compute the percent of time the wind is at each speed – eliavs Feb 13 '11 at 14:18
• what i meAn is can you help me with the integration --> thank you – eliavs Feb 13 '11 at 14:45

I recreated your plot with data from http://hawaii.gov/dbedt/ert/winddata/krab0192.txt (I took the 1200 measurements). I got a decent fit of the data, generally using your code:

library(lmom)

wind.avg <- na.omit(as.numeric(daten[,"X12"]))
wind.moments<-samlmu(wind.avg)
moments<-pelwei(wind.moments)
x.wei<-rweibull(n=length(wind.avg), shape=moments["delta"], scale=moments["beta"])
hist(as.numeric(wind.avg), freq=FALSE)
lines(density(x.wei), col="red", lwd=4)


Sorry, I'm not shure were your problem could be, but I think you should be able to fit weibull to your data. What makes me suspicious is the bell-curve of your density plot, I have no idea where that came from.

Here are the moments I generated:

wind.moments

       l_1         l_2         t_3         t_4
15.17287544  4.80372580  0.14963501  0.06954438


moments

     zeta      beta     delta
0.516201 16.454233  1.745413


WTR to the annual output: I suppose I'd generate discrete values for the probability density function, multiply these values with the output function and sum it up. Alternatively, you could just use your raw data, multiply the values with the output function, sum it up and calculate the annual average, you should control for seasonality in a suitable way (e. g. make sure to use whole years, or to weight accordingly).

Here is the uncontrolled output (using the formula from http://www.articlesbase.com/diy-articles/determining-wind-turbine-annual-power-output-a-simple-formula-based-upon-blade-diameter-and-average-wind-speed-at-your-location-513080.html)

years  <- length(wind.avg)/365
diameter <- 150
Power = (0.01328*diameter^2)*((wind.avg)^3)
(annual.power <- sum(Power)/years)
[1] 791828306


Here's a recent post at SO on wind turbines. My answer on that link has three links that you might be interested in:

https://stackoverflow.com/questions/4843194/r-language-sorting-data-into-ranges-averaging-ignore-outliers/4844783#4844783

I just checked one of the Weibull links in the above SO answer. For some reason, the link is down. Here are some links that provide the same basic information:

http://www.gso.uri.edu/ozone/

http://www.weru.ksu.edu/new_weru/publications/pdf/Comparison%20of%20the%20Weibull%20model%20with%20measured%20wind%20speed%20distributions%20for%20stochastic%20wind%20genera.pdf

http://www.kfupm.edu.sa/ri/publication/cer/41_JP_Weibull_parameters_for_wind_speed_distribution_in_Saudi_Arabia.pdf

http://journal.dogus.edu.tr/13026739/2008/cilt9/sayi1/M00195.pdf

http://www.eurojournals.com/ejsr_26_1_01.pdf

Also, from the power generated from wind, the seasonality is obvious.

I'm not sure if somebody has already made this point, but pelwei can actually be forced to work as a 2 parameter weibull function by adding in a fixed bound.

Insead of calling moments<-pelwei(wind.moments) you should simply call moments<-pelwei(wind.moments,bound=0)

you can always check what the zeta value is. If it's not 0 and you're using dweibull, you need to do something about it.