Homework 01
Before you begin
Homework 01 contains six required questions on the mathematical and computing foundations used later in the course:
- matrix notation and least squares;
- the Gaussian likelihood for linear regression;
- nonconvex numerical optimization;
- near collinearity and coefficient instability;
- basic data preparation and summaries; and
- repeated measurements, selection bias, and causal interpretation in wearable data.
Complete all six questions. Use your work to identify any topics that you should revisit before they appear later in the course.
Questions 1 through 5 may be completed in either R or Python. Use software for numerical calculations, and show mathematical reasoning where a task asks for it. Use stable numerical routines, and explain the statistical meaning of each result rather than reporting code output alone.
First make a serious attempt using your current knowledge. You may then use an AI agent to clarify an error, check code, or compare approaches. You should still be able to explain every quantity that you report.
Download the materials
Extract the ZIP file inside the homework/ folder of your stat432-fall2026 repository. The ZIP creates week-01/, so the complete path is homework/week-01/:
week-01/
├── homework-01.qmd
├── solutions-01.qmd
└── data/
└── data-manipulation.csv
The data file can also be downloaded separately:
Work in homework/week-01/ and write your answers in homework-01.qmd. Render the completed file as homework-01.html or homework-01.pdf. That rendered report is the file you submit through GitHub.
Question 1 (Least squares and matrix calculations)
Set the random seed to 43201. Generate observations with predictors according to
with all predictors and errors generated independently. Let
and generate
Generate the data and report the dimensions and rank of . Calculate the least-squares estimate using a numerically stable least-squares routine, without explicitly calculating . Compare the estimates with the coefficients used to generate the data.
Calculate the fitted values, the residual vector , and the training root mean squared error
- Report . Explain why this value should be close to zero and what it tells us about the residual vector.
Question 2 (Gaussian likelihood for linear regression)
Continue with the data from Question 1. Suppose
The log-likelihood, including the constant term, is
For fixed , explain why maximizing over is equivalent to minimizing the residual sum of squares. What does this imply about the maximum-likelihood estimate of ?
For fixed , differentiate the log-likelihood with respect to and derive its maximum-likelihood estimate. Calculate this estimate at and compare it with the unbiased estimate of . Explain why the two denominators differ.
Let
Using the variance estimate from part b, plot
over a grid of values from to . State where the maximum occurs and explain why this agrees with the least-squares result.
Question 3 (Starting values in nonconvex optimization)
Consider the function
with derivative
Plot over the interval . Based on the plot, describe the important features of the objective function that may affect numerical optimization.
Use BFGS to minimize twice, starting at and . Supply to the optimizer. For each run, report the final value of , the final objective value, , and whether the optimizer reported convergence.
Explain why the two runs can converge to different answers. Which run gives the lower objective value? What additional evidence would be needed before claiming that this point is the global minimum?
Question 4 (Nearly collinear predictors)
Continue with and from Question 1. Set the random seed to 43202 and generate
Define
and let
Use a numerically stable least-squares routine throughout.
Fit using and . For each design matrix, report the condition number and training RMSE. For the augmented fit, also report the coefficients of and .
Fit using . Report the changes in the coefficients of and . Compare the two fitted-value vectors using their root mean squared difference and maximum absolute difference.
Use the identity
to explain why the fitted values change very little while the two coefficients change substantially. What does this example suggest about interpreting separate effects for nearly collinear predictors?
Question 5 (Data preparation and summary statistics)
The file data/data-manipulation.csv is a small constructed data table containing an observation identifier, a group label, two numeric predictors, and a response. Some response values are missing. For analyses involving the response, use only observations with a recorded response. Do not replace a missing response with zero or a group mean.
- Read the data and report its dimensions, column types, number of duplicated identifiers, and number of missing values in each column. Create an analysis table containing only observations with a recorded response, and define
For each group, report the number of observations, the mean response, and the mean of
feature_sum. State clearly which observations these summaries describe.Sort the analysis table by response from largest to smallest and report the first three rows, including
observation_id,group,response, andfeature_sum. Add code checks verifying that the number of retained rows equals the number of nonmissing responses in the original data, that the analysis table has no missing response values, and that its identifiers are unique.
Question 6 (Can 39 million Fitbit records represent US adults?)
Patten et al. (2026) describe Fitbit data from 59,018 participants in the All of Us Research Program. The dataset spans 14 years and contains more than 39 million daily step records. Participants contributed data through one of two routes:
- Bring Your Own Device (BYOD): participants shared data from a Fitbit they already owned.
- Wearables Enhancing All of Us Research (WEAR): invited participants received a Fitbit at no cost.
In the general activity cohort, the BYOD and WEAR groups contained 32,035 and 22,474 participants, respectively. The BYOD value is listed first in each comparison below:
- 77.3% versus 55.1% reported being White;
- 6.1% versus 15.2% reported annual household income between and ; and
- median daily steps were 6,867 versus 5,797.
Suppose the target is the mean of the participant-specific average daily step counts among US adults during the study period, with each adult given equal weight. A researcher writes:
“This dataset contains more than 39 million daily Fitbit records. Therefore, the average of all recorded step counts should provide an accurate estimate of mean daily activity among US adults.”
Are the 39 million daily records independent observations? What characteristics or behaviors could cause some participants to contribute more recorded days than others? Explain how averaging all recorded days would then weight participants unequally.
BYOD participants reported a median of 6,867 daily steps, compared with 5,797 among WEAR participants. Does this comparison show that already owning a Fitbit causes people to walk more? Explain your answer and give at least one plausible alternative explanation based on how participants entered the two groups.
A very large dataset can still produce a biased estimate of a population quantity when the people and observations entering the dataset are selected. Using this study, explain how selection of both participants and recorded days could make the observed data differ from the US adult population. Why might the naive average of all recorded daily step counts fail to estimate the stated target? You do not need to determine the direction of the bias.
Source
Patten, T., Preble, E. A., Master, H., et al. (2026). The All of Us Research Program’s wearables dataset. Nature Medicine, 32, 2302-2310.