# 70 students as of Mar 2
windows11 <- c("aflores-hernandez","akwong25","bdelacruz-angeles",
"bhernandezarteaga","cbettencourt2","cchen271","cornelas3",
"craigelijaesoriano","davila-castaneda","dvargas38",
"ecastillo-quevedo","efernando","ekjotjohal","elliottwhitney",
"fromerobojorquez","genaxiong","ggonzalez-ramirez",
"ghendrickson","gurindersahota","jasminesamayoa",
"jcontrerastrinidad","jessiemorales","jlegaspina","joneal2",
"jwong290","kchen129","leogarciaortiz","lillieyang",
"lindaespinozamunoz","lorenackerman","mdesilva","rbujji",
"roderickma","skodur","sraman7","tolaniyan","trevoroh")
macOS <- c("adimasagurto","ahmiyasalter","alannahtanner","aleroux",
"alizeibarra","apatterson9","asingh368",
"eflores136","elmermartinez","emendozagonzalez",
"emoya8","isidrohernandez","jaisingh","jangel15","jardindo",
"jessecaclark","jmandujano4","jperez460","kamryntaylor",
"kchen132","kvu56","lalagos","malachifuqua","manroopkaur",
"mayraarias","msuccari","omarkhalil","rbeattie","seanjimenez",
"vchezhiyan","xcortes2")
language_table_students <- c("edmondcheng", "angeliachunyu")
teamsize <- 7
# Set seed for reproducibility
set.seed("20260302")
shuffled_win11 <- sample(windows11, replace = FALSE)
tables <- c(rep(1:3,each=teamsize),rep(4:5,each=(teamsize+1)))
teams_win11 <- split(shuffled_win11, tables)
shuffled_macOS <- sample(macOS, replace = FALSE)
tables <- c(rep(6,(teamsize-1)),rep(7,(teamsize-2)),rep(8:9,each=teamsize),rep(10,(teamsize-1)))
teams_macOS <- split(shuffled_macOS, tables)
teams_macOS$`7` <- c(teams_macOS$`7`,language_table_students)
teams <- lapply(c(teams_win11,teams_macOS),sort)
invisible(lapply(seq_along(teams), function(i) {
cat("Team at Table", i, ":", teams[[i]], "\n")
}))
## Team at Table 1 : efernando ggonzalez-ramirez gurindersahota jlegaspina kchen129 leogarciaortiz trevoroh
## Team at Table 2 : bhernandezarteaga cbettencourt2 jcontrerastrinidad jessiemorales jwong290 lorenackerman roderickma
## Team at Table 3 : akwong25 cornelas3 dvargas38 lillieyang lindaespinozamunoz rbujji sraman7
## Team at Table 4 : bdelacruz-angeles cchen271 davila-castaneda elliottwhitney fromerobojorquez genaxiong jasminesamayoa tolaniyan
## Team at Table 5 : aflores-hernandez craigelijaesoriano ecastillo-quevedo ekjotjohal ghendrickson joneal2 mdesilva skodur
## Team at Table 6 : alannahtanner eflores136 emoya8 lalagos mayraarias rbeattie
## Team at Table 7 : angeliachunyu edmondcheng elmermartinez emendozagonzalez kamryntaylor kchen132 malachifuqua
## Team at Table 8 : ahmiyasalter alizeibarra asingh368 isidrohernandez jangel15 jardindo xcortes2
## Team at Table 9 : adimasagurto aleroux apatterson9 jaisingh jessecaclark jperez460 kvu56
## Team at Table 10 : jmandujano4 manroopkaur msuccari omarkhalil seanjimenez vchezhiyanDSC 011 S26 Lecture 16 Demo
Binomial Calculations in R
Preliminaries: Assignment of Teams and Team Tables
The class will split into OS-specific randomly assigned teams of about seven. The teams and team tables are determined by random sampling without replacement (also known as permutation) as follows:
Instructions for Completing and Submitting This Assignment
- Download and open today’s template notebook in RStudio
- Personalize the file by writing your name in the YAML header (replace “FirstName LastName”) — be sure to do this or you will lose points!
- Save with your name in RStudio and move to course directory: In RStudio select
File ??? Save as..., find your course directory files and move and rename the file to include your name (e.g.,FirstName_LastName_Quantiles_Demo.qmd) - Render to HTML
- Follow instructions from the HTML rendered output by editing your personalized notebook.
- As you work the assignment, keep rendering and editing the file, asking for help from your team until you get all CORRECT for each problem. Two or more students may ask for help from the instructors.
- Render to HTML and submit to Catcourses. Turn in as much CORRECT work as you can by the end of class today. Submission by end of class qualifies you for credit.
- Resubmit your best work by midnight tonight for better grade or fully accepted work – only your latest and best work gets graded.
Assignment
Compute Binomial Tail Probabilities, Interval Probabilities, Quantiles, and Simulating Binomial Variates in R
Demonstration 1 Binomial Tail Probabilities
In the Console, use pbinom, the cumulative distribution function for the binomial, and fill in values 47 for x, 100 for size, and 0.5 for prob to compute the one-sided tail probability of 47 or fewer successes in 100 I.I.D. trials of a fair Bernoulli random variable. Round to 8 digits after the decimal place.
After getting this to work, copy and paste your working R expression code from the Console into the code chunk below, replacing NULL as the argument to the quote() to test its correctness.
code <- quote(round(pbinom(47, 100, 0.5), 8))
print_and_check_expr(
code,
value_key = "56dca91c2a45dd0a7aab137761a048434bdaa02284f89e1d3a923eefcc6b6e75",
required_fns = c("round", "pbinom")
)
## [1] 0.30864971
## [VALUE] CORRECT
## [CODE] Uses round(): YES -- CORRECT
## [CODE] Uses pbinom(): YES -- CORRECTDemonstration 2: Binomial Interval Probabilities
In the Console, evaluate ?pbinom to examine the documentation of pbinom. Note the default behavior of the pbinom function is with its optional argument lower.tail = TRUE returning the value \(F(x) \equiv \Pr(x \le X)\).
In the R Console, write an R expression that uses pbinom twice and not dbinom to show that for 100 I.I.D. Bernoulli trials with probability of success \(\pi = 0.5\), there is about a 24% chance that the numbers of successes will be between 49 and 51 inclusive. Round to 8 digits after the decimal place.
After getting this to work, copy and paste your working R expression code from the Console into the code chunk below, replacing NULL as the argument to the quote() to test its correctness.
code <- quote(round(pbinom(51,100,0.5) - pbinom(48,100,0.5), 8))
print_and_check_expr(
code,
value_key = "166ba9f34d4e947ab9c559e6136ea51c94ad6b57c5e722f2830122dfb8200f46",
expr_key = "26acd2ce1701e940053a56de392693b4e97c78fd4f2dc80b7ef69f74c774abbe",
required_fns = c("round", "pbinom"),
forbidden_fns = c("dbinom", "sum")
)
## [1] 0.23564657
## [VALUE] CORRECT
## [CODE] Uses round(): YES -- CORRECT
## [CODE] Uses pbinom(): YES -- CORRECT
## [CODE] Uses dbinom(): not used -- CORRECT
## [CODE] Uses sum(): not used -- CORRECTDemonstrations 3 and 4: Binomial Quantiles
- In the Console, write an R expression that uses
qbinomto calculate the 90th percentile of the number of successes expected in 100 I.I.D. Bernoulli trials with probability of success \(\pi = 0.5\). Then replaceNULLin the code chunk below with your working R expression.
answer <- qbinom(0.9, 100, 0.5)
print_and_check(
answer,"2e67810256cb6c4b797c97579a741aefda855a1944b2e2ca986b4ae560b48c78"
)
## [1] 56
## [VALUE] CORRECT- In the Console, write an R expression that uses
qbinomto calculate the 95th percentile of the number of successes expected in 100 I.I.D. Bernoulli trials with probability of success \(\pi = 0.75\). Then replaceNULLin the code chunk below with your working R expression.
answer <- qbinom(0.95, 100, 0.75)
print_and_check(
answer,"9f06801ef5c78e154b8a42393591326e36bcda798727e0f44bd189728f2cfbb4"
)
## [1] 82
## [VALUE] CORRECTDemonstration 5: Simulate Binomial Variates
Replace NULL with an R expression that uses rbinom to simulate 10 binomial variates in 100 I.I.D. Bernoulli trials with probability of success \(\pi = 0.75\). Then replace NULL in the code chunk below with your working R expression.
set.seed(1234)
answer <- rbinom(10, 100, 0.75)
print_and_check(answer, "465dea1b1d21ef19091439594c982833105c6ff07a3b50b6ac0be11339f71fd3")
## [1] 80 74 74 74 70 74 85 78 73 75
## [VALUE] CORRECT