Skip to content

Linear Model Prediction

6 messages · cm, Uwe Ligges, michael.weylandt at gmail.com (R. Michael Weylandt +1 more

cm
#
I have data X and Y, and I want to predict what the very next point would be
based off the model. This is what I have:
I think I want to use the predict function, but I'm not exactly sure what to
do.

Thank you!



--
View this message in context: http://r.789695.n4.nabble.com/Linear-Model-Prediction-tp4637644.html
Sent from the R help mailing list archive at Nabble.com.
#
On 24.07.2012 20:20, cm wrote:
Hmmm, are you sure about the above code?
Yes, use predict().

Is this homework?


Uwe Ligges
On Jul 24, 2012, at 1:38 PM, cm <bunnylover23 at optonline.net> wrote:

            
You need to supply newdata=  . predict() without new data gives predicted values for the predictors you for the model to. 

Incidentally, repeating Uwe -- are you sure you want x~y ?

Michael
cm
#
Yes, why wouldn't I? It's a linear model between two sets of data: x and y.
 
Also, what would the new data be if i want to predict into the future? So,
for example, the data goes from a month ago to today. I want to predict what
tomorrow's data would be. So what is "newdata"?




--
View this message in context: http://r.789695.n4.nabble.com/Linear-Model-Prediction-tp4637644p4637660.html
Sent from the R help mailing list archive at Nabble.com.
#
Hello,

The example below gives you some information about using predict().?? This was originally used to predict NAs. 


dat1<-data.frame(Year=1962:1986,Discharge=c(rnorm(15,25),rep(NA,5),1:5))
lm1<-lm(Discharge~Year,dat1)
dat2<-data.frame(Year=dat1[,1])
dat1$fit<-predict(lm1,newdata=dat2)
#The code below is to replace the NA values with predicted. 

#dat1<-within(dat1,{Dischargenew<-ifelse(is.na(Discharge)==T,fit,Discharge)})
#dat1new<-dat1[,c(1:2,4)]


A.K.



----- Original Message -----
From: cm <bunnylover23 at optonline.net>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, July 24, 2012 2:20 PM
Subject: [R] Linear Model Prediction

I have data X and Y, and I want to predict what the very next point would be
based off the model. This is what I have:
I think I want to use the predict function, but I'm not exactly sure what to
do.

Thank you!



--
View this message in context: http://r.789695.n4.nabble.com/Linear-Model-Prediction-tp4637644.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.