Lab 2D
Directions: Follow along with the slides and answer the questions in red font in your journal.
R
, simulate a playlist of songs containing 30 "rap"
songs, 23 "country"
songs and 47 "rock"
songs.
c
ombined playlist the name songs
.0.30
.replace
option in the sample
function to FALSE
.size
100 from our playlist of songs without replacement. Assign this sample the name without
.
tally(~without)
? Does something similar happen if you sample with replacement?size = 101
and replace = FALSE
?sample
from the candy jar. Assume the simulated jar is named candies
.do
function to perform 10 simulated sample
s of size
2, with replacement and assign the simulations the name draws
.mutate(draws, nrap = rowSums(draws=="rap"))
draws == "rap"
rowSums(draws == "rap")
mutate(draws, nrap = rowSums(draws=="rap"))
"rap"
songs.draws_sub <- filter(draws, ___ == "rap", ___ == "rap")
nrow(___) / ___
"rap"
songs."rap"
song in the first draw and a "country"
song in the 2nd."rap"
song occurred in each simulation. That is, how often were zero rap songs drawn? A single rap song? Two rap songs?If we draw 5 songs from a playlist of 30 rap, 23 country and 47 rock songs, how does the estimated probability of all 5 songs being rap songs change if we draw the songs with or without replacement?