0

I am trying to use linear regression using R. The following is my code, everything works fine except last line which gives following error: Error in .Primitive("%*%")(x, y) : requires numeric/complex matrix/vector arguments

data<-read.table("tmp.txt",header=TRUE)
X<-data$P
Y<-data$Q
plot(data, pch=16)
model <- lm(Y ~ X , data)
# make a prediction for each X
predY <- predict(model,data)
Akhter
  • 59
  • 1
  • 6
  • There's no need to generate separate `Y` and `X`. Use `model <- lm(Q ~ P, data)` instead. – Joris Meys Mar 17 '17 at 10:39
  • Yes, I did that too but it seems as if predict function isn't working. why is there the error: Error in .Primitive("%*%")(x, y) : requires numeric/complex matrix/vector arguments – Akhter Mar 17 '17 at 10:41
  • @Akther Without any idea about your data, your question cannot be answered. Please look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example on how to do that. Otherwise your question is likely to be closed, for the reasons explained. If `predict(model)` doesn't work, problem is your data, not `predict`. – Joris Meys Mar 17 '17 at 10:44
  • I am adding my data – Akhter Mar 17 '17 at 11:00
  • P 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 – Akhter Mar 17 '17 at 11:00
  • Q 3 4 8 4 6 9 8 12 15 26 35 40 45 54 49 59 60 62 63 68 – Akhter Mar 17 '17 at 11:00
  • Error in is.data.frame(frame) : object 'X.test' not found – Akhter Mar 17 '17 at 11:06

0 Answers0