> (apropos '-rand) -RAND F-RAND BINOMIAL-RAND MAKE-RANDOM-STATE GAMMA-RAND T-RAND NORMAL-RAND CAUCHY-RAND CHISQ-RAND UNIFORM-RAND POISSON-RAND BETA-RAND
These generators are accompanied by
> (apropos 'poisson) POISSON POISSONREG-MODEL POISSON-PMF POISSON-QUANT POISSON-CDF POISSON-RAND
You will need to be careful in how you save the seed, however. Consider the following output (generated in the new release 3.48 of LispStat on a Macintosh).
> *random-state* #$(1 #(2147483562 0 44830 4924)) > (setf saveSeed *random-state*) #$(1 #(2147483562 0 44830 4924)) > (uniform-rand 5) (0.742012 0.638736 0.703512 0.3317438 0.079660) > *random-state* #$(1 #(2147483562 171069757 327390122 156320365)) > saveSeed #$(1 #(2147483562 171069757 327390122 156320365))
Can you explain what has happened?
The way to save a copy of the seed that will not change is to use the make-random-state function. This same function can also be used to initialize the seed, typically using some function relying upon the internal clock in the computer you're using.
> (setf saveSeed (make-random-state *random-state*)) #$(1 #(2147483562 171069757 327390122 156320365)) > (uniform-rand 3) (0.18446831 0.336059123 0.22523372) > *random-state* #$(1 #(2147483562 483685715 100858525 1764656372)) > saveseed #$(1 #(2147483562 171069757 327390122 156320365)) > (setf *random-state* (make-random-state t)) ; init from clock #$(1 #(2147483562 0 44830 5893))
Written informally, here's the code. This code will save all of the values that are generated, not just some summary statistics. This a useful since you can then do some data analysis using the simulated values.
(setf stat ()) (dotimes (i nReps) (generate random numbers of chosen distribution and sample size) (evaluate statistic with this data) (push the statistic on the list stat) ) (analyze results)This is so general, we can write a function that will write this function for us.
Finally, once the simulation has been run, the simulation values (rather than a few summary statistics) are available for analysis using all of the LispStat statistical procedures (eg compare, scatterplot-matrix, etc).
The key thing that we need to bootstrap a statistic is a way of sampling with replacement from a list of values. Fortunately, LispStat has the sample function we need:
> (sample (iseq 10) 10) ; without replacement (3 1 0 6 5 7 4 9 2 8) > (sample (iseq 10) 10 t) ; WITH replacement (6 6 5 6 5 6 2 1 8 0)
This problem fits our prior style of simulation and so we can exploit the same code to bootstrap a statistic, emphasizing the linkage between resampling and simulation.