MASS fitdistr with plyr or data.table?
On Wed, Apr 27, 2011 at 3:55 PM, Justin Haynes <jtor14 at gmail.com> wrote:
I am trying to extract the shape and scale parameters of a wind speed
distribution for different sites. ?I can do this in a clunky way, but
I was hoping to find a way using data.table or plyr. ?However, when I
try I am met with the following:
set.seed(144)
weib.dist<-rweibull(10000,shape=3,scale=8)
weib.test<-data.table(cbind(1:10,weib.dist))
names(weib.test)<-c('site','wind_speed')
fitted<-weib.test[,fitdistr(wind_speed,'weibull'),by=site]
Error in class(ans[[length(byval) + jj]]) = class(testj[[jj]]) :
?invalid to set the class to matrix unless the dimension attribute is
of length 2 (was 0)
In addition: Warning messages:
1: In dweibull(x, shape, scale, log) : NaNs produced
...
10: In dweibull(x, shape, scale, log) : NaNs produced
(the warning messages are normal from what I can tell)
or using plyr:
set.seed(144)
weib.dist<-rweibull(10000,shape=3,scale=8)
weib.test.too<-data.frame(cbind(1:10,weib.dist))
names(weib.test.too)<-c('site','wind_speed')
fitted<-ddply(weib.test.too,.(site),fitdistr,'weibull')
Well fitdistr doesn't return a data frame, so you need to do something to its output... Hadley
Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/