View source: R/S05_Statistics.R
pvalues | R Documentation |
Given a set of Monte Carlo
samples, estimates a p-value from
the proportion of values that fall
above or below a comparison point.
If string
is TRUE
,
takes a numeric p-value and converts
it into a formatted character
string, either 'p = ...' or
'p < ...'.
pvalues(
x,
comparison = 0,
alternative = "two-sided",
digits = 3,
string = FALSE,
pad = FALSE
)
x |
Either a) a vector of numeric values (Monte Carlo samples) or b) a single p-value. |
comparison |
The comparison value; the p-value is computed from the proportion of Monte Carlo samples above or below this cut-off. |
alternative |
A character string
indicating the type of alternative
hypothesis to test, either a) |
digits |
Number of digits to round to when formatting the p-value. |
string |
Logical; if |
pad |
Logical; if |
Either a numeric p-value or a character string, a nicely formatted version of the p-value.
# Example based on two-sample t-test
set.seed(40)
x <- data.frame(
y = c(rnorm(50), rnorm(50, mean = .3)),
group = rep(1:2, each = 50)
)
# Two-sample t-test
tt <- t.test(y ~ group, data = x)
print(pvalues(tt$p.value))
print(pvalues(tt$p.value, digits = 2))
# For very small p-values, automatically
# converts to 'p < cut-off' format
print(pvalues(1e-6))
# Computing p-values from
# Monte Carlo samples
# Simulate data from standard normal;
# on average 50% of sample falls
# below zero
set.seed(50)
x <- rnorm(1000)
# Default is two-sided
pvalues(x)
# Can specify less than or greater than
pvalues(x, alternative = "less")
pvalues(x, alternative = "greater")
# Against different comparison point
pvalues(x, alternative = "less", comparison = .68)
# Simulate data from normal distribution
# with mean of 0.68, on average
# approximately 75% of sample falls
# below zero
set.seed(60)
x <- rnorm(1000, mean = .68)
pvalues(x)
pvalues(x, alternative = "less")
pvalues(x, alternative = "greater")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.