Exam 1 Combined Practice Problems Solutions
Code
Q1
install.packages() is when you need to install a package on your computer. You only need to do this one time per machine. In contrast, library() simply loads the package into your current workspace. You would include library() in your Quarto document, but not install.packages().
Q2
If she completes her analysis in excel and simply shares her results, there will not be a record of the steps she took to complete her analysis. In this way, it will be difficult (perhaps impossible) to reproduce her analysis. Using R and typing code into a document (such as Quarto), we can keep a record of all steps taken in the analysis, improving the possibility of reproducing the results.
Q3
### in front of text makes a header.
Q4
# in front of code creates a comment. This tells R not to run this line of code.
Q5
There is an extra parentheses at the end of her code. This is causing an error. To fix it, she should delete this parentheses.
Q6
geom_point() produces a scatterplot.
Q7
summarize()is creating a new variable calledavg_exerciserepresenting the mean of theExercisevariable within the dataset.na.rm = Tis telling R to remove anyNAvalues within theExercisevariable.
Q8
Correct answer: C
Q9
A, B, C are correct.
Q10
those with age at least 50 and sbp greater than 140 mmHg.
pipes the dataset into the filter command
No. She is creating a new dataset but hasn’t asked anything to be printed.
Q11
A and D are correct.
Q12
One row per age_group.
A column mean_bmi containing the mean BMI for each sex, with NAs removed.
Conceptual
Q1
Reproducibility: taking original data and code to reproduce all numerical findings. Replicability: being able to independently repeat an entire study without use of original data.
Q2
Quota sampling is sampling until you have reached a particular number of participants. This type of sampling is not as generalizable as a probability sampling scheme.
Q3
In the COVID-19 seroprevalence paper, the recruitment strategy followed a “snowball” sampling scheme via Facebook ads. This may have introduced sampling bias because it may have attracted people concerned about COVID-19 or those who thought they were already exposed. This may have led to an overestimation of seroprevalence, and it could have been made worse since these individuals may have recruited others in their network.
Q4
Population: Adults aged 65 or older.
Q5
True
Q6
False - some probabilities could be zero.
Q7
True
Q8
False
Applied
Q1
z-score = (165-135)/20
Since different variables follow different normal distributions (i.e. with different means and variances), it’s helpful to standardize in order to create a unitless measure of the number of standard deviations away from the mean. This way, we can more easily see how extreme a particular value is.
Q2
Sensitivity is the probability the rapid test is positive given disease is present. Sensitivity = \(\frac{72}{72 + 8} = \frac{72}{80}\)
Specificity is the probability the rapid test is negative given disease is absent. \(\text{Specificity} = P(\text{Test –} \mid \text{Disease –}) = \frac{\text{True Negatives}}{\text{True Negatives + False Positives}} = \frac{102}{102 + 18} = \frac{102}{120}\)
In this context, specificity means: Among patients who truly do not have influenza (PCR negative), the rapid test correctly identifies about 85% as negative.
Q3
True
Q4
(B). The probability that the test is positive given that the person truly has COVID-19 is just the sensitivity, 90% (0.9).
\(P(\text{Infected} \mid \text{Test +}) = \frac{P(\text{Test +} \mid \text{Infected}) \times P(\text{Infected})}{P(\text{Test +})}\)
From the table:
Test positive & disease positive = 70
Disease positive total = 80
\(\text{Sensitivity} = \frac{70}{80}\)
Q5
Events occur independently – Each patient’s arrival is assumed independent of others.
- In practice, independence may be reasonable, unless e.g., an asthma trigger affects multiple people simultaneously.
The average rate \(\lambda\) is constant – The expected number of arrivals per hour does not change significantly over time.
Events occur singly – Only one event occurs at a particular instant.
Number of events in non-overlapping intervals is independent – The number of arrivals in one hour is independent of arrivals in another hour.
Q6
- All probabilities are between 0 and 1.
The sum of probabilities for all outcomes is 1.
The probability of the union of disjoint events equals the sum of their probabilities.
- \(P(X \ge 2) = 1 - P(X < 2) = 1 - P(X = 0) - P(X = 1)\)
\(P(X \ge 2) = 1 - \frac{e^{-3} 3^0}{0!} - \frac{e^{-3} 3^1}{1!}\)
- Answer is (B):
1 - ppois(1, lambda = 3). Note that this is the same as1 - (dpois(0, lambda = 3) + dpois(1, lambda = 3)).