compmeansC {RCPA3} | R Documentation |
Mean comparison analysis function, makes controlled comparisons, generates plots, performs ANOVA
Description
Mean comparison analysis, options for weighted observations and control variable. Also supports several plotting options for basic mean comparisons and controlled mean comparisons. Can conduct single and two-factor analysis of variance (ANOVA) to test differences among multiple means.
Usage
compmeansC(dv, iv, w, z, data, digits = 2, compact = FALSE, ivlabs, zlabs,
anova = FALSE, printC = FALSE, plot = TRUE, main, xlab, ylab, ylim,
plot.ci = FALSE, z.palette, legend.title)
Arguments
dv |
Dependent variable, should be in dataset$var form unless dataset specified in optional data argument. |
iv |
Independent variable, should be in dataset$var form unless dataset specified in optional data argument. |
w |
(Optional) Sampling weights of variable (optional), 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 (optional). |
digits |
(Optional) The number of decimal places reported in result (defaults to 2). |
compact |
(Optional) Do you want compact version of controlled mean comparison table with N and Std. Dev. values omitted? Default is FALSE. Compact display only available for controlled comparisons. |
ivlabs |
(Optional) A vector of names for the independent variable's values (to abbreviate the mean comparison table's row labels and iv labels on plots) |
zlabs |
(Optional) A vector of names for the control variable's values (to abbreviate a controlled mean comparison table's column labels and z variable's labels on plots) |
anova |
(Optional) Do you want to conduct analysis of variance (ANOVA)? Default is FALSE. |
printC |
(Optional) Do you want results printed to .html file in your working directory? Default is FALSE. Set to TRUE to print results. |
plot |
(Optional) Do you want a plot of the means? Default is TRUE (makes a bar plot). Additional options:
|
main |
(Optional) Main label for plot, if missing, default main title generated. |
xlab |
(Optional) x-axis label for plot, if missing, default label generated using iv name. |
ylab |
(Optional) y-axis label for plot, if missing, default label generated using dv name. |
ylim |
(Optional) Range of y-axis values on plot. |
plot.ci |
(Optional) Do you want vertical 95 percent confidence intervals added to line plot of means? Default is FALSE. Only works when |
z.palette |
(Optional) For bar and line charts with control variables (z), the name of HCL color palette to use. Default is "LightGrays". See |
legend.title |
(Optional) Customize title of legend on plot used for controlling comparisons. |
Value
Returns a mean comparison table as a matrix of values.
RCPA3 Package Tutorial Videos
-
Make Mean Comparisons with RCPA3's compmeansC Function 13:20, shows you how to use the RCPA3 Package's compmeansC function to compare values of an interval-level dependent variable across categories of an independent variable.
-
Making Controlled Mean Comparisons with RCPA3's compmeansC Function 25:46
-
Complete Playlist of RCPA3 Package Tutorial Videos, includes video for this function and many more.
Textbook References
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. ISBN-13: 978-1506379616; ISBN-10: 150637961.
Online Resources
-
R 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.
Examples
library(RCPA3)
# basic usage: dv and iv, variables are vectors
compmeansC(dv=nes$ft.rep, iv=nes$partyid7)
compmeansC(dv=nes$ft.rep, iv=nes$partyid7, w=nes$wt, plot=TRUE)
# basic usage: data argument used
compmeansC(dv=infant.mortality, iv=region, data=world, plot=FALSE)
# with weights and z variable
compmeansC(dv=nes$ft.rep, iv=nes$partyid7, w=nes$wt, z=nes$gender, plot="line")
compmeansC(dv=nes$ft.gay, iv=nes$gender, z=nes$partyid3, compact=TRUE, plot=TRUE)