crosstabC | R Documentation |
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.
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)
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:
|
plot.response |
(Optional) Set |
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 |
legend.title |
(Optional) Title for legend shown if plot used with z argument. |
Returns a cross-tabulation
Create Cross-Tabulations to Make Comparisons with RCPA3's crosstabC Function 13:31
Plots for Cross-Tabulations with RCPA3's crosstabC Function 29:51
Making Controlled Comparisons with RCPA3's crosstabC Function 28:34
Complete Playlist of RCPA3 Package Tutorial Videos, includes video for this function and many more.
Philip H. Pollock and Barry C. Edwards, An R Companion to Political Analysis, 3rd Edition (Thousand Oaks, CA: Sage Publications, Forthcoming 2022), Chapters 4, 5, 7, 10.
Philip H. Pollock and Barry C. Edwards, The Essentials of Political Analysis, 6th Edition (Thousand Oaks, CA: Sage Publications, 2020), pp.85-97, 150-156, 215-231. ISBN-13: 978-1506379616; ISBN-10: 150637961.
Tutorials & Resources for Making Comparisons, Graphing Relationships and Describing Patterns, Making Controlled Comparisons, and Chi-Square Test and Analysis of Variance, compiled by Barry C. Edwards
Sage Edge Resources for Political Analysis Series, for streaming videos, flashcards, and more student resources for textbooks by Pollock and Edwards, from Sage Publications.
Political Science Data Web Site: Find datasets for your own research and resources to help with the analysis.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.