11.4.3. Homework#
Use this assignment to practice the chapter’s concepts and coding skills in runnable Python code.
Sign in from the account menu before you start working on the assignment.
Write and run your code directly in the coding cells.
Multiple submissions are allowed. The highest score is kept.
1. How Resampling Works
A bootstrap resample is drawn without replacement from the original sample and has the same size as the original sample.
2. Interval for a Mean
A 95% confidence interval for the mean order value is $42 to $48. This means that 95% of individual orders are between $42 and $48.
3. What “95% Confidence” Means
For a reliable approximate procedure under suitable sampling conditions, if we repeated the whole process many times (draw a new random sample, bootstrap it, build a 95% interval), about 95% of those intervals would contain the true parameter.
4. Lower Confidence
From the same bootstrap distribution, the 80% confidence interval is no wider than the 95% confidence interval.
5. Estimating a Maximum
A bootstrap confidence interval works well for estimating the highest salary paid by a large company from a random sample of its employees.
### 6. The Middle Half of Orders
# Describe individual order values (in dollars), not uncertainty in a mean.
# Use the chapter's nearest convention; this odd-size sample has the same
# ordinary median and nearest 50th percentile.
# 1. Compute the 25th, 50th, and 75th percentiles with method='nearest'.
# Print exactly:
# 25th percentile: 45
# Median: 49
# 75th percentile: 52
import numpy as np
import pandas as pd
orders = pd.Series([38, 52, 45, 61, 47, 55, 40, 49, 58, 44, 51, 46, 63, 42, 50])
### Your code starts here.
### Your code ends here.
25th percentile: 45
Median: 49
75th percentile: 52
### 7. One Bootstrap Resample
# Draw one bootstrap resample of orders with .sample(): same size,
# replacement, and random_state=7. Then summarize that resample.
# 1. Compute the mean of the resample, rounded to 2 decimals.
# 2. Count the distinct values in the resample with nunique().
# Print exactly:
# Resample mean: 50.67
# Distinct values: 9 of 15
import numpy as np
import pandas as pd
orders = pd.Series([38, 52, 45, 61, 47, 55, 40, 49, 58, 44, 51, 46, 63, 42, 50])
### Your code starts here.
### Your code ends here.
Resample mean: 50.67
Distinct values: 9 of 15
### 8. Interval for the Mean Order Value
# Generate 40 bootstrap means from orders: draw len(orders) values WITH
# replacement using rng.choice, and collect each mean in bootstrap_means.
# Set up the list before the loop. Keep the seed outside the loop.
# Then compute a central 95% interval with method='nearest'.
# Round only the displayed endpoints to 2 decimals.
# Forty repetitions make this a coarse workflow exercise; use thousands
# and check endpoint stability for a real management decision.
# Print exactly:
# 95% CI: 45.67 to 52.6
import numpy as np
import pandas as pd
orders = pd.Series([38, 52, 45, 61, 47, 55, 40, 49, 58, 44, 51, 46, 63, 42, 50])
rng = np.random.default_rng(434)
### Your code starts here.
### Your code ends here.
95% CI: 45.67 to 52.6
### 9. Sample Size and Interval Width
# Two surveys estimated the share of customers who use the mobile app.
# Survey A asked 100 customers; survey B asked 400.
# 1. Compute the width of each 95% interval, rounded to 3 decimals.
# 2. Compute how many times wider interval A is than interval B, rounded to 1 decimal.
# Print exactly:
# Width A: 0.18
# Width B: 0.09
# Ratio: 2.0
import numpy as np
import pandas as pd
interval_a = [0.31, 0.49] # n = 100
interval_b = [0.355, 0.445] # n = 400
### Your code starts here.
### Your code ends here.
Width A: 0.18
Width B: 0.09
Ratio: 2.0
### 10. Checking a Supplier's Claim
# A supplier claims a 5% defect rate. In a random sample of 300 parts, 18 (0.06)
# were defective. The 40 rounded bootstrap proportions below are supplied
# for arithmetic practice, not a complete supplier-approval analysis.
# 1. Compute the 95% confidence interval (method='nearest').
# 2. Check whether the claimed rate of 0.05 is inside the interval.
# Print exactly:
# 95% CI: 0.033 to 0.083
# Claim inside interval: True
import numpy as np
import pandas as pd
claimed = 0.05
bootstrap_props = pd.Series([0.043, 0.07, 0.033, 0.05, 0.093, 0.057, 0.063, 0.07, 0.067, 0.06,
0.033, 0.067, 0.043, 0.05, 0.047, 0.083, 0.04, 0.067, 0.057, 0.083,
0.057, 0.077, 0.083, 0.05, 0.057, 0.033, 0.06, 0.04, 0.06, 0.057,
0.067, 0.07, 0.063, 0.05, 0.067, 0.073, 0.05, 0.057, 0.053, 0.073])
### Your code starts here.
### Your code ends here.
95% CI: 0.033 to 0.083
Claim inside interval: True