View source: R/significance_pvalue.R
compare_proportions | R Documentation |
compare_proportions
calculates p-values (via z-test) for comparison
between each proportion in the prop1
and prop2
. Results are calculated
with the same formula as in prop.test without continuity
correction.
compare_means
calculates p-values (via t-test) for comparison between
each mean in the mean1
and mean2
. Results are calculated on the
aggregated statistics (means, std. devs, N) with the same formula as in
t.test.
These functions mainly intended for usage inside significance_cpct and
significance_means.
compare_proportions(prop1, prop2, base1, base2, common_base = 0)
compare_means(
mean1,
mean2,
sd1,
sd2,
base1,
base2,
common_base = 0,
var_equal = FALSE
)
prop1 |
a numeric vector of proportions in the group 1. Values should be between 0 and 1 |
prop2 |
a numeric vector of proportions in the group 2. Values should be between 0 and 1 |
base1 |
a numeric vector for |
base2 |
a numeric vector for |
common_base |
numeric. Number of cases that belong to both values in the
first and the second argument. It can occur in the case of overlapping
samples. Calculations are made according to algorithm in IBM SPSS Statistics
Algorithms v20, p. 263. Note that with these adjustments t-tests between
means are made with equal variance assumed (as with |
mean1 |
a numeric vector of the means in the first group. |
mean2 |
a numeric vector of the means in the second group. |
sd1 |
a numeric vector of the standard deviations in the first group. Values should be non-negative. |
sd2 |
a numeric vector of the standard deviations in the second group. Values should be non-negative. |
var_equal |
a logical variable indicating whether to treat the variances in the groups as being equal. For details see t.test. |
numeric vector with p-values
significance_cpct, significance_means, prop.test, t.test
# proportions
data(mtcars)
counts = table(mtcars$am, mtcars$vs)
props = prop.table(counts)
compare_proportions(props[,1], props[,2],
colSums(counts)[1], colSums(counts)[1])
# means
t.test(mpg ~ am, data = mtcars)$p.value
# the same result
with(mtcars,
compare_means(
mean(mpg[am==0]), mean(mpg[am==1]),
sd(mpg[am==0]), sd(mpg[am==1]),
length(mpg[am==0]), length(mpg[am==1])
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.