kmmoon100
2014-Feb-26 11:20 UTC
[R] Error message in `fitdistr` function in the MASS package
I have one issue at the moment while I am using a function, fitdistr in package MASS. I have 12 years of wind data with 30 min average interval. My data look like below: Time windspeed 1/01/2005 0:00 15 1/01/2005 0:30 11 1/01/2005 1:00 11 1/01/2005 1:30 13 1/01/2005 2:00 15 1/01/2005 2:30 13 1/01/2005 3:00 13 1/01/2005 3:30 13 1/01/2005 4:00 15 1/01/2005 4:30 17 1/01/2005 5:00 17 1/01/2005 5:30 15 1/01/2005 6:00 13 1/01/2005 6:30 13 1/01/2005 7:00 15 1/01/2005 7:30 18 1/01/2005 8:00 18 1/01/2005 8:30 21 1/01/2005 9:00 21 1/01/2005 9:30 22 1/01/2005 10:00 24 1/01/2005 10:30 26 1/01/2005 11:00 24 1/01/2005 11:30 24 1/01/2005 12:00 24 1/01/2005 12:30 24 1/01/2005 13:00 17 1/01/2005 13:30 18 1/01/2005 14:00 21 1/01/2005 14:30 21 1/01/2005 15:00 22 1/01/2005 15:30 24 1/01/2005 16:00 24 1/01/2005 16:30 24 1/01/2005 17:00 21 1/01/2005 17:30 24 1/01/2005 18:00 22 1/01/2005 18:30 22 1/01/2005 19:00 21 1/01/2005 19:30 21 1/01/2005 20:00 15 1/01/2005 20:30 11 1/01/2005 21:00 13 My intention of using this function is to get daily Weibull parameters (shape and scale) but it keeps giving me errors. The code I put was: walpeup_alldata <- read.csv("walpeup_excercise.csv", header=TRUE, sep=",") walpeup_alldata$Date <- as.POSIXct(walpeup_alldata$Time, format = "%d/%m/%Y %H:%M", tz = "Australia/Melbourne") walpeup_alldata$day_index <- paste(format(walpeup_alldata$Date, "%Y"), format(walpeup_alldata$Date, "%j"), sep "_") walpeup_aggregation <- aggregate(walpeup_alldata$windspeed, by=list(walpeup_alldata$day__index), FUN= function(x) {fitdistr(x, densfun="weibull")} ) Interesting thing is when I used short duration of wind data, the code works but produces lots of residuals. The residuals are like this. 33 2005_033 c(4.75967037103778, 36.0492072865698) 34 2005_034 c(7.71303917850763, 35.3491854177213) 35 2005_035 c(5.68407836144938, 28.721154798025) 36 c(0.485695856927515, 0.720482566441891) 37 c(0.479982752982148, 0.605561818452758) 38 c(0.398017326464339, 0.975977176044699) 39 c(0.603493688481038, 1.04186250740921) 40 c(0.787847162718371, 0.600969267921991) 71 c(0.235900465436553, 0.110092730139038, 0.110092730139038, 0.519095128546693) 72 c(0.230383443160322, 0.094083878067012, 0.094083878067012, 0.366705115967811) 73 c(0.15841779216582, 0.127050034063599, 0.127050034063599, 0.952531448160185) 106 -144.261676847584 107 -134.931368456724 108 -155.386471593028 109 -163.984332061118 172 48 173 48 174 48 175 48 However when I increase size of the data by more than few months, it starts not to work again with providing below error message. *Error in fitdistr(x, densfun = "weibull") : optimization failed In addition: There were 50 or more warnings (use warnings() to see the first 50)* I have taken out all zero values in advance. It worked well for another dataset. I don't know what the cause and the solution for the data are at the moment. Thank you for your attention. -- View this message in context: http://r.789695.n4.nabble.com/Error-message-in-fitdistr-function-in-the-MASS-package-tp4685862.html Sent from the R help mailing list archive at Nabble.com.