1
votes

I want to plot and generate new data based on my Regression Model which I created:

Trend <- seq(1:length(Daten$TSLAC))

TISPYNVDA_TSLA <- lm(TSLAC ~ Trend + SPYC * NVDAC, data = Daten)

summary(TISPYNVDA_TSLA)

plot(predict(TISPYNVDA_TSLA), type = "l", 
     xlab="geschätzte Werte der abh. Variablen", 
     ylab="geschätzte Residuen", main="Residuenplot", pch=20)

lines(Daten$TSLAC, col="red")

As seen above, I created a trend sequence for the creation of future data with:

newline <- data.frame(wt=predict(TISPYNVDA_TSLA))

The function:

TISPYNVDA_TSLA <- lm(TSLAC ~ Trend + SPYC * NVDAC, data = Daten)

creates the regression. After that, I plot the regression together with the real data on TSLAC (Tesla Close Price).

Then I want to predict further afterwards as a "future prediction".

How can I do that?

I tried the predict() function, but it's not working:

lines(252:350,predict(newline,newdata=newline))

252 because the data is going to 251, then it should predict in the future.

Could you post your output? - Gonzalo Donoso
In predict(newline, newdata=newline), I think you want predict(TISPYNVDA_TSLA, newdata=newline) instead. - smanski
@smanski thanks for the quick answer. However, if I change it to your idea my output says: "Error in eval(predvars, data, env) : object 'SPYC' not found" Is there any other way to generate a new predictive plot or did i made a mistake? - Aron1894
@GonzaloDonoso Thanks for the quick answer, my output is: "Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "data.frame"" Maybe the way i generate is a little bit wrong? - Aron1894
@Aron1894 newdata in predict needs to be a dataframe with columns for all variables used in your linear model. When you say "future predictions", you need to specify what these future X values are. - smanski