1

The error is

Error in x$terms %||% attr(x, "terms") %||% stop("no terms component nor attribute") : no terms component nor attribute

To the code

cooked2 <- data.frame(cooked = c(1, 3, 6, nrow = 1) )#predicting with 1,3 and 6 times cooking
predict.lm(model2, newdata = cooked2, interval = "prediction")

Not able to guess what is the issue, since in another code it worked.

Works here

ig1 <- data.frame(ig = c(10, 100, 200)) #predicting with 10,100 and 200 followers
predict.lm(model, newdata = ig1)  #predicting with lm since we use lm models in TASK 1

Edit : Model 2 is created by

cor(dw$wb, dw$cooked) #predic ting with the variable cooked

#the result is 0.6047707 which shows the variables are close to postively correlated.

#Now with the help of lm( ) function, we are going to make a linear model. #lm( ) function has two attributes first is a formula where we will use “ wb~ cooked” #because cooked is an independent variable and wb is a dependent variable r

model2 <- lm(wb ~ cooked, data = dw)
print(model2)
summary(model2)

cafeco09
  • 19
  • 2
  • I removed nrow still getting the same error, is there any way to use upper and lower limit here? – cafeco09 Nov 02 '21 at 22:06
  • How did you make "model2"? Please edit your question to allow us to replicate the issue, e.g. [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) / [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – jared_mamrot Nov 02 '21 at 22:17
  • Welcome to Stackoverflow. Worth noting that `vector` is neither `matrix` nor `data.frame`, and none of your examples point towards `vector(mode = 'numeric & etc'`, so you might, for clarity, drop vector from title, unless of course it is a vector you want, in which case, drop data.frame and nrow... – Chris Nov 02 '21 at 22:24
  • @jared_mamrot, edited with model 2 – cafeco09 Nov 02 '21 at 22:25

1 Answers1

0

Based on the info provided, please test:

model2 <- lm(wb ~ cooked, data = dw)
cooked2 <- data.frame(cooked = c(1, 3, 6))
predict(model2, newdata = cooked2)
predict(model2, newdata = cooked2, interval = "prediction")

Do these return the same error?

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • Turns out I set model 2 as a variable in creating a ggplot too, that was causing an issue, thanks for pointing out the problem can be in using model 2 – cafeco09 Nov 02 '21 at 22:40
  • 1
    You're welcome. Please note, per ['What should I do when someone answers my question?'](https://stackoverflow.com/help/someone-answers) "Comments are meant for requesting clarification, leaving constructive criticism, or adding relevant but minor additional information – not for socializing. If you want to say "thank you," vote on or accept that person's answer, or simply pay it forward by providing a great answer to someone else's question." – jared_mamrot Nov 02 '21 at 22:43