Lab 2D
Directions: Follow along with the slides, completing
the questions in blue on your
computer, and answering the questions in red in your
journal.
Space, Click, Right Arrow or swipe left to move to
the next slide.
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)
and describe the output.
Does something similar happen if you sample with
replacement?
~
was not needed with the
tally
function. This is because without
was
not a variable within a data frame but rather a vector which acts like a
lone variable.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, without
replacement and assign the simulations the name
draws
and then View
your file. Use
set.seed(1)
."rap"
songs.Answer the following questions by performing
500 simulations of sampling 2 songs from a playlist of 30
"rap"
, 23 "country"
and 47 "rock"
songs. You might consider running set.seed
so that your
results can be reproduced:
Calculate estimated probabilities for the following situations:
"rap"
songs."rap"
song in the first draw and a
"country"
song in the 2nd.Create a histogram
that displays the number
of times a "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?