Question

I ran a hypothesis test with glht in R and I want to extract the t-stat of the test. I read that there supposed to be an element "test" in the class "glht" which I received, but when going over the elements I got from running the glht it doesn't appear.

the code is very simple and is given below:

reg = lm(dep ~ indep)
htest = glht(reg,linfct = c("indep  = 0.5"))
names(htest)

running the last line gives me: [1] "model" "linfct" "rhs" "coef" "vcov" "df" "alternative" "type"

anyone has an answer to that?

Thank You.

Was it helpful?

Solution

Use summary:

indep <- 1:10
set.seed(42)
dep <- indep/2+5+rnorm(10)

reg = lm(dep ~ indep)

library(multcomp)
htest = glht(reg,linfct = c("indep  = 0.5"))
summary(htest)
#Simultaneous Tests for General Linear Hypotheses
#
#Fit: lm(formula = dep ~ indep)
#
#Linear Hypotheses:
#             Estimate Std. Error t value Pr(>|t|)
#indep == 0.5  0.53040    0.09697   0.313    0.762
#(Adjusted p values reported -- single-step method)

You can extract the values like this:

res <- summary(htest)
res$test[-(1:2)]
# $coefficients
# indep 
# 0.5303967 
# 
# $sigma
# indep 
# 0.09696568 
# 
# $tstat
# indep 
# 0.3134785 
# 
# $pvalues
# [1] 0.7619346
# attr(,"error")
# [1] 0
# 
# $type
# [1] "single-step"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top