1

I'm performing the polynomial regression and testing the linear combination of the coefficient. But I'm running to some problems that when I tried to test the linear combination of the coefficient.

LnModel_1 <- lm(formula = PROF ~ UI_1+UI_2+I(UI_1^2)+UI_1:UI_2+I(UI_2^2)) 
summary(LnModel_1)

It output the values below:

Call:
lm(formula = PROF ~ UI_1 + UI_2 + I(UI_1^2) + UI_1:UI_2 + I(UI_2^2))
Residuals:
 Min      1Q  Median      3Q     Max 
-3.4492 -0.5405  0.1096  0.4226  1.7346 
Coefficients:
Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.66274    0.06444  72.354  < 2e-16 ***
UI_1         0.25665    0.07009   3.662 0.000278 ***
UI_2         0.25569    0.09221   2.773 0.005775 ** 
I(UI_1^2)   -0.15168    0.04490  -3.378 0.000789 ***
I(UI_2^2)   -0.08418    0.05162  -1.631 0.103643    
UI_1:UI_2   -0.02849    0.05453  -0.522 0.601621

Then I use names(coef()) to extract the coefficient names

names(coef(LnModel_1))
output:
[1] "(Intercept)" "UI_1"        "UI_2"        "I(UI_1^2)" 
"I(UI_2^2)""UI_1:UI_2" 

For some reasons, when I use glht(), it give me an error on UI_2^2

slope <- glht(LnModel_1, linfct = c("UI_2+ UI_1:UI_2*2.5+ 2*2.5*I(UI_2^2) =0
") )
Output:
Error: multcomp:::expression2coef::walkCode::eval: within ‘UI_2^2’, the term
‘UI_2’ must not denote an effect. Apart from that, the term must evaluate to
a real valued constant

Don't know why it would give me this error message. How to input the I(UI_2^2) coefficient to the glht()

Thank you very much

cloud
  • 23
  • 3

1 Answers1

0

The issue seems to be that I(UI^2) can be interpreted as an expression in R in the same fashion you did here LnModel_1 <- lm(formula = PROF ~ UI_1+UI_2+I(UI_1^2)+UI_1:UI_2+I(UI_2^2))

Therefore, you should indicate R that you want to evaluate a string inside your string:

slope <- glht(LnModel_1, linfct = c("UI_2+ UI_1:UI_2*2.5+ 2*2.5*\`I(UI_2^2)\` =0
") )

Check my example (since I cannot reproduce your problem):

library(multcomp)

cars <- copy(mtcars)
setnames(cars, "disp", "UI_2")
model <- lm(mpg~I(UI_2^2),cars)

names(coef(model))

slope <- glht(model, linfct = c("2*2.5*\`I(UI_2^2)\` =0") )
LocoGris
  • 4,432
  • 3
  • 15
  • 30