Get startedGet started for free

Visualizing the relationship

Now that we've gone over the effect on certain errors and calculated the necessary sample size for different power values, let's take a step back and look at the relationship between power and sample size with a useful plot.

In this exercise, we'll switch gears and look at a t-test rather than a z-test. In order to visualize this, use the plot_power() function that shows sample size on the x-axis with power on the y-axis and different lines representing different minimum effect sizes.

This exercise is part of the course

Practicing Statistics Interview Questions in Python

View Course

Exercise instructions

  • Assign a TTestIndPower() object to the results variable.
  • Visualize the relationship between power and sample size using the plot_power() function with the appropriate parameter values; what do you notice?

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

sample_sizes = np.array(range(5, 100))
effect_sizes = np.array([0.2, 0.5, 0.8])

# Create results object for t-test analysis
from statsmodels.stats.power import TTestIndPower
results = ____

# Plot the power analysis
results.plot_power(dep_var='nobs', nobs=____, effect_size=____)
plt.show()
Edit and Run Code