在线性回归中绘制交互项

Graphing Interaction Terms in Linear Regression

我不明白下面的错误是什么意思。

代码:

library(interactions)

df = read.csv(file="birthweight_data.csv", sep=",")[c("fnocig", "fage", "fedyrs")]
df=rename(df, `Cigarettes Smoked Per Day` = `fnocig`)
df=rename(df, `Father's Age` = `fage`)
df=rename(df, `Years of Education` = `fedyrs`)

model = lm(`Cigarettes Smoked Per Day` ~ `Father's Age` + `Years of Education`, data = df)

interact_plot(model, pred=`Father's Age`, modx=`Years of Education`, plot.points=TRUE)

错误:

数据帧print(df):

根据 interact_plot 文档中的示例,您需要在 lm() 调用中拟合预测变量和调节变量之间的交互项。

尝试:

lm(`Cigarettes Smoked Per Day` ~ `Father's Age` * `Years of Education`, data = df)