21 Random Number Generation and Simulation Statistics

You can generate random numbers from various continuous and discrete random variables. You can replicate samples, and apply either a set of predefined statistics or customized statistic (written using R code) to each sample.

21.1 Generating Random Samples

Instructions for generating random values from a distribution

  1. Open the Probability-Simulation toolbox on the left-hand side of the Rguroo window. Use the Probability dropdown menu and choose Multiple Distribution Generator. The Multiple Distribution Random Generator dialog opens (see Figure 21.1) .

  2. Click the plus icon plus button icon to generate a set of random numbers. You can type in a name in the textbox that appears. You can add more than one random variable by clicking on the plus icon plus button icon.

  3. From the Distribution dropdown, select the distribution from which you want to generate random values. In this example, we selected Binomial.

  4. Fill in the distribution parameters. For example, for the binomial, we fill in the No. of Trials and Probability of Success textboxes.

  5. Specify the Sample Size, number of times you want to replicate your sample (Replication), and a seed for the random generation.

  6. Click the Preview icon preview icon to view the result.

  7. (Optional) You can save the result as a stand-alone dataset by typing a name in the Save Dataset As textbox and clicking on the Save Dataset As button.

Rguroo Dialog
Multiple random genertor dialog

Figure 21.1: Multiple Distribution Random Generator Dialog

Output of random generation

Figure 21.2: Output of Random Generation

21.2 Applying Statistics to Selected Random Samples

You can apply statistics to the random samples you generate by selecting from a set of predefined standard statistics (e.g., mean, median. standard deviation, etc.) or by writing custom statistics using R code. In the example below, we compute the standard statistic mean and range for the three randomly generated samples of Section 21.1. Moreover, we write an R code to compute the midrange for the three samples.

Instructions for computing statistics oapplied to random samples

Continue the Rguroo instructions of Section 21.1.

  1. From the Statistic dropdown, select Mean and Range (see Figure 21.3) .

  2. To write custom statistics using R code, click on the Custom Statistic button. The Custom Statistic dialog opens.

  • Click the plus icon plus button icon to add a statistic. Name your statistic in the textbox that appears.
  • Type your R code on the right-hand side panel. Use lower case x to refer to the generated values (for example, min(x)).
  • You can write multiple lines of code. However, the result of your code, when applied to each replicate, must be a single number or character.
  1. Click the Preview icon preview icon to view the result.

  2. (Optional) You can save the result as a stand-alone dataset by typing a name in the Save Dataset As textbox and clicking on the Save Dataset As button.

Multiple random genertor dialog for computing statistics

Figure 21.3: Multiple Distribution Random Generator Dialog

Output of summary stats random generation