[R] Optimization failed in fitdistr (Weibull distribution)

peter dalgaard pdalgd at gmail.com
Tue Oct 29 07:44:49 CET 2013


On 28 Oct 2013, at 13:07 , kmmoon100 <k.moon at student.unimelb.edu.au> wrote:

> Hello everyone,
> 
> This is Kangmin.
> 
> I am trying to produce shape and scale of my wind data. My data is based on
> wind speed frequency with 1km/hr increment. data is described below.
> 
> Windspeed (km/h)    Frequency
> 1	351
> 2	147
> 3	317
> 4	378
> 5	527
> 6	667
> 7	865
> 8	970
> 9	987
> 10	907
> 11	905
> 12	642
> 13	1000
> 14	983
> 15	847
> 16	842
> 17	757
> 18	698
> 19	632
> 20	626
> 21	599
> 22	529
> 23	325
> 24	391
> 25	356
> 26	267
> 27	230
> 28	223
> 29	190
> 30	142
> 31	124
> 32	104
> 33	97
> 34	37
> 35	62
> 36	46
> 37	42
> 38	24
> 39	9
> 40	13
> 41	9
> 42	5
> 43	2
> 
> R codes to calculate shape and scale are described below:
> 
> Pine.windfrequency.4weeks<-read.table("C:/Users/kmoon/Documents/Pine_frequency_4weeks.csv",header=TRUE,sep=",")
> fitdistr(Pine.windfrequency.4weeks$Frequency, densfun="weibull")
> 
> I have got an error message when I was using 'fitdistr' function
> 
> "Error in fitdistr(Pine.windfrequency.4weeks$Frequency, densfun = "weibull")
> : 
>  optimization failed"
> 
> Please help me calculating shape and scale of weibull distribution.
> 
> And please understand that I am not an user familiar with R program but I am
> really trying to make my analysis work on R!

There really is no substitute for knowledge and understanding! Did it not occur to you that the Windspeed column needs to enter into your analysis? 

I suppose you wanted the following:

> tt<-read.delim("/tmp/foo")
> summary(tt)
 Windspeed..km.h.   Frequency     
 Min.   : 1.0     Min.   :   2.0  
 1st Qu.:11.5     1st Qu.: 100.5  
 Median :22.0     Median : 351.0  
 Mean   :22.0     Mean   : 415.7  
 3rd Qu.:32.5     3rd Qu.: 682.5  
 Max.   :43.0     Max.   :1000.0  
> x <- rep(tt$Windspeed..km.h., tt$Frequency)
> library(MASS) 
> fitdistr(x, densfun="weibull")
      shape         scale   
   1.99900495   16.43640142 
 ( 0.01174133) ( 0.06468371)
Warning messages:
1: In densfun(x, parm[1], parm[2], ...) : NaNs produced
2: In densfun(x, parm[1], parm[2], ...) : NaNs produced
3: In densfun(x, parm[1], parm[2], ...) : NaNs produced
4: In densfun(x, parm[1], parm[2], ...)


> 
> Thank you!!!
> 
> Kangmin.
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-failed-in-fitdistr-Weibull-distribution-tp4679167.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list