# 70 students as of March 18
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","jaisingh","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","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 <- 7L
session_date <- 20260318L # long (4-byte) integer
set.seed(session_date)
shuffled_win11 <- sample(windows11, replace = FALSE)
tables <- c(rep(1:2, each = teamsize), rep(3:5, each = teamsize + 1L))
teams_win11 <- split(shuffled_win11, tables)
shuffled_macOS <- sample(macOS, replace = FALSE)
tables <- c(rep(6L, teamsize - 1L), rep(7L, teamsize - 2L),
rep(8:9, each = teamsize), rep(10L, teamsize - 2L))
teams_macOS <- split(shuffled_macOS, tables)
teams_macOS$`7` <- c(teams_macOS$`7`, language_table_students)
teams <- lapply(c(teams_win11, teams_macOS), sort)
names(teams) <- as.character(1:10)
session_type <- "lecture"
# PLEASE WRITE USERIDs of ABSENT TEAM MEMBERS HERE
# TO REASSIGN ROLES ON YOUR TEAM.
# PLEASE DELETE THOSE USERIDS TO RESTORE ROLES
# IF THEY JOIN THE TEAM LATER.
absent <- c()
# the following source statement
# requires teams, session_date to be defined
# prints role table and copy-forward block
source("dsc011_assign_roles.R")
##
## ======================================================================
## DSC 011 S26 | Lecture 20260318 | Team Roles
## ======================================================================
##
## Tbl Student Role
## --- ------------------------------------------ -----------------
## 1 Bryan Hernandez Arteaga (bhernandezarteaga) Developer
## 1 Elijah Fernando (efernando) Developer
## 1 Kelvin Chen (kchen129) Scrum Master [SM]
## 1 Linda Espinoza Munoz (lindaespinozamunoz) Developer
## 1 Mila De Silva (mdesilva) Developer
## 1 Rishit Bujji (rbujji) Developer
## 1 Sidharth Raman (sraman7) Reporter [R]
##
## 2 Alan Flores-Hernandez (aflores-hernandez) Developer
## 2 Alton Kwong (akwong25) Developer
## 2 Brandon De La Cruz-Angeles (bdelacruz-angeles) Developer
## 2 Grant Hendrickson (ghendrickson) Developer
## 2 Gurinder Sahota (gurindersahota) Scrum Master [SM]
## 2 John Legaspina (jlegaspina) Reporter [R]
## 2 Srika Kodur (skodur) Developer
##
## 3 Connor Chen (cchen271) Developer
## 3 Casey Ornelas (cornelas3) Reporter [R]
## 3 Diego Avila-Castaneda (davila-castaneda) Developer
## 3 Frida Romero Bojorquez (fromerobojorquez) Developer
## 3 Jessie Morales (jessiemorales) Developer
## 3 Joshua O'Neal (joneal2) Developer
## 3 Lillie Yang (lillieyang) Scrum Master [SM]
## 3 Loren Ackerman (lorenackerman) Developer
##
## 4 Ekjot Johal (ekjotjohal) Developer
## 4 Elliott Whitney (elliottwhitney) Developer
## 4 Gelsey Gonzalez Ramirez (ggonzalez-ramirez) Developer
## 4 Jai Singh (jaisingh) Developer
## 4 Jasmine Samayoa (jasminesamayoa) Developer
## 4 Jeffrey Wong (jwong290) Scrum Master [SM]
## 4 Leo Garcia Ortiz (leogarciaortiz) Developer
## 4 Deborah Olaniyan (tolaniyan) Reporter [R]
##
## 5 Christopher Bettencourt (cbettencourt2) Scrum Master [SM]
## 5 Craig Soriano (craigelijaesoriano) Developer
## 5 Delia Vargas (dvargas38) Developer
## 5 Ernesto Castillo-Quevedo (ecastillo-quevedo) Developer
## 5 Gena Xiong (genaxiong) Developer
## 5 Jose Contreras Trinidad (jcontrerastrinidad) Reporter [R]
## 5 Roderick Ma (roderickma) Developer
## 5 Trevor Oh (trevoroh) Developer
##
## 6 April Dimas Agurto (adimasagurto) Developer
## 6 Alexis Martinez (elmermartinez) Reporter [R]
## 6 Kalynn Vu (kvu56) Developer
## 6 Marco Succari (msuccari) Developer
## 6 Sean Jimenez (seanjimenez) Developer
## 6 Vainavi Chezhiyan (vchezhiyan) Scrum Master [SM]
##
## 7 Angelia Chunyu (angeliachunyu) Developer
## 7 Edmond Cheng (edmondcheng) Developer
## 7 Jordan Angel (jangel15) Developer
## 7 Malachi Fuqua (malachifuqua) Scrum Master [SM]
## 7 Manroop Kaur (manroopkaur) Reporter [R]
## 7 Mayra Arias (mayraarias) Developer
## 7 Xochilt Cortes (xcortes2) Developer
##
## 8 Alannah Tanner (alannahtanner) Reporter [R]
## 8 Alize Ibarra (alizeibarra) Developer
## 8 Anyhea Patterson (apatterson9) Developer
## 8 Esteban Flores (eflores136) Developer
## 8 Emily Mendoza Gonzalez (emendozagonzalez) Developer
## 8 Kevin Chen (kchen132) Scrum Master [SM]
## 8 Liam Alagos (lalagos) Developer
##
## 9 AhMiya Salter (ahmiyasalter) Reporter [R]
## 9 Andres Leroux (aleroux) Developer
## 9 Edgar Moya (emoya8) Developer
## 9 Jorge Mandujano (jmandujano4) Scrum Master [SM]
## 9 Kamryn Taylor (kamryntaylor) Developer
## 9 Omar Khalil (omarkhalil) Developer
## 9 Rachel Beattie (rbeattie) Developer
##
## 10 Apeksha Singh (asingh368) Scrum Master [SM]
## 10 Isidro Hernandez (isidrohernandez) Reporter [R]
## 10 Jardin Do (jardindo) Developer
## 10 Jesseca Clark (jessecaclark) Developer
## 10 Johnny Perez (jperez460) Developer
##
## Legend: [SM] Scrum Master | [R] Reporter | Developer | ** ABSENT **DSC 011 S26 Lecture 23 Demo
Bootstrap Interval Estimates of Relative Risks, Take II
Preliminaries
Today’s Teams and Roles
The class splits into OS-specific randomly assigned teams of seven. Teams and roles are determined by seeded random permutation of the roster. Each team has one Scrum Master, one Reporter, and the remaining members work as Developers. Roles are described in the micro-sprint section below.
Instructions for This Notebook
- Download today’s zipped team folder from CatCourses.
- Move it from Downloads into your course
DEMOSdirectory. - Unzip the folder and double-click the
.Rprojfile to open the project. - Open this
.qmdfile in the RStudio source pane. - Personalize by replacing
FirstName LastNamein the YAMLauthorfield (you will lose points if you don’t). - Save As with your name in the filename, in the same project directory.
- Render to HTML — fix any errors before proceeding.
- Work the Assignment with your team according to the role. Your goal is for all team members to accurately reproduce the instructor’s demo.
- Render and resubmit as you finish problems — only your latest submission is graded.
- Submit by midnight for full credit.
- Scroll and Recall your History in the R Console or Bash shell using ↑ and ↓ to recall and rerun older inputs. Avoid retyping that leads to typo-causing errors.
- Modify Working Code Iteratively in the R Console or Bash shell to build out validated error-free workflows. Use Ctrl+a and Ctrl+e to jump to the beginning and ends of lines. Avoid typing out names which is error-prone and costs you time.
- Use the REPL to Inspect Return Values in the R Console or Bash shell to investigate the structure of your data and validate the outputs of your code. Look under the hood to see what data your functions or programs are passing to each other.
- Tab-complete names of functions, variables and arguments in R Console and commands, files and directories in Bash Shell using Tab. Avoid typos that cause errors.
- Code in the Console or Shell Rather than your Notebook Code Chunks. Take advantage of command-line editing and tab-completion to code faster and more accurately.
- Copy/Paste working code solutions from your Console/Shell to your notebook to memorialize working code that you want to save. Notebooks are for communication, not code development.
- Read errors before asking for help: they usually name the problem exactly. Find the line numbers referenced and quote the error and the code when you ask for help.
- Only replace
NULLinsidequote()— don’t edit anything else in aprint_and_check_expr()chunk.
- All Team Members work individually to follow and reproduce the demonstration.
- All Team Members signal Reporter or Scrum Master if they are blocked and unable to render or get code to work without error.
- Scrum Master or Reporter connects their screen to table’s monitor to help track the instructor demo.
- Scrum Master leads Initial Stand-Up where teams members take turns introduce themselves, their roles, how they will work and what they need for success. (about two minutes).
- Scrum Master and Reporter work together to keep track of who is blocked.
- Scrum Master asks free Developers to help team members who are blocked (including his or herself).
- Reporter assists Scrum Master in keeping track of who is blocked.
- Reporter records in her notebook copy blockages and resolutions. There is a separate Reporter’s section for each Demonstration.
- Scrum Master signals to instructor that the team is ready to move on or asks instructor to help the team.
- Developers test and troubleshoot code solutions, report blocks to Reporter and Scrum Master, and help other team members.
- Scrum Master runs Retrospective at the End asking team for reflection on what worked and what could be improved.
- Reporter records summary of Retrospective in their notebook.
Data
Aspirin-Heart Attack Data
These data cross-classify aspirin use as explanatory variable and heart attack (Myocardial Infarction, or MI) incidence as response variable. The data were published from results of a large scale long-term prospective observational study of male physicians in Steering Committee of the Physicians’ Health Study Research Group (1988) and analyzed in Efron and Tibshirani (1994).
heart <- data.frame(Fatal = c(18,5),
Nonfatal = c(171,99),
No_Attack = c(10845,10933))
row.names(heart) <- c("Placebo","Aspirin")
heart
## Fatal Nonfatal No_Attack
## Placebo 18 171 10845
## Aspirin 5 99 10933Aspirin-Stroke Data
These data cross-classify aspirin use as explanatory variable and stroke incidence as response variable. The data were published from results of a large scale long-term prospective observational study of male physicians in Steering Committee of the Physicians’ Health Study Research Group (1988) and analyzed in Efron and Tibshirani (1994).
stroke <- data.frame(Strokes = c(119,98),
Total = c(11037,11034))
row.names(stroke) <- c("Aspirin","Placebo")
stroke
## Strokes Total
## Aspirin 119 11037
## Placebo 98 11034Assignment
Demonstration 1: Adding Row Margin Totals for Heart Attack Data
Add a column of row totals using apply with the sum function and bind it to the name Total in the data.frame heart.
heart$Total <- apply(heart,1,sum)
heart
## Fatal Nonfatal No_Attack Total
## Placebo 18 171 10845 11034
## Aspirin 5 99 10933 11037Reporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Demonstration 2: Slicing by Name and Computing Relative Risk for Baby Aspirin-Heart Attack Data in base-R
Compute the Relative Risk (RR) of heart attack in subjects who took placebo versus a daily baby aspirin regimen. Round to two digits after the decimal place.
nA <- heart["Aspirin","Total"]
nP <- heart["Placebo","Total"]
kA <- sum(heart["Aspirin",c("Fatal","Nonfatal")])
kP <- sum(heart["Placebo",c("Fatal","Nonfatal")])
RR <- round(((kP/nP)/(kA/nA)),2)
print_and_check(RR, "034fbed1afa5fda9b30eeae6415dcf7927f46618125e597ad86415799fafeb86")
## [1] 1.82
## [VALUE] CORRECTReporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Demonstration 3: Computing Relative Risk for Baby Aspirin-Stroke Data
Compute the Relative Risk (RR) of stroke in subjects who took a daily baby aspirin regimen versus placebo. Round to two digits after the decimal place.
nA <- stroke["Aspirin","Total"]
nP <- stroke["Placebo","Total"]
kA <- stroke["Aspirin","Strokes"]
kP <- stroke["Placebo","Strokes"]
RR <- round(((kA/nA)/(kP/nP)),2)
print_and_check(RR, "e710b5767d137e92f2debe5ada151025084c814c6b4f65ed5b8316c53cc41ce2")
## [1] 1.21
## [VALUE] CORRECTReporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Demonstration 4: Bootstrap Confidence Interval for Relative Risk of Heart Attack with Placebo Over Aspirin
Compute 0.025- and 0.975-fractiles of the bootstrap sampling distribution of Relative Risk (RR) of Heart Attack in Placebo over Aspirin rounded to two digits after the decimal place to obtain a 95% Bootstrap Confidence Interval for this RR, and note whether or not it contains the null hypothesis value of 1.
nA <- 1
nP <- 1
kA <- 1
kP <- 1
jA <- 1
jP <- 1
sampleA <- NULL
sampleP <- NULL
set.seed(1024)
numreps <- 1000
bootrepsA <- NULL
bootrepsP <- NULL
dim(bootrepsA)
## NULL
dim(bootrepsP)
## NULL
# Time the apply approach
#time_app <- system.time({
#a <- apply(bootrepsA, 2, sum)
#p <- apply(bootrepsP, 2, sum)
#bootRR <- (p/nP) / (a/nP)
#})
# Time the looped approach
#time_loop <- system.time({
# bootRR2 <- rep(NULL, numreps)
#for(i in 1:numreps){
# bkA <- sum(bootrepsA[,i])
# bkP <- sum(bootrepsP[,i])
# bootRR2[i] <- (bkP/nP) / (bkA/nA)
#}
#})
# Time the vectorized colSums approach
#time_vec <- system.time({
#a <- colSums(bootrepsA)
#p <- colSums(bootrepsP)
#bootRR3 <- (p/nP) / (a/nA)
#})
#cat("apply-based: ", time_app["elapsed"], "sec\n")
#cat("Looped: ", time_loop["elapsed"], "sec\n")
#cat("colSums: ", time_vec["elapsed"], "sec\n")
#cat("Speedup vs loop:", round(time_loop["elapsed"] / time_vec["elapsed"], 1), "x\n")
#hist(bootRR,main="computed using apply")
#hist(bootRR2,main="computed using for loop")
#hist(bootRR3,main="computed using colSums")
#bootCI <- round(quantile(bootRR3,c(NULL,NULL)),2)
#cat("95% Bootstrap Confidence Interval of Heart Attack in Placebo over Aspirin:\n")
#print_and_check(bootCI, "7a9d9fb8fd7c5ea3ca47a101d2e9da9d27fdd535ba16719061dd7c97e8fe6451")Reporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Demonstration 5: Show Consistency of Interval Estimate and Conclusion of Bootstrap Confidence Interval for Relative Risk of Heart Attack with Placebo Over Aspirin Under the Monotonic Reciprocal Transformation
Switch the roles of Aspirin and Placebo and show you get the same results as before: compute 0.025- and 0.975-fractiles of the bootstrap sampling distribution of Relative Risk (RR) of Heart Attack in Aspirin over Placebo rounded to two digits after the decimal place, and note whether or not it contains the null hypothesis value of 1. Then compute reciprocals of the lower and upper bounds and show they are the same as previously computed.
#bootRR4 <- (a/nA) / (p/nP)
#hist(bootRR4,main="Bootstrap RR for Aspirin over Placebo")
bootCI2 <- NULL
#names(bootCI2) <- names(bootCI)
#cat("95% Bootstrap Confidence Interval of Heart Attack in Placebo over Aspirin:\n")
print_and_check(bootCI2, "7a9d9fb8fd7c5ea3ca47a101d2e9da9d27fdd535ba16719061dd7c97e8fe6451")
## NULL
## [VALUE] INCORRECTReporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Demonstration 6: Compute Bootstrap Confidence Interval for Relative Risk of Stroke with Aspirin Over Placebo
Note whether or not the 95% bootstrap CI contains the null hypothesis value of 1.
nA <- 1
nP <- 1
kA <- 1
kP <- 1
jA <- 1
jP <- 1
sampleA <- NULL
sampleP <- NULL
set.seed(1024)
numreps <- 1000
bootrepsA <- NULL
bootrepsP <- NULL
a <- NULL
p <- NULL
bootRR5 <- NULL
#hist(bootRR5,main="Bootstrapped Relative Risk for Stroke Data")
#bootCI <- round(quantile(bootRR5,c(NULL,NULL)),2)
#cat("95% Bootstrap Confidence Interval of Stroke in Aspirin over Placebo:\n")
#print_and_check(bootCI, "1eb277d60390f2754f14767089ed3dbc7ea54ced342658aab21c462b5a324f1c")Reporter’s Block/Resolution Log
| Block | Resolution |
|---|---|
Reporter’s Mini-Retrospective Summary
What helped the team succeed today:
(write here)
What could make the next session run better:
(write here)