0

I have a regression model fitted with least squares.

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

plot(hours)
abline(lmhr2)

When I run abline to the plot, I get this error:

In abline(lmhr2) : only using the first two of 3 regression coefficients

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
Nana
  • 13
  • 4
  • 1
    Have you looked at this? https://stackoverflow.com/questions/54737007/how-do-i-fix-the-abline-warning-only-using-first-two-coefficients – dcsuka Nov 28 '22 at 01:10
  • doesnt work, I put it up – Nana Nov 28 '22 at 01:14
  • 1
    You will need to use the `predict()` function to calculate the dependent variable for a sequence of "hours" – Dave2e Nov 28 '22 at 01:41
  • 1
    @Dave2e, please post as an answer? – Ben Bolker Nov 28 '22 at 02:19
  • 1
    Ben, If Nana took the time to accept the answers to the previous questions, I would take more time to provide a formal answer. https://stackoverflow.com/help/someone-answers – Dave2e Nov 28 '22 at 02:45

1 Answers1

0

You can plot your model using 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))

zephryl
  • 14,633
  • 3
  • 11
  • 30