轉換解釋變數
如果反應變數與解釋變數之間沒有線性關係,有時可以透過轉換一個或兩個變數來建立線性關係。這裡,你要嘗試轉換解釋變數。
你會再看一次臺灣房地產資料集,這次把距離最近捷運站的距離當作解釋變數。你會用程式碼實現通勤族的夢想:把到捷運站的距離開平方根,讓距離變短。地理條件,讓開!
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)