"#plot the regression line
plot(data$speed,data$power, col = "blue", xlab = "speed", ylab = "power")
abline(speedpower1, lwd=5, col="red")

#prediction
say <- data.frame(data$speed = 8.7)
predict(speedpower1, say)

Why would this error occur? Thanks!

"say <- data.frame(data$speed = 8.7)
Error: unexpected '=' in "say <- data.frame(data$speed ="

When R reads `data$speed`

, it 'thinks' you want the contents of that vector, but I'm guessing you just want to create a column with that name -- is that right?

yes, i figured it out. Thanks for the help

h say <- data.frame(speed=8.7)

predict(speedpower1, say)
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
object is not a matrixmm. then this.

any help. thanks

What is `speedpower1`

? Where did it come from?

it is a "list of 12" values.

#plot the regression line
plot(data$speed,data$power, col = "blue", xlab = "speed", ylab = "power")
abline(speedpower1, lwd=5, col="red")

#prediction
say <- data.frame(speed = 8.7)
predict(speedpower1, say)

Could you post the output to `str(speedpower1)`

?

str(speedpower1)
List of 12
coefficients : Named num [1:2] 8.92 2.45
..- attr(*, "names")= chr [1:2] "(Intercept)" "power"
residuals : Named num [1:2544] -6.016 -1.316 2.153 0.378 0.333 ...
..- attr(, "names")= chr [1:2544] "1" "2" "3" "4" ...
effects : Named num [1:2544] -891.842 373.019 2.287 0.499 0.454 ...
..- attr(*, "names")= chr [1:2544] "(Intercept)" "power" "" "" ...
rank : int 2
fitted.values: Named num [1:2544] 8.92 8.92 12.35 16.02 16.27 ...
..- attr(*, "names")= chr [1:2544] "1" "2" "3" "4" ...
assign : int [1:2] 0 1
qr :List of 5
.. qr : num [1:2544, 1:2] -50.4381 0.0198 0.0198 0.0198 0.0198 ...
.. ..- attr( , "dimnames")=List of 2
.. .. .. : chr [1:2544] "1" "2" "3" "4" ...
.. .. .. : chr [1:2] "(Intercept)" "power"
.. ..- attr(, "assign")= int [1:2] 0 1
.. qraux: num [1:2] 1.02 1.02
.. pivot: int [1:2] 1 2
.. tol : num 1e-07
.. rank : int 2
..- attr( , "class")= chr "qr"
df.residual : int 2542
xlevels : Named list()
call : language lm(formula = speed ~ power, data = data)
terms :Classes 'terms', 'formula' language speed ~ power
.. ..- attr(, "variables")= language list(speed, power)
.. ..- attr( , "factors")= int [1:2, 1] 0 1
.. .. ..- attr(, "dimnames")=List of 2
.. .. .. .. : chr [1:2] "speed" "power"
.. .. .. .. : chr "power"
.. ..- attr( , "term.labels")= chr "power"
.. ..- attr(, "order")= int 1
.. ..- attr( , "intercept")= int 1
.. ..- attr(, "response")= int 1
.. ..- attr( , ".Environment")=<environment: R_GlobalEnv>
.. ..- attr(, "predvars")= language list(speed, power)
.. ..- attr( , "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. ..- attr(, "names")= chr [1:2] "speed" "power"
model :'data.frame': 2544 obs. of 2 variables:
.. speed: num [1:2544] 2.9 7.6 14.5 16.4 16.6 1.6 10.1 23.8 42.4 18.9 ...
.. power: num [1:2544] 0 0 1.4 2.9 3 0 0.2 6.2 7.4 3.5 ...
..- attr(*, "terms")=Classes 'terms', 'formula' language speed ~ power
.. .. ..- attr(*, "variables")= language list(speed, power)
.. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. : chr [1:2] "speed" "power"
.. .. .. .. ..$ : chr "power"
.. .. ..- attr( , "term.labels")= chr "power"
.. .. ..- attr(, "order")= int 1
.. .. ..- attr( , "intercept")= int 1
.. .. ..- attr(, "response")= int 1
.. .. ..- attr( , ".Environment")=<environment: R_GlobalEnv>
.. .. ..- attr(, "predvars")= language list(speed, power)
.. .. ..- attr( , "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. .. ..- attr(*, "names")= chr [1:2] "speed" "power"

attr(*, "class")= chr "lm"
Thanks for the help!!!

Sure: When you post here, you should do it this way:

```
```
<--- paste here, including the ```s
```
```

Could you do that?

No worries, but could you re-post

JamesVU2000:

str(speedpower1)
List of 12
coefficients:Namednum[1:2]8.922.45..βattr(β,"names")=chr[1:2]"(Intercept)""power" coefficients : Named num [1:2] 8.92 2.45 ..- attr(*, "names")= chr [1:2] "(Intercept)" "power" residuals : Named num [1:2544] -6.016 -1.316 2.153 0.378 0.333 ...

the way I suggested?

I am sorry. I dont understand. Do you want me to copy and paste code into another area? is the what the arrow means?

You could click the 'Edit' icon on your post, and type ``` before and after the code you already posted there -- could you try that?

I am still confused, but I did try to edit. Is there a faq i could read to understand better?

Could you run `summary(speedpower1)`

and paste the output here between a pair of triple backticks, like this?

```
```
<---- paste output here
```
```

```
Call:
lm(formula = speed ~ power, data = data)
Residuals:
Min 1Q Median 3Q Max
-25.334 -3.953 -0.716 2.202 49.884
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 8.91611 0.21134 42.19 <2e-16 ***
power 2.45036 0.04515 54.27 <2e-16 ***
---
Signif. codes: 0 β***β 0.001 β**β 0.01 β*β 0.05 β.β 0.1 β β 1
Residual standard error: 6.874 on 2542 degrees of freedom
Multiple R-squared: 0.5367, Adjusted R-squared: 0.5365
F-statistic: 2945 on 1 and 2542 DF, p-value: < 2.2e-16
```

thanks for the help. I am trying to do a regression with predict function

1 Like

This shows that you're predicting speed data from power data, so you need new power data to make new predictions.

This shows you're trying to supply speed data to the `predict()`

function, but you need to supply power data. Could you try that?

yes, thank you for the help

1 Like

unexpected error in ggplot with time series

```
autoplot(ts(train$Prices.BE,frequency = 24, ylab = "Price BE")
autoplot(ts(train$Prices.BE,frequency = 24, ylab = "Price BE", ylim = (c,200))
```

Hi @JamesVU2000 : You should post a separate question since this is unrelated to your original question, and you should include 1) the data you're using, 2) the code and packages you're using, and 3) the error messages you're getting. The best way to do this is to follow this guide: FAQ: How to do a minimal reproducible example ( reprex ) for beginners .