1

I was about test the coefficients with lht command in the following model:

fashion.lm<-lm(LOGS~D2+D3+D4+I(D1*LOGA)+I(D2*LOGA)+I(D3*LOGA)+I(D4*LOGA)+I(D1*LOGC)+I(D2*LOGC)+I(D3*LOGC)+I(D4*LOGC))

However, when I try to put I(D1*LOGA) into lht() function, it generates errors:

library(car)
lht(fashion.lm,c("I(D1*LOGA)"))

> lht(fashion.lm,c("I(D1*LOGA)"))
Error in constants(lhs, cnames_symb) : 
  The hypothesis "I(D1*LOGA)" is not well formed: contains bad coefficient/variable names.
In addition: Warning message:
In constants(lhs, cnames_symb) : NAs introduced by coercion

I was wondering how to properly do the test in the model? I know one (not so smart method) is to create a variable with the values equal to D1*LOGA before I run the regression. But is there a more convenient way or doing it?

Lstat
  • 1,450
  • 1
  • 12
  • 18
Jinhua Wang
  • 1,679
  • 1
  • 17
  • 44

1 Answers1

1

Function lht() treats I(D1*LOGA) as an invalid character. It does not perform operation inside of I()

Here is a solution which uses indirect coefficient specification:

mod.davis <- lm(weight ~ repwt + I(log(repwt)), data=Davis)
lht(mod.davis, hypothesis.matrix = names(coef(mod.davis)[3]))
Lstat
  • 1,450
  • 1
  • 12
  • 18
  • What if I want to test if the coefficient of repwt and I(log(repwt)) are equal? – Jinhua Wang Nov 24 '17 at 21:14
  • I can only give you a reference to a possible solution here: https://stackoverflow.com/questions/37591550/testing-the-equality-of-multiple-coefficients-in-r I don't work with this function. Hope the code will work... – Lstat Nov 28 '17 at 09:09