| t |) library(lsmeans) warp.lm = lm(breaks ~ wool *...">

How to extract p value from "summary.glht"

I want to extract the value from the Pr column (> | t |)

library(lsmeans) warp.lm = lm(breaks ~ wool * tension, data = warpbreaks) toP<-lsmeans(warp.lm, pairwise ~ wool | tension, glhargs=list()) toP[[2]] Simultaneous Tests for General Linear Hypotheses Fit: lm(formula = breaks ~ wool * tension, data = warpbreaks) Linear Hypotheses: Estimate Std. Error t value Pr(>|t|) A - B | L == 0 16.333 5.157 3.167 0.00797 ** A - B | M == 0 -4.778 5.157 -0.926 0.73187 A - B | H == 0 5.778 5.157 1.120 0.60282 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Adjusted p values reported -- single-step method) 

How to do it? class(toP[[2]]) let's say "summary.glht" "glht" . There are $ pvalues ​​in toP [[2]] [9], but toP [[2]] [9] $ pvalues ​​give NULL

+4
source share
2 answers

If you want to know the "elements" that you can access for this object, do not use class , use names :

 R> names(toP[[2]]) [1] "model" "linfct" "rhs" "coef" "vcov" [6] "df" "alternative" "type" "test" 

Here you can see that there is an element called test . Look at this:

 R> names(toP[[2]]$test) [1] "pfunction" "qfunction" "coefficients" "sigma" [5] "tstat" "pvalues" "type" 

Hmm, there is an element called pvalues . It sounds good. You can access it:

 R> toP[[2]]$test$pvalues [1] 0.007954354 0.731843623 0.602840958 attr(,"error") [1] 7.579683e-05 

And here you get your p-values ​​...

Another way to get the structure of an object is to use str() . For your case ( str(toP[[2]]) ) this leads to a slightly longer output, but may allow you to directly determine how you access your p values.

+4
source

Have you tried:

  toP[[2]]$test$pvalues 
+2
source

All Articles