開始使用免費開始

線性迴歸

你可以使用 lm() 函式來執行簡單線性迴歸。在這個練習中,你會將 ageshuckedWeight 作為自變數(或由它來預測)來配適模型。你會把模型結果儲存成一個物件,接著從這個輸出物件中顯示元素,例如 coefficients

你也會對模型物件執行 summary(),並將其輸出儲存到另一個物件中。該物件包含與模型擬合相關的元素,例如 r.squaredadj.r.squaredabaloneKeep 資料集已為你載入。

本練習屬於課程

給 SAS 使用者的 R

檢視課程

練習說明

  • 使用 lm() 以 shucked weight 對 age 進行簡單線性迴歸。將輸出儲存為 lmshucked
  • lmshucked 顯示 coefficients 元素,以取得截距與斜率的模型係數。
  • lmshucked 執行 summary(),並將輸出儲存為 smrylmshucked
  • 從摘要輸出物件 smrylmshucked 中,顯示 r.squaredadj.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
___
___
編輯並執行程式碼