testpropsC {RCPA3}R Documentation

Tests the difference between two sample proportions, or difference between sample proportion and hypothesized value, with options for weighted observations, confidence intervals

Description

Difference of proportions test with optional sample weights. Reports P-value of two-tailed significance test. Currently limited to testing one response from one dataset. If you want to compare x1 from dataset1 and x2 from dataset2, you can create new dataframe to test as dv ~ iv where dv is vector of x1 and x2 values and iv is vector identifying the source (i.e. dataset1 and dataset2). If you want to compare different responses, such as "Yes" value for x1 and "Agree" value for x2, you will need to transform one of the variables so they have comparable response values.

Usage

testpropsC(x1, x2, w, data, dv, iv, digits = 3, response, printC = FALSE,
  ci.table = TRUE, ci.level = 95, ci.plot = TRUE, main, xlab, xlim, ...)

Arguments

x1

A categorical variable

x2

Value or variable to compare x1 against.

w

(Optional) Weights variable.

data

(Optional) Specify name of dataset (data frame) with x1 and x2 variables (or dv and iv).

dv

Dependent variable

iv

Independent variable, should have only two unique values. For comparison purposes, group1 will be first level of iv and group2 will be the second level of iv. To change order of groups, you can modify levels(iv).

digits

(Optional) Number of digits to report after decimal place, optional (default: 3).

response

(Optional) Identify the response value you wish to compare. If not specified, the function will compare first value of the dv (or x1 variable). If you want to group multiple responses together, use transformC to make dummy variable.

printC

(Optional) Do you want results printed to .html file in your working directory? Default is FALSE. Set to TRUE to print results.

ci.table

(Optional) Do you want a table reporting confidence interval of the difference of proportions? (default: TRUE)

ci.level

(Optional) Desired confidence level, as percentage (default: 95)

ci.plot

(Optional) Do you want a plot of the confidence interval of the difference of proportions? (default: TRUE)

main

(Optional) Main title for plot of confidence interval of difference

xlab

(Optional) Label for x-axis of plot of confidence interval of difference

xlim

(Optional) A vector (of length 2) specifying the range of the x-axis, useful to zoom in on CI. By default, xlim=c(-1, 1).

...

(Optional) Additional arguments passed to plot function for the CI plot

Value

No return

RCPA3 Package Tutorial Videos

Textbook References

Online Resources

Examples

   library(RCPA3)
   
   
   # one sample test: x1 variable against hypothesized value (of x2)
   testpropsC(x1=nes$gun.bg.checks, x2=.500, w=nes$wt, response="1. Favor a great deal", 
              xlim=c(0, .2))

   # two sample test x1 versus x2
   testpropsC(x1=approve.local.covid, x2=approve.pres.covid, w=wt, data=nes, 
              response="1. Approve strongly", xlim=c(0, .2))
   
   # test of proportions dv by iv
   testpropsC(dv=marital, iv=gender, w=wt, data=nes, response="3. Widowed", 
              xlim=c(-.10, 0))
   

[Package RCPA3 version 1.2.1 Index]