Compute the mean and standard error of paired before-and-after differences
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `paired_diff_mean_se(before, after)` in `solution.py`. Each unit is measured once before and once after a change, and the two arrays are aligned by index. Compute the per-unit differences `d = after - before` and return `(mean_diff, se_diff)`.
```python
def paired_diff_mean_se(before: np.ndarray, after: np.ndarray) -> tuple:
...
```
Requirements:
- The difference is `after` minus `before`.
- `mean_diff = mean(d)`.
- `se_diff = np.std(d, ddof=1) / sqrt(n)`, using the sample standard deviation (`ddof=1`, not `ddof=0`).
- Return exactly two Python floats, `(float, float)`.
Example:
```python
before = [10, 13, 8, 17, 12, 10, 15, 14]
after = [12, 16, 9, 21, 14, 13, 18, 17]
paired_diff_mean_se(before, after)
# -> (2.625, 0.3238992347717331)
```
```hint Check the default
Look up which `ddof` NumPy's `np.std` uses when you do not pass one, and compare it with what the standard error of a sample mean needs.
```
### Constraints & Assumptions
- `before` and `after` have the same length `n`, with `n >= 2` so the sample standard deviation is defined.
- Inputs may be NumPy arrays or Python lists (the example passes lists).
- Values are numeric with no missing entries.
### What a Strong Answer Covers
- Differences taken per unit in the stated direction, which turns the task into a one-sample problem.
- The sample standard deviation with `ddof=1`, divided by the square root of `n`.
- Input handling for lists or arrays, and plain float outputs.
- Why pairing changes the standard error compared with treating the two sets of measurements as independent groups.
### Follow-up Questions
- Why is the paired SE smaller than an unpaired two-sample SE?
- How would you turn these two numbers into a hypothesis test?
- What should the function do with missing measurements or fewer than two units?
Overview: Write a function that returns the mean and standard error of paired before and after differences. Tests the paired design, the sample standard deviation with ddof=1, and why pairing shrinks the standard error compared with an unpaired comparison.