1

我打算在以下模型中使用 lht 命令测试系数:

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

但是,当我尝试投入I(D1*LOGA)使用时lht(),它会产生错误:

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

我想知道如何正确地在模型中进行测试?D1*LOGA我知道一个(不是那么聪明的方法)是在运行回归之前创建一个值等于的变量。但是有没有更方便的方法或者做呢?

4

1 回答 1

1

函数lht()I(D1*LOGA)其视为无效字符。它不执行内部操作I()

这是一个使用间接系数规范的解决方案:

mod.davis <- lm(weight ~ repwt + I(log(repwt)), data=Davis)
lht(mod.davis, hypothesis.matrix = names(coef(mod.davis)[3]))
于 2017-11-24T14:36:31.700 回答