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:

  • "line" to make a line plot

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

  • "points" to show means as points without connecting lines,

  • FALSE or F to suppress plot.

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 plot="line" or plot="points"

z.palette

(Optional) For bar and line charts 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) 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

Textbook References

Online Resources

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)
  

[Package RCPA3 version 1.2.1 Index]