Lab 3 Probability R Afara Emmanuel

docx

School

Harrisburg University of Science and Technology *

*We aren’t endorsed by this school

Course

502

Subject

Statistics

Date

Feb 20, 2024

Type

docx

Pages

7

Uploaded by ConstableCrown17410

Report
> download.file("http://www.openintro.org/stat/data/kobe.RData", destfile = "kobe.RData") trying URL 'http://www.openintro.org/stat/data/kobe.RData' Content type 'unknown' length 2280 bytes downloaded 2280 bytes > load("kobe.RData") # Kobe's shooting stats in few games > head(kobe) vs game quarter time description basket 1 ORL 1 1 9:47 Kobe Bryant makes 4-foot two point shot H 2 ORL 1 1 9:07 Kobe Bryant misses jumper M 3 ORL 1 1 8:11 Kobe Bryant misses 7-foot jumper M 4 ORL 1 1 7:41 Kobe Bryant makes 16-foot jumper (Derek Fisher assists) H 5 ORL 1 1 7:03 Kobe Bryant makes driving layup H 6 ORL 1 1 6:01 Kobe Bryant misses jumper M > tail(kobe) vs game quarter time description basket 128 ORL 3 4 3:57 Bryant Jump Shot: Made (28 PTS) H 129 ORL 3 4 3:33 Bryant Layup Shot: Missed M 130 ORL 3 4 2:02 Bryant 3pt Shot: Missed M 131 ORL 3 4 00:23.9 Bryant 3pt Shot: Missed M 132 ORL 3 4 00:06.9 Bryant 3pt Shot: Missed M 133 ORL 3 4 00:00.5 Bryant Layup Shot: Made (31 PTS) H > dim(kobe) [1] 133 6 > kobe$basket[1:9] [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" > kobe[1:9,6] [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" > kobe_streak <- calc_streak(kobe$basket) > streak_length_of_1 <-calc_streak(1) > print(streak_length_of_1) Q1: What does a streak length of 1 mean, i.e. how many hits and misses are in a streak of 1? W 1? What about a streak length of 0? The code defines a streak length of one which is a shot and a miss. There are 0 hits and 1 misses in a streak length of 0. [1] 0 0 > streak_length_of_0 <-calc_streak(0) > print(streak_length_of_0) [1] 0 0 Q2: To describe the distribution of kobe’s streak lengths from the 2009 NBA finals. A barplot instead of a histogram is preferable for our data counts.The plot defines Kobe’s typic Typical streak length and the length of his longest streak of baskets. > kobe_streak <- calc_streak(kobe$basket) > kobe_streak [1] 1 0 2 0 0 0 3 2 0 3 0 1 3 0 0 0 0 0 1 1 0 4 1 0 1 0 1 0 1 2 0 1 2 1 0 0 1 0 0 0 1 1 0 1 0 2 0 0 0 3 0 1 0 1 2 [70] 0 1 1 0 0 0 1 >
> barplot(table(kobe_streak)) > > table(kobe$basket)/133 H M 0.4360902 0.5639098 > kobe_streak <- calc_streak(kobe$basket) > barplot(table(kobe_streak)) > table(kobe$basket)/133 H M 0.4360902 0.5639098 > title("streak lengths from 2009 NBA finals") > barplot(table(kobe_streak)) > > table(kobe$basket)/133 H M 0.4360902 0.5639098 > kobe_streak <- calc_streak(kobe$basket) > barplot(table(kobe_streak)) > table(kobe$basket)/133 H M 0.4360902 0.5639098 > title("streak lengths from 2009 NBA finals")
> outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
> sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "heads" > outcomes <- c("heads", "tails") > sample(outcomes, size = 1, replace = TRUE) [1] "tails" > set.seed(5) Q3.In the simulation of flipping the unfair coin 100 times, how many flips came up heads? > outcomes <- c("heads", "tails") > sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8)) > table(sim_unfair_coin) sim_unfair_coin
heads tails 28 72 Q4.What change needs to be made to the sample function so that it reflects a shooting percentage of 45%? Make this adjustment, then run a simulation to sample 133 shots. Assign the output of this simulation to a new object called sim_basket . > outcomes <- c("H", "M") > sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(.45, 0.55)) > sim_basket [1] "H" "H" "H" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "M" "M" "H" "M" "M" "H" "H" "H" "M" [35] "M" "M" "M" "M" "M" "H" "M" "M" "M" "H" "H" "H" "M" "H" "H" "H" "M" "H" "H" "M" "M" "H" "H" "M" "M" [69] "H" "H" "M" "H" "H" "M" "M" "H" "M" "H" "M" "M" "H" "H" "M" "M" "H" "M" "H" "M" "H" "M" "H" "H" "M" [103] "H" "H" "H" "M" "H" "M" "M" "M" "H" "H" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "H" "M" "H" "H" "H" Describe the distribution of streak lengths. What is the typical streak length for this simulated independent shooter with a 45% shooting percentage? How long is the player's longest streak of baskets in 133 shots? > outcomes <- c("H", "M") > sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(.45, 0.55)) > sim_basket [1] "H" "H" "M" "M" "M" "M" "H" "H" "M" "H" "H" "M" "M" "M" "M" "H" "M" "H" "M" "M" "M" "H" "M" "M" "H" [35] "M" "H" "H" "H" "M" "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "M" "M" "H" "M" "H" "H" "M" "H" "M" "H" [69] "M" "H" "M" "M" "H" "H" "M" "M" "H" "H" "M" "M" "H" "H" "M" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M" [103] "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "M" "M" "M" "H" "H" "M" "H" "M" "M" "M" "H" "M" "M" "M > calc_streak(sim_basket) [1] 2 0 0 0 2 2 0 0 0 1 1 0 0 1 0 1 2 0 0 0 0 0 0 3 1 0 0 1 2 0 0 0 1 2 1 1 1 0 0 0 0 2 1 0 2 0 2 0 2 0 0 1 0 2 0 [70] 1 0 0 0 0 0 2 1 0 0 1 0 0 2 0 2 > sim_streak <- calc_streak(sim_basket) > barplot(table(calc_streak(sim_basket))) >
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help