If you look closely at the results, you’ll notice that they are identical. Look back at the last three calls of sample() above. Sometimes this is exactly what you want, but other times you will want a random result that you generate to be reproducible by others. That is, every time you call the function, unless otherwise specified, the result will be different from the last time you called it. There is one more detail about sample() that is very important for us to be aware of: its results are random. Therefore in order to get sample() to draw 10 times from coin, we need to change the value of replace to TRUE.įreq <- as.vector( table( sample(coin, 100, replace = TRUE))) prop <- prop.table(freq) flips_df <- ame( 'Face' = coin, 'Frequency' = freq, 'Proportion' = prop) flips_df # Face Frequency Proportion For coin, since there are only 2 elements in this vector, it’s not possible to sample from it without replacement 10 times because there will be no more elements to draw after the second draw. In other words, when sample() draws at random from some population, it does not put back the elements from each individual sample. The default value for the replace argument is FALSE, which means that by default sample() samples without replacement. In this case the size of the population from which we are sampling is 2 because coin is a vector with 2 elements. This is because this function “cannot take a sample larger than the population when ‘ replace = FALSE’”. Unfortunately, if we try to draw 10 samples from coin, R will throw an error. This is equivalent to flipping a real coin 10 times. Let’s try drawing a sample of size 10 from coin. The first argument, x, is the object from which a sample is to be drawn and the second argument, size, is the size of the sample to be drawn. Now is a good time to introduce a couple of functions that are very valuable for running simulations like this. Notice that as the number of flips increases, the proportion of flips that are heads converges towards the probability that a single flip of a fair coin will land on heads. The horizontal dashed line is drawn at the probability that any single flip of a fair coin will land on heads, which is 0.5. The blue lines in each of the plots below represent the proportion of flips of a fair coin which are heads for a certain number of flips. To illustrate these concepts, we looked at some plots which expand on an example that’s given in the textbook on page 5. This is given by N(A)/n as n approaches infinity.Probability: The proportion of times an event occurs when the number of trials is very large. ![]() N(A): The number of times that event A occurs during n trials.n: Number of times a trial/experiment is run.Relative frequency: The proportion of times some event occurs during a certain number of trials.Recall in discussion while we were reviewing section 1.1 of the Tanis/Hogg text we established definitions for the following two similar but not identical terms. 28.0.1 Further courses in Mathematics and Statistics. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |