crosstabC {RCPA3}R Documentation

Cross-tabulation analysis, option for weighting observations, makes controlled comparisons, generates plots, performs Chi-Square test, measures strength of association

Description

This is a workhorse function for analyzing the relationship between two variables measured at the nominal or ordinal-level (factors). Basic output is a cross-tabulation with column percentages and counts. Options include weighting observations, adding control variable for controlled cross-tabulation, several plotting options, conducting Chi-Square test of independence, and measuring strength of association.

Usage

crosstabC(dv, iv, w, z, data, digits = 2, compact = FALSE, dvlabs, ivlabs,
  zlabs, chisq = FALSE, lambda = FALSE, somers = FALSE,
  cramers = FALSE, printC = FALSE, plot = TRUE, plot.response, main,
  xlab, ylab, z.palette, legend.title)

Arguments

dv

Dependent variable, should be in dataset$var form unless dataset specified in optional data argument. Should be a nominal or ordinal-level variable.

iv

Independent variable, should be in dataset$var form unless dataset specified in optional data argument. Should be a nominal or ordinal-level variable.

w

(Optional) Sampling weights of variable, must be numeric; should be in dataset$weightvar form unless dataset specified in optional data argument.

z

(Optional) Control variable, must be numeric; should be in dataset$weightvar form unless dataset specified in optional data argument.

data

(Optional) Name of dataset that contains dv, iv (and w) variables.

digits

(Optional) Number of decimal places reported in result (defaults to 2).

compact

(Optional) Do you want compact display of cross-tabulation with row subtotals omitted? Default is FALSE.

dvlabs

(Optional) A vector of names for the dependent variable's values (to abbreviate the cross-tabulation's row labels and dv labels on plots)

ivlabs

(Optional) A vector of names for the independent variable's values (to abbreviate the cross-tabulation's column labels and iv labels on plots)

zlabs

(Optional) A vector of names for the control variable's values (to abbreviate the controlled cross-tabulation's column labels and z variable labels on plots)

chisq

(Optional) Do you want to conduct Chi-Square Test? If z argument specific, Chi-Square Test conducted on dv-iv relationship for each value of z.

lambda

(Optional) Do you want Lambda reported? If z argument specified, Lambda reported for dv-iv relationship for each value of z.

somers

(Optional) Do you want Somers' d reported? If z argument specific, Somers' D reported for dv-iv relationship for each value of z.

cramers

(Optional) Do you want Cramer's V reported? If z argument specific, Cramer's V reported for dv-iv relationship for each value of z.

printC

(Optional) Do you want to print cross-tabulation and plot (if plot is used) to .html file in working directory? (default: FALSE)

plot

(Optional) Do you want a plot of the cross-tabulation? Default is TRUE (and makes a bar plot). Other plot options:

  • "line" for a line plot,

  • "mosaic" for a mosaic plot,

  • "bar", TRUE, or T for a bar plot (default plot)

  • FALSE or F to suppress plot.

plot.response

(Optional) Set plot.response="all" to plot all DV values (for uncontrolled comparisons only).

main

(Optional) Main label for plot

xlab

(Optional) x-axislabel for plot

ylab

(Optional) y-axis label for plot

z.palette

(Optional) For bar and line plots with control variables (z), the name of HCL color palette to use. Default is "LightGrays". See grDevices::hcl.pals for palette names and more information. Also see https://developer.r-project.org/Blog/public/2019/04/01/hcl-based-color-palettes-in-grdevices/ to view color palettes.

legend.title

(Optional) Title for legend shown if plot used with z argument.

Value

Returns a cross-tabulation

RCPA3 Package Tutorial Videos

Textbook References

Online Resources

Examples

 
  library(RCPA3)
  
  
  crosstabC(dv=nes$death.penalty, iv=nes$partyid3)
  
  # with optional w, data, chisq, somers arguments
  crosstabC(dv=death.penalty, iv=partyid3, w=wt, data=nes, chisq=TRUE, somers=TRUE)
  
  # example with optional w, data, z, and plot="line" arguments
  crosstabC(dv=death.penalty, iv=partyid3, w=wt, data=nes, z=gender, plot="line")
  

[Package RCPA3 version 1.2.1 Index]