I want it to run
Claude: AI-drafted suggestion from a review of these notes (Nov 2026), posted from David's account. Not yet checked by David.
Issue (E-35): The section stops at a wish: a specification table (test_models) and four hand-written model calls, with no code that runs the models from the table.
Suggestion: One way to run the models from the table (code not run here; there is no R in this environment):
```r fit_spec <- function(df, filter, y, x, model, family) { d <- get(df) if (filter != "") d <- dplyr::filter(d, !!rlang::parse_expr(filter)) f <- reformulate(trimws(strsplit(x, ",")[[1]]), response = y) if (model == "glm") glm(f, data = d, family = family) else lm(f, data = d) }
results <- test_models %>% mutate( fit = pmap(list(df, filter, y, x, model, family), fit_spec), coefs = map(fit, broom::tidy), summ = map(fit, broom::glance) )
one row per coefficient
results %>% select(dataset = df, filter, y, coefs) %>% unnest(coefs)
one row per model
results %>% select(dataset = df, filter, y, summ) %>% unnest(summ) ```
Each row of the table becomes one call to fit_spec(). get() fetches the data frame by name, the filter string is parsed as in the 'lists of filters' section, and reformulate() builds the formula from the comma-separated regressors. The fitted models sit in a list-column, and tidy() and glance() turn them into the two standard result tables. The spec column df is renamed before unnesting because glance() returns a column of the same name. One caution about the example itself: the disp < 100 subset of mtcars has 5 cars, so the second specification estimates four coefficients from five observations.