转换自变量
当因变量与自变量之间不存在线性关系时,有时可以通过对一个或两个变量进行变换来构造出近似线性关系。这里,您将尝试转换自变量。
您将再次查看台湾房地产数据集,这次使用到最近 MRT(地铁)站的距离作为自变量。我们将用代码来实现每位通勤者的梦想:对到地铁站的距离取平方根,从而「缩短」距离。地理因素,接招吧!
taiwan_real_estate 可用,且已加载 ggplot2 和 tibble。
本练习是课程的一部分
R 中的回归入门
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Run the code to see the plot
# Edit so x-axis is square root of dist_to_mrt_m
ggplot(taiwan_real_estate, aes(dist_to_mrt_m, price_twd_msq)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)