Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Practicing Statistics Interview Questions in Python

Cursus bekijken

Oefeninstructies

  • 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?

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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()
Code bewerken en uitvoeren