[R] Error-linear regression

Saba Sehrish sabasehrish at yahoo.com
Fri Dec 18 05:12:23 CET 2015


Hi 
I am trying to apply linear regression on the attached data of two variables (DODGX, TRMCX) in R by taking time lag=5 for both of them. Each time I run this command, it gives me following error:

Error in lm.fit(x,y,offset = offset, singular.ok = singular.ok, ...) : 
NA/NaN/lnf in 'y' 
In addition: Warning message: 
In model.response(mf,"numeric") : NAs introduced by coercion

Following is the command:

library(lmtest)data<-read.csv(file="---",header=T,sep=",")
A<-as.matrix(data$DODGX) 
B<-as.matrix(data$TRMCX) 

nrow<-nrow(A) 
A1<-matrix(NA,nrow,1) 
A2<-matrix(NA,nrow,1)

A3<-matrix(NA,nrow,1)

A4<-matrix(NA,nrow,1)

A5<-matrix(NA,nrow,1)

A1[2:nrow,1]<-A[1:(nrow-1),1] 
A2[3:nrow,1]<-A[1:(nrow-2),1]

A3[4:nrow,1]<-A[1:(nrow-3),1]

A4[5:nrow,1]<-A[1:(nrow-4),1]

A5[6:nrow,1]<-A[1:(nrow-5),1]

nrow<-nrow(B) 
B1<-matrix(NA,nrow,1) 
B2<-matrix(NA,nrow,1)

B3<-matrix(NA,nrow,1)

B4<-matrix(NA,nrow,1)

B5<-matrix(NA,nrow,1)

B1[2:nrow,1]<-B[1:(nrow-1),1] 
B2[3:nrow,1]<-B[1:(nrow-2),1]

B3[4:nrow,1]<-B[1:(nrow-3),1] 
B4[5:nrow,1]<-B[1:(nrow-4),1]
B5[6:nrow,1]<-B[1:(nrow-5),1] 

reg1<-lm(A~A1+A2+A3+A4+A5+B1+B2+B3+B4+B5) 
reg2<-lm(B~B1+B2+B3+B4+B5+A1+A2+A3+A4+A5)



Regards
Saba
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Monthly data.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20151218/27cef314/attachment.txt>


More information about the R-help mailing list