R Programming: Introduction to Pseudo-Random Number Generators -- runif() and sample()

preview_player
Показать описание
This video is an introduction to methods that generate pseudo-random numbers in R programming. Our R Script starts using the method runif() where the "r" stands for "random" and the "unif" stands for "uniform" -- meaning the numbers are drawn from a uniform distribution (as opposed for instance drawing numbers from a normal distribution). The three arguments in the method runif(100,0,1) mean that we are generating 100 numbers that fall between 0 and 1. The method outputs a vector and the individual numbers can be called data points or elements or components. We applied some of R's statistical methods to the data set: mean(), sd(), median(), quantile(). Next we use R's ifelse method to convert the vector into a coin-toss simulation. Another way to achieve the same end is to use R's sample() method. In the example we show, the sample method has three arguments: 1) the set we are sampling or pulling from, 2) how many samples we are pulling, and 3) the replace argument which determine whether or not we can obtain duplicate values. We use the table() method to count the frequencies of the sample data set. To illustrate the difference between replace=true and replace=false, we compare picking a daily lottery number to picking a "lotto" numbers. We next use sample() to simulate the rolling of a die. We visualize the distribution using the hist() method. We finally consider the breaks argument of the hist() method that allows us some control over the histogram.
Рекомендации по теме
visit shbcf.ru