Functionals, Function Factories, and Function Operators
Author
Brian Helsel
Published
October 7, 2026
Assignment. Practice using functionals, function factories, and function operators to improve your programming skillset.
Functionals: Run Multiple Regressions. Use a functional to fit a separate regression of mpg on each predictor. Extract the coefficient, p-value, and R2 from each model. Combine the results into a data frame showing one row per predictor.
Function Factories: Create a Model Factory. Create a function called make_modeler that takes a dataset and an outcome variable and returns a function that fits a linear model using a predictor supplied later. Use it to fit models predicting mpg and modify the returned function so it returns a tidy summary of the model rather than the entire model object.