Another way, which I believe will be a little more memory efficient
and time inefficient, though that might vary by machine, would be to
use replicate:

library(MASS)
set.seed(123)
m <- replicate(1000, coef(fitdistr(rweibull(50, 0.8, 2), "weibull")))
summary(t(m)) # Need to transpose here (or you could do it in the line
above, but it's already crowded)

I haven't tested my efficiency claims, but I'm pretty sure you gain on
the memory end because it runs each simulation sequentially and only
stores results, and you loose on the time end because you wind up
calling rweibull() 1000 times instead of once. If you are leaning
heavily on your memory bounds though, the time thing might be moot due
to paging effects.

Michael

On Fri, Jan 27, 2012 at 8:39 AM, Gabor Grothendieck
<ggrothendi...@gmail.com> wrote:
> On Fri, Jan 27, 2012 at 6:35 AM, Christopher Kelvin
> <chris_kelvin2...@yahoo.com> wrote:
>> Hello,
>> How can i do simulation with a weibull distribution after i have generated 
>> data with the distribution,
>> for example; if i generate x=rweibull(50,shape=0.8,scale=2) and i want to 
>> simulate this data 1000 times so that i can use it to estimate
>> the parameters.
>
> library(MASS)
> set.seed(123)
> n <- 1000
> k <- 50
> r <- matrix(rweibull(n*k, shape = 0.8, scale =2), k)
> m <- t(apply(r, 2, function(x) coef(fitdistr(x, "weibull"))))
> summary(m)
>
> Please use a meaningful subject on your posts to r-help and trim them
> so that they don't include the literally thousands of lines of garbage
> that were at the end of your post.
>
> ______________________________________________
> R-help@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.

______________________________________________
R-help@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.

Reply via email to