LoslegenKostenlos loslegen

Permutation practice

Are NBA players heavier than US adult males? You are now interested in calculating the 95% confidence interval of the mean difference (in kilograms) between NBA players and US adult males. You'll use the two lists provided.

Permutation is great when testing for difference, so that's the resampling method you'll use here!

nba_weights = [96.7, 101.1, 97.9, 98.1, 98.1, 100.3, 101.0, 98.0, 97.4, 100.5, 100.3, 100.2, 100.6]
us_adult_weights = [75.1, 100.1, 95.2, 81.0, 72.0, 63.5, 80.0, 97.1, 94.3, 80.3, 93.5, 85.8, 95.1]

Note that each of the above lists has 13 weights listed.

The following have been imported for you: random, numpy as np, seaborn as sns, and matplotlib.pyplot as plt.

Diese Übung ist Teil des Kurses

Monte Carlo Simulations in Python

Kurs anzeigen

Anleitung zur Übung

  • Define all_weights as a list which contains the values from both nba_weights and us_adult_weights.
  • Perform the permutation on all_weights using np.random.permutation().
  • Assign the first 13 permutated samples to perm_nba and the remaining 13 to perm_adult.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Define all_weights
all_weights = ____
simu_diff = []

for i in range(1000):
	# Perform the permutation on all_weights
    perm_sample = ____
    # Assign the permutated samples to perm_nba and perm_adult
    perm_nba, perm_adult = ____, ____
    perm_diff = np.mean(perm_nba) - np.mean(perm_adult)
    simu_diff.append(perm_diff)
mean_diff = np.mean(nba_weights) - np.mean(us_adult_weights) 
upper = np.quantile(simu_diff, 0.975)
lower = np.quantile(simu_diff, 0.025)
print(mean_diff, lower, upper)
Code bearbeiten und ausführen