I want to extract value from Pr(>|t|) column
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 this? class(toP[[2]])
say it "summary.glht" "glht"
. There are $pvalues in toP[[2]][9] but toP[[2]][9]$pvalues give NULL
If you want to know the "elements" you can access for a given object, don't 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
. Let's look at it :
R> names(toP[[2]]$test)
[1] "pfunction" "qfunction" "coefficients" "sigma"
[5] "tstat" "pvalues" "type"
Hmm, there's an element called pvalues
. Sounds good. You can access it with :
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 the str()
. Applied to your case (str(toP[[2]])
) it leads to a bit long output, but could have allowed you to directly determine the way to access your p-values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With