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?
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]))