answer <- "pbinom"
print_and_check(answer, "ca37a1780346d8a124387b53dd1c6ba2e02d2ca7c55aaf86ef15fd8319df9ef4")
## [1] "pbinom"
## [VALUE] CORRECTDSC 011 S26 Lab 6 and Problem Set
Practice with Binomial Computations
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
Binomial Tail and Interval Probabilities: European Mitochondrial DNA variants (8 points)
Rubric
- 2 points for using the correct R function to compute binomial tail probabilities
- 1 point for correct arguments for call to R function (for each of three questions)
- 1 point for computing the correct tail or interval probability (for each of three questions)
Problem Statement
A survey of European mitochondrial DNA variation found that the most common haplotype “H” occurs in 40% of Europeans (Roostalu et al. 2007).
Question 1: R Function for Binomial Cumulative Fractions
What is the name of the function in R that computes the cumulative fractions of distributions less than or equal to one or more binomial quantiles (i.e. numbers of successes)?
Save the name of this function within double quotation marks ("") but without the following parentheses (()) in the variable answer in the code chunk below. If you get it right, the code chunk will return CORRECT.
Question 2: Tail Probability for Haplotype Frequencies, I
If we were to sample 400 individuals from the European population, what is the probability that at least 180 people are haplotype H?
Find the correct code in the R Console, and then replace NULL with your code to check the result.
code <- quote(pbinom(180,400))
print_and_check_expr(
code,
value_key = "bd165a9d7e80c06e630c1e2640f93b02afaa45361e1eff50a998ed2c2ea30e9a",
required_fns = c("pbinom")
)
## [ERROR] Expression failed: argument "prob" is missing, with no defaultQuestion 3: Tail Probability for Haplotype Frequencies, II
Continuing from the previous problem, what is the probability that at least 130 people are haplotype H?
Save the value of your unrounded answer in the variable answer in the code chunk below. If you have calculated it correctly, the code chunk will return the value CORRECT.
code <- quote(NULL)
print_and_check_expr(
code,
value_key = "876fe791c6ed51725bf022446edf217c1376bbf3f4a3e24ca9318f5e1a2f68d0",
required_fns = c("pbinom")
)Question 4: Interval Probability for Haplotype Frequencies
Continuing from the previous problem, what is the probability that between 115 and 170 people (inclusive) are haplotype H?
Save the value of your unrounded answer in the variable answer in the code chunk below. If you have calculated it correctly, the code chunk will return the value CORRECT.
code <- quote(NULL)
print_and_check_expr(
code,
value_key = "22f5afbc01fbadda7e1c8d1147be2a32f663424dd583de89fa32a90702941dae",
required_fns = c("pbinom")
)Question 5: Binomial Tail Probability
Suppose that in U.S. Hospitals, 30% of isolates of Enterococcus are resistant to the antibiotic vancomycin (Wenzel 2004). Assume that seven isolates of Enterococcus have been independently isolated from patients.
What is the probability that exactly five of these isolates will be found to be resistant to vancomycin? (Hint: you need to use the dbinom). Please provide your answer to three digits of precision after the decimal place?
code <- quote(NULL)
print_and_check_expr(
code,
value_key = "7bc7619875250fab95958a3c251786fa5e8a107a7110922406e582bf46731554",
required_fns = c("dbinom")
)Question 6: Binomial Expectations
Continuing from the last question:
What would be the expected number of isolates in the previous problem to be found resistant to vancomycin? Round to the nearest integer and show work (copy code, not values!).
code <- quote(round(7*0.3))
print_and_check_expr(
code,
value_key = "1eead23f0469385c21fac3a835d4b3201f579bbd9adb94a6f5cdf96c1a189469",
required_fns = c("round")
)
## [1] 2
## [VALUE] CORRECT
## [CODE] Uses round(): YES -- CORRECTBinomial Interval Estimates
Cocaine Cash: Construct Bayesian 99% Highest Posterior Density Credible Interval with the binom.confint() function in R
In the United States, paper currency often comes into contact with cocaine either directly or via counting machines. A forensic survey found that forty-six of fifty $1 bills had detectable levels of cocaine on them (Jenkins 2001).
Assuming this sample was random, Using the binom.confint() function, compute the default “highest probability density (hpd)” estimate for the 99% credible interval for the relative frequency of U.S. $1 bills with detectable levels of cocaine assuming a “flat” or “uninformative” prior distribution and a sample of 46 successes in 50 trials.
Hint: you need to set values for the prior.shape1 and prior.shape2 optional arguments to the function call), use values of 1 for each. Select the 99% confidence interval using optional argument conf.level = 0.99 and Bayes with method="bayes".Extract the lower bound by write $lower after the function call binom.confint**
What is the lower bound of this interval estimate?
library(binom)
code <- quote(binom.confint(
x=46,
n=50,
method="bayes",
conf.level=0.99,
prior.shape1=1,
prior.shape2=1,
)$lower)
print_and_check_expr(
code,
value_key = "ea6a58798e637c4f120e39ebe1fe3aaed3a9bedce55b9019a552f1e2b113ef19",
required_fns = c("binom.confint")
)
## [1] 0.785473727372929
## [VALUE] CORRECT
## [CODE] Uses binom.confint(): YES -- CORRECT