So lets work through the example from ?t.test()
We do a two-sample t-test on the data by:
t.test(1:10, y = c(7:20))
Now I am only interested in saving the p-value
When I input the followng code, the $p.value
is also saved.
t.test(1:10, y = c(7:20))[3]
I want only the p-value
saved (with the $p.value
) as an numeric/integer/double. Sorry for asking such a simple question
The p-value is an estimate of the probability of seeing a t-value as extreme, or more extreme the one you got, if you assume that the null hypothesis is true (the null hypothesis is usually "no effect", unless something else is specified).
Every t-value has a p-value to go with it. A p-value from a t test is the probability that the results from your sample data occurred by chance. P-values are from 0% to 100% and are usually written as a decimal (for example, a p value of 5% is 0.05).
In R, we may use the pnorm() function to find the p-value associated with a z-score, which has the following syntax. mean: The normal distribution's mean. The default value is 0. sd: The normal distribution's standard deviation.
You can save the p-value from the t-test to another variable with something like:
pVal <- t.test(1:10, y = c(7:20))$p.value
pVal
will then be numeric:
> str(pVal)
num 1.86e-05
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