線性迴歸
你可以使用 lm() 函式來執行簡單線性迴歸。在這個練習中,你會將 age 以 shuckedWeight 作為自變數(或由它來預測)來配適模型。你會把模型結果儲存成一個物件,接著從這個輸出物件中顯示元素,例如 coefficients。
你也會對模型物件執行 summary(),並將其輸出儲存到另一個物件中。該物件包含與模型擬合相關的元素,例如 r.squared 和 adj.r.squared。abaloneKeep 資料集已為你載入。
本練習屬於課程
給 SAS 使用者的 R
練習說明
- 使用
lm()以 shucked weight 對 age 進行簡單線性迴歸。將輸出儲存為lmshucked。 - 從
lmshucked顯示coefficients元素,以取得截距與斜率的模型係數。 - 對
lmshucked執行summary(),並將輸出儲存為smrylmshucked。 - 從摘要輸出物件
smrylmshucked中,顯示r.squared與adj.r.squared元素。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Run lm() of age by shuckedWeight, save output as lmshucked
lmshucked <- lm(___ ~ ___, data = ___)
# Display coefficients element from lmshucked
___
# Save summary() output of lmshucked as smrylmshucked
___
# Show r.squared and adj.r.squared elements of smrylmshucked
___
___