Hi Please find the attachment with (.txt) extension and I hope the command is visible now. 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)
Following error is occurring: 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 RegardsSaba On Friday, 18 December 2015, 15:11, David Winsemius <dwinsem...@comcast.net> wrote: > On Dec 17, 2015, at 1:13 PM, Saba Sehrish via R-help <r-help@r-project.org> > wrote: > > Hi I am trying to apply linear regression on the attached data The is no attached data; please read the posting guide. Do not post with .csv or .doc files. You can have commas as separators but an attachment must have a .txt extension. > of two variables (DODGX, TRMCX) in R by taking into account 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/Inf in 'y'In addition: Warning message:In model.response(mf, > "numeric") : NAs introduced by coercion > Following is the programming I am using: > > data<-read.csv(file="---",header=T)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) I do not see the usual html delted message but nonetheless your code has arrived without any linebreaks. Linebreaks are syntactically necessary. So pleas learn to post with plain text in a format that does mangle the ability of humans to read this code. -- David Winsemius Alameda, CA, USA
DODGX,TRMCX "739,171,876.13","-30,023,111.44" "487,266,676.01","21,283,768.23" "372,851,476.15","-40,442,678.43" "63,229,603.27","10,656,220.90" "42,006,490.16","-11,533,497.55" "190,745,334.56","-5,394,116.27" "172,710,138.57","-15,091,006.48" "231,059,302.57","23,568,469.87" "519,602,621.84","64,131,342.59" "997,358,074.79","23,623,980.29" "291,864,614.39","65,303,351.45" "80,844,732.71","69,354,076.90" "701,170,068.28","106,386,633.76" "440,463,911.27","105,165,515.47" "67,256,920.87","57,943,316.76" "64,101,070.80","50,209,212.89" "-71,028,831.03","31,292,473.88" "-197,854,142.48","32,805,225.46" "-189,290,263.33","4,638,671.93" "-520,470,164.74","962,640,792.41" "-471,115,277.27","-1,093,666,458.34" "-955,868,238.04","-102,261,874.75" "-1,098,715,608.87","-101,020,121.92" "-738,546,938.53","-69,222,216.12" "-1,085,874,989.74","-136,045,443.89" "193,157,212.12","-2,473,692.63" "-6,269,415.53","-28,891,931.00" "199,824,564.81","5,127,403.10" "302,376,261.45","6,655,585.13" "-67,851,220.11","-13,741,489.54" "-370,952,946.99","-24,219,268.21" "34,404,761.25","27,283,468.90" "-428,849,252.43","-85,765,593.88" "-924,463,014.01","-112,574,045.54" "-495,270,249.60","-2,965,265.14" "-668,618,574.50","-39,930,551.16" "-10,436,100.77","90,010,638.89" "-281,751,636.53","-22,157,882.66" "-385,194,082.95","43,186,980.60" "104,681,563.10","40,450,660.38" "-15,283,793.52","60,454,998.18" "-26,567,438.37","52,683,189.80" "-98,612,309.08","25,319,905.01" "21,402,708.99","44,019,777.51" "-74,846,057.05","45,104,511.78" "-951,203,476.25","9,858,962.32" "-338,231,274.10","86,293,283.74" "-424,023,473.54","102,767,273.58" "20,027,128.13","185,851,265.95" "-815,545.80","163,237,321.24" "46,996,041.85","194,808,434.99" "134,571,135.25","122,988,858.88" "-183,703,166.02","53,086,443.78" "212,728,895.49","73,301,796.90" "-197,466,304.16","-11,713,239.02" "-393,762,814.65","11,580,149.74" "-343,324,235.59","-13,610,112.45" "-260,888,613.88","10,047,787.51" "-759,009,960.63","-151,251,490.77" "-383,721,497.02","-42,502,501"
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.