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.
Deze oefening maakt deel uit van de cursus
Monte Carlo Simulations in Python
Oefeninstructies
- Define
all_weightsas a list which contains the values from bothnba_weightsandus_adult_weights. - Perform the permutation on
all_weightsusingnp.random.permutation(). - Assign the first 13 permutated samples to
perm_nbaand the remaining 13 toperm_adult.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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)