针对非线性关系进行调整
接下来的三个示例使用的数据集都不满足线性回归的技术条件。对于每个示例,您将对数据进行变换,使残差图呈现随机散点的样子。
在第一个示例中,变量之间似乎不存在线性关系。
本练习是课程的一部分
R 中的线性回归推断
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Run this to see how the model looks
ggplot(hypdata_nonlinear, aes(x = explanatory, y = response)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
# Model response vs. explanatory
model <- ___
# Extract observation-level information
modeled_observations <- ___
# See the result
modeled_observations
# Using modeled_observations, plot residuals vs. fitted values
___ +
# Add a point layer
___ +
# Add horizontal line at y = 0
___