我将如何在以下线性模型中提取特定棒球队的提取残差数据?例如,我将如何提取“CLE”的残差?
library(Lahman)
library(dplyr)
library(broom)
# create baseball team data
data(Teams)
teams <- Teams
teams <- teams %>% mutate(win_percentage = (W / (W + L)) * 100)
# summarize baseball team salary by year
salaries <- Salaries
salaries <- salaries %>%
group_by(teamID, yearID, lgID) %>%
summarise(payroll_M = sum(as.numeric(salary)) / 10^6) %>%
ungroup()
# add winning percentage to the salary table
salaries <- teams %>%
select(yearID, teamID, win_percentage) %>%
right_join(salaries, by = c("yearID", "teamID"))
# compute linear model of winning vs team salary
model <- salaries %>%
group_by(yearID) %>%
do(fit = augment(lm(win_percentage ~ payroll_M, data = .)))
# extract residuals for Cleveland ??????