[R] Simulations / repetitions help!

Lauren_G lgxlg1 at nottingham.ac.uk
Wed Sep 24 16:42:56 CEST 2008

Dear all,

My question concerns using repetitions and simulations (loops?) in R.  I am
very new R user, so any help that can be offered would be greatly

I am using fitdistr() to determine the distribution of empirical univariate
datasets, and ks.test to assess the goodness of fit.  Because the null
distribution of the KS statistic is not known when the distribution
parameters are estimated from the data I would like to use simulations to
generate a more accurate p-value (following the methods explained in the
second to last paragraph on page 11 of Clauset et al. [2007] available at
http://arxiv.org/abs/0706.1062 - also attached)


I would like to generate a random dataset (‘x’) from a distribution (e.g.


calculate the parameters of the best-fit distribution:

      shape          scale    
  14.872762181    1.098046257  
 ( 0.250069835) ( 0.002030626)

 and assess the goodness-of-fit of ‘x’ to this best-fit distribution.  

data:  x 
D = 0.215, p-value < 2.2e-16
alternative hypothesis: two-sided 

I would like to repeat this c.500 times using a new random dataset each
time, calculating D for each dataset relative to its own best fit model
(i.e. using the parameters generated by fitdistr each time).  As a final
output I would like a matrix listing all 500 D values.  

I am very new to R, so any advice anyone could give me (no matter how simple
it may seem) would be greatly appreciated!

Many thanks

View this message in context: http://www.nabble.com/Simulations---repetitions-help%21-tp19648673p19648673.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list