1
$\begingroup$

I am trying to use the least absolute deviation regression from my dataset which has one column of dependent variable and multiple columns of independent variables. I tried using the following syntax but get errors where the 'co' contains the dataset and the 12th column is my dependent variable:

 co_reg1=lad(co[,12]~co[,2]+co[,3]+co[,5]+co[,7]+co[,8]+co
 [,9]+co[,11]+co[,2]*co[,11])

but I get error saying:

 argument "y" is missing, with no default

So I also tried this method:

 co_reg1=lad(cbind(co[,2],co[,3],co[,5],co[,7],co[,8],co[,9],co[,11],co[,2]
 *co[,11]),co[,12])

But I still get error saying I need the arguments for x and y to be in matrix form.

May I get help on this?

$\endgroup$
  • $\begingroup$ It works for me lad(mtcars[,1] ~ mtcars[,2] + mtcars[,3]*mtcars[,4])... The question is off-topic and you didn't provide a reproducible example what makes it impossible to answer. lad takes as argument standard R formula and then parses it using the same methods as functions like lm, so it should work if you use it with valid input data and use it correctly. $\endgroup$ – Tim May 6 '17 at 19:09
  • $\begingroup$ Now I get it. When I delete a library something like "ldr" package, it works. I tried to call this ldr package to use summary.lad function. However since it seems like I cannot call both functions, probably summary.lad is not supposed to give the summary result for least absolute deviation regression result. Because in some other package lad function means different one if I am correct. So I think there was some collusion. $\endgroup$ – Eric May 6 '17 at 19:28
  • $\begingroup$ May I know the name of the function? Cuz theoretically people say it is not available. $\endgroup$ – Eric May 6 '17 at 23:07
  • $\begingroup$ You are right. What kind of summary would you need? $\endgroup$ – Tim May 7 '17 at 6:35
  • $\begingroup$ t-test for coefficients and for overall f-test and R square values $\endgroup$ – Eric May 7 '17 at 10:59
2
$\begingroup$

Someone's going to complain that this question belongs to other stackoverflow forum. But the quick take on your question is, you need to follow the standard R idiom. That is, for function like lad, it wants a formula like y ~ x1 + ... and a data object. To use your syntax, you want l1fit which accepts a x and y. Just read the documentation carefully.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Sorry but I don't understand. The example I show above is using y~x1+... already but getting error. $\endgroup$ – Eric May 6 '17 at 19:07
  • $\begingroup$ @Eric Try use l1fit and see if you get the same error. And read the doc. $\endgroup$ – horaceT May 6 '17 at 19:08
  • $\begingroup$ Yes when I supply x and y as required by the syntax it works. But since my ultimate goal is to use the summary.lad function over it, I may need to use lad() function. When I run the lad() function with the working syntax in l1fit, I get error saying "supply both 'x' and 'y' or a matrix-like 'x'" which I don't understand either. $\endgroup$ – Eric May 6 '17 at 19:13
  • $\begingroup$ Now I get it. When I delete a library something like "ldr" package, it works. I tried to call this ldr package to use summary.lad function. However since it seems like I cannot call both functions, probably summary.lad is not supposed to give the summary result for least absolute deviation regression result. Because in some other package lad function means different one if I am correct. So I think there was some collusion. $\endgroup$ – Eric May 6 '17 at 19:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.