why r's prop.test
function (documentation here) return different results based on whether pass matrix
or vectors?
here pass vectors:
> prop.test(x = c(135, 47), n = c(1781, 1443)) 2-sample test equality of proportions continuity correction data: c(135, 47) out of c(1781, 1443) x-squared = 27.161, df = 1, p-value = 1.872e-07 alternative hypothesis: two.sided 95 percent confidence interval: 0.02727260 0.05918556 sample estimates: prop 1 prop 2 0.07580011 0.03257103
here create matrix
, pass in instead:
> table <- matrix(c(135, 47, 1781, 1443), ncol=2) > prop.test(table) 2-sample test equality of proportions continuity correction data: table x-squared = 24.333, df = 1, p-value = 8.105e-07 alternative hypothesis: two.sided 95 percent confidence interval: 0.02382527 0.05400606 sample estimates: prop 1 prop 2 0.07045929 0.03154362
why different results? expect same results both scenarios returned.
when x
, n
entered separate vectors, treated, respectively, number of successes , total number of trials. when enter matrix, first column treated number of successes , second number of failures. prop.test
:
x vector of counts of successes, one-dimensional table 2 entries, or two-dimensional table (or matrix) 2 columns, giving counts of successes , failures, respectively.
so, same result matrix, need convert second column of matrix number of failures (assuming in example x
number of successes , n
number of trials).
x = c(135, 47) n = c(1781, 1443) prop.test(x, n) # x = successes; n = total trials
2-sample test equality of proportions continuity correction data: x out of n x-squared = 27.161, df = 1, p-value = 1.872e-07 alternative hypothesis: two.sided 95 percent confidence interval: 0.02727260 0.05918556 sample estimates: prop 1 prop 2 0.07580011 0.03257103
prop.test(cbind(x, n - x)) # x = successes; convert n number of failures
2-sample test equality of proportions continuity correction data: cbind(x, n - x) x-squared = 27.161, df = 1, p-value = 1.872e-07 alternative hypothesis: two.sided 95 percent confidence interval: 0.02727260 0.05918556 sample estimates: prop 1 prop 2 0.07580011 0.03257103
Comments
Post a Comment