Simulating a distribution in R?

  • Thread starter Thread starter moonman239
  • Start date Start date
  • Tags Tags
    Distribution
moonman239
Messages
276
Reaction score
0
I have a dataset in R. What I want to do is simulate a variable that holds the same distribution. How do I do this?
 
Physics news on Phys.org
Are you interested in a computer simulation? Look up Monte Carlo method.
 
mathman said:
Are you interested in a computer simulation?

Yes

mathman said:
Look up Monte Carlo method.

I know about Monte Carlo simulations.
 
moonman239 said:
I have a dataset in R. What I want to do is simulate a variable that holds the same distribution. How do I do this?

You need a random number generator where you can specify the distribution parameters for N simulations. Of course the simulated distribution parameters will only match your template on average. I worked with simulations in Minitab where you could specify four moments of a normal distributions and also for a few others such as the Poisson and binomial. You can write your own programs by using the PDFs and MGFs with randomly generated parameters (ie simulated random sample means around a specified population mean) if you like doing that sort of thing.
 
Last edited:
SW VandeCarr said:
You need a random number generator where you can specify the distribution parameters for N simulations.

I know. Is there a function to do that in R? I know you can simulate variables from widely-known distributions (normal, Poisson, uniform, chi-square, etc.)
 
moonman239 said:
I know. Is there a function to do that in R? I know you can simulate variables from widely-known distributions (normal, Poisson, uniform, chi-square, etc.)

A good stats package should have this ability. I don't specifically know about R. Did you check commands that begin with RAND?
 
Anything else? I don't think that helped. Thanks, anyways.
 
Rather than trying to estimate the distribution from which the data was drawn, and to then use that (parameterized) distribution to simulate from(involving random number generators), you can just bootstrap sample straight from the observed data, i.e., just keep resampling, with or without replacement (with to get iid sampling) from the observed data. Look at the function: sample(), then there's more sophisticated boot() functions too.
 
Back
Top