aislinx
aislinx

Reputation: 47

Extracting p-value from anova table in R

** The preceding steps are as such:

a <- rnorm(100, mean=2, sd=3)
response <- a * 1.5 + rnorm(100, mean=0, sd=1)
model <- lm(response ~ a)
vartest <- anova(model)

I would like to extract the p-value into a vector associated with the a coefficient, which is a value that will be < 2.2e-16.

The code I have is:

vartest[1,5]
[1] 1.002182e-63

in which vartest produces the following variance table. I would like to know if I'm doing it wrong, or is there an alternative to this method, for extracting the value into a vector?

enter image description here

Upvotes: 1

Views: 1690

Answers (1)

akrun
akrun

Reputation: 886938

We can directly extract with the name of the column with either [[ or $

out <- vartest[["Pr(>F)"]][1]
is.vector(out)
#[1] TRUE

-checking with OP's approach

identical(out, vartest[1,5])
#[1] TRUE

We could check the structure of the object with str

str(vartest)

and this would give an idea about how to extract the components

Upvotes: 3

Related Questions