I want to augment the data frame with .fitted
columns from broom::augment()
for different lm()
models so that I can compare the predictions later. I (re)name() the .fitted
column for each model, but augment()
also adds .rownames
.se.fit
, etc., columns. So when I run augment()
for the second model I get
Error: Column
.rownames
must have a unique name
for each of the columns from augment()
that I am not interested in.
I end up un-selecting each of the columns from augment()
that I am not interested in. I have to do this after each call to augment()
.
{r}
require(tidyverse)
require(broom)
require(ISLR)
lm.obj <- lm(mpg ~ horsepower, data = Auto)
Auto <- Auto %>%
augment(x = lm.obj) %>%
rename(mpg_pred_linear = .fitted)
qd.obj <- lm(mpg ~ horsepower + I(horsepower^2), Auto)
Auto <- Auto %>%
augment(x = qd.obj) %>%
rename(mpg_pred_quad = .fitted)
I know I could use predict.lm()
instead, but in the course I am teaching I have already used augment()
to create the predictions, and I wanted consistency for my students.
Are there options in augment.lm()
that I am not finding that allow for customization of column names? Or choice of output columns?
I am not sure if this is a problem I just need to cope with, or if I should submit it as an issue instead. Please advise (or chastise) as you see fit.