[R-SIG-Finance] Error in lm prediction

amol gupta amolgupta87 at gmail.com
Sun Jul 16 22:31:03 CEST 2017


Hi

I am most likely committing an error in trying to predict  using linear
regression lm model. please help me figure out what am I doing wrong. I am
trying to regress a index and its constituents. Here is the code


#split ts inttwo parts
a<-300;

x1<-x[1:a,];
y1<-y[1:a,];

x2<-x[(a+1):nrow(x),];
y2<-y[(a+1):nrow(y),];


#regression
m1<-lm( y1~x1)
r1<-residuals(m1)
coef(m1)

##out of sample
y_hat<-predict.lm(m1,x2);
r2<-y_hat-y2;


x,y are xts. X contains multiple time series. The y_ hat turns out to be of
300 samples only, whereas x2 contains 1400 samples.

Please help me figure out how to predict using model that I have found
using regression.


-- 
Regards
Amol
+91-9897860992
+91-8889676918

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list