簡體   English   中英

用最小二乘法繪制調整回歸

[英]Plotting adjusted regression with least squares

我有一個裝有最小二乘法的回歸 model。

library(TSA)
data(hours)
lmhr2 <- lm(hours ~ time(hours)+ I(time(hours)^2), data =hours) 
summary(lmhr2)

plot(hours)
abline(lmhr2)

當我運行abline到 plot 時,出現以下錯誤:

在 abline(lmhr2) 中:僅使用 3 個回歸系數中的前兩個

您可以使用ggplot2::geom_smooth()

library(TSA)
library(ggplot2)
data(hours)

data.frame(time = time(hours), hours = hours) |>  
  ggplot(aes(time, hours)) +
  geom_smooth(method = lm, formula = y ~ x + I(x^2))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM