n gives the number of samples you want to take. The binomial can be a coin flipping distribution. The binomial distribution sounds like a scary word… binomial (AAGGGGHHHHH, stay away!). We put more 5s in, and voila, more 5s come out of in our big sample of 1000. We are looking at lots of samples from our little gumball machine of numbers. Sample_of_numbers <- sample(some_numbers, 1000, replace= TRUE) Let’s sample 1000 times from our some_numbers variable, and then look at the histogram library(ggplot2) Sample_of_numbers <- sample(some_numbers, 20, replace= TRUE) Here’s another example with numbers some_numbers <- c( 1, 2, 3, 4, 5, 5, 5, 5) We set replace=TRUE so that after each sample, we put the item back into the gumball machine and start again. We set it do this 10 times, so our sample has 10 things in it. Here the sample function randomly picks A or B each time. Sample_of_gumballs <- sample(gumballs, 10, replace= TRUE) You put the gumballs inside with different properties, say As and Bs, and then you let sample endlessly take gumballs out. The sample function is like an endless gumball machine.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |