Lab#
Learning Objectives#
At the end of this learning activity you will be able to:
Estimate the effect size given a set of confidence intervals.
Calculate the
effect_size,alpha,power, andsample_sizewhen given 3 of the 4.Interpret a power-plot of multiple experimental choices.
Calculate how changes in estimates of the experimental error impact sample size requirements.
Rigorously choose the appropriate experimental design for the best chance of success.
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pingouin as pg
sns.set_style('whitegrid')
Step 1: Define the hypothesis#
For this lab we are going to investigate a similar metric. We will imagine replicating the analysis considered in Figure 3C. This analysis considers the different sub-values of the vigalence index. It shows that SK609 is improving attention by reducing the number of misses.
Copying the relevant part of the caption:
“Paired t-tests revealed that SK609 (4mg/kg; i.p.) specifically affected the selection of incorrect answers, significantly reducing the average number of executed misses compared to vehicle conditions (t(6))=3.27, p=0.017; 95% CI[1.02, 7.11]).”
Since this is a paired t-test we’ll use the same strategy as the walkthrough.
Step 2: Define success#
Q1: What is the average difference in misses between vehicle control and SK609 rodents?#
Hint: Calculate the center (average) of the confidence interval; the CI is bolded in the caption above.
Checked variables:
q1_change- A number indicating the average number of fewer missed prompts between treated and vehicle controls.
Total Points |
5 |
|---|---|
Public Checks |
1 |
Points: 5
q1_change = ...
print(f'On average, during an SK609 trial the rodent missed {q1_change} fewer prompts than vehicle controls.')
grader.check("q1_change")
Q2: Calculate the effect size.#
Hint: Use the change just defined in Q1.
Assume from our domain knowledge and inspection of the figure that there is an error of 3.5 misses.
Checked variables:
q2_effect_size- The cohen’s-D effect size for this experiment.Should be a number (float)
Hint
The effect size is the ratio of the change to the error. Use the q1_change calculated above.Total Points |
5 |
|---|---|
Public Checks |
1 |
Points: 5
error = 3.5
q2_effect_size = ...
print(f'The normalized effect_size of SK609 is {q2_effect_size:0.3f}')
grader.check("q2_effect_size")
Step 3: Define your tolerance for risk#
For this assignment consider that we want to have 80% chance of detecting a true effect and a 1% chance of falsely accepting an effect.
Checked variables:
power- The desired power. Should be a number:0.7(representing 70%)alpha- The desired alpha threshold. Should be a number:0.05(representing 5%)
Total Points |
5 |
|---|---|
Public Checks |
2 |
Points: 5
power = ...
alpha = ...
grader.check("q3_tolerance")
Step 4: Define a budget#
In the figure caption we see that the paper used a total of 16 mice:
“Difference in VI measurements calculated against previous day vehicle performance in rats (n=16) showed SK609 improved sustained attention performance …”
Step 5: Calculate#
Q4: Calculate the minimum change detectable with 16 animals.#
Use alternative='two-sided' and as we do not know whether the number of misses is always increasing.
Also, use contrast='paired' as we are doing a paired test we are compairing the same mice across each category.
Hint: Use the power-calculator, and then use that effect size to calculate the min_change.
Checked variables:
q4_effect_size- The minimum detectable effect size given N, alpha, and power.Should be a number (the result from
pg.power_ttest())Leave
d = Nonewhen callingpg.power_ttest()(this is what we’re solving for)
q4_min_change- The minimum change in misses that we can detect.Should be a number calculated as:
q4_effect_size * error
Hint
Refer to the Module 10 Walkthough Step 5 for a review of how to use `pg.power_ttest`Total Points |
5 |
|---|---|
Public Checks |
2 |
Points: 5
q4_effect_size = ...
print('The effect size is:', q4_effect_size)
# What is the minimum change that we can detect at this power?
q4_min_change = ...
print(f'with 16 animals, one could have detected as few as {q4_min_change:0.2f} min change.')
grader.check("q4_min_effect")
Step 6: Summarize#
Let’s propose a handful of different considerations for our experiment. As before, we’ll keep the power and alpha the same, but we’ll add the following experimental changes:
A grant reviewer has commented on the proposal and believes that your estimate of the error is too optimistic. They would like you to consider a scenario in which your error is 50% larger than the current estimate.
A new post-doc has come from another lab that has a different attention assay. Their studies show that it has 25% less error than the current one.
Consider these two experimental changes and how they effect sample size choices.
Q5: Calculate new effect sizes for these conditions.#
Hint: Refer to the bolded experimental changes above and adjust the errors then the effect sizes, keeping in mind the q1_change variable.
This can be done in two steps if needed.
Checked variables:
q5_high_noise_effect_size- The minimum detectable effect size in a high error consideration.Should be a number (int or float)
High noise scenario: error increases by 50%, so
new_error = error * 1.5
q5_new_assay_effect_size- The minimum detectable effect size in a new assay configuration.Should be a number (int or float)
New assay scenario: error decreases by 25%, so
new_error = error * 0.75
Note: Use q1_change from Q1 and error = 3.5 from Q2
Total Points |
5 |
|---|---|
Public Checks |
2 |
Points: 5
q5_high_noise_effect_size = ...
q5_new_assay_effect_size = ...
print(f'Expected effect_size {q2_effect_size:0.2f}')
print(f'High noise effect_size {q5_high_noise_effect_size:0.2f}')
print(f'New assay effect_size {q5_new_assay_effect_size:0.2f}')
grader.check("q5_multiple_choices")
# DO NOT EDIT
# Check many different sample sizes
sample_sizes = np.arange(1, 31)
names = ['Expected', 'High-Noise', 'New-Assay']
colors = 'krb'
effect_sizes = [q2_effect_size, q5_high_noise_effect_size, q5_new_assay_effect_size]
fig, ax = plt.subplots(1,1)
# Loop through each observation size
for name, color, effect in zip(names, colors, effect_sizes):
# Calculate the power across the range
powers = pg.power_ttest(d = effect,
n = sample_sizes,
power = None,
alpha = alpha,
contrast = 'paired')
ax.plot(sample_sizes, powers, label = name, color = color)
ax.legend(loc = 'lower right')
ax.set_ylabel('Power')
ax.set_xlabel('Sample Size')
The plot above shows the expected power, the likelihood of detecting an effect, as a function of the sample size of the experiment. The black line represents the current experimental system. The red line indicates the high noise worst-case scenario presented by the grant reviewer. And the blue line shows the effect of the newly designed system. Use this to answer the questions below.
Q6 Summary Questions#
Assume an 80% power threshold for the following questions.
Checked variables:
q6a- Would an experiment that had sample size of 15 be sufficiently powered to detect an effect under the expected assumption? yes/noShould be a string: either
'yes'or'no'(lowercase)Look at the plot above to see if n=15 reaches 80% power for the expected (black line) scenario
q6b- Would an experiment that had sample size of 15 be sufficiently powered to detect an effect under the high-noise assumption? yes/noShould be a string: either
'yes'or'no'(lowercase)Look at the plot above to see if n=15 reaches 80% power for the high-noise (red line) scenario
q6c- How many fewer animals could be used if the new experiment was implemented vs. the expected/current one (using 80% power)? (number)Should be a number (round up to whole animals)
Use
pg.power_ttest()twice to calculate the required sample sizes for:Standard assay (using
q2_effect_size)New assay (using
q5_new_assay_effect_size)
Then find the difference and round up
Total Points |
5 |
|---|---|
Included Checks |
3 |
Hidden Tests |
3 |
Points: 5
# Would an experiment that had nobs=15 be sufficiently powered
# to detect an effect under the expected assumption?
# 'yes' or 'no'
q6a = ...
# Would an experiment that had nobs=15 be sufficiently powered
# to detect an effect under the high-noise assumption?
# 'yes' or 'no'
q6b = ...
# How many fewer animals could be used if the new experiment was implemented
# vs. the expected/current one (using 80% power)?
q6c = ...
grader.check("q6")
grader.check_all()
Submission#
Check:
That all tables and graphs are rendered properly.
Code completes without errors by using
Restart & Run All.All checks pass.
Then save the notebook and the File -> Download -> Download .ipynb. Upload this file to BBLearn.