Learn R Programming

expss (version 0.10.7)

compare_proportions: Calculate significance (p-values) of differences between proportions/means

Description

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.

Usage

compare_proportions(prop1, prop2, base1, base2, common_base = 0)

compare_means( mean1, mean2, sd1, sd2, base1, base2, common_base = 0, var_equal = FALSE )

Arguments

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 compare_means and single number for compare_proportions. Number of valid cases for each mean in the first group for compare_means and number of cases for compare_proportions.

base2

a numeric vector for compare_means and single number for compare_proportions. Number of valid cases for each mean in the second group for compare_means and number of cases for compare_proportions.

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 var_equal = TRUE).

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.

Value

numeric vector with p-values

See Also

significance_cpct, significance_means, prop.test, t.test

Examples

Run this code
# NOT RUN {
# 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
calculate(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])
          ))
# }

Run the code above in your browser using DataLab