correlateC {RCPA3} | R Documentation |
Correlation analysis for two or more numeric variables, with options for scatterplots, weighted observations, and inferential statistics.
Description
Given two or more numeric variables, correlateC
reports correlation coefficients, along with inferential statistics (if requested), works with sampling weights. If more than two x variables are supplied, the function calculates correlation coefficients using pairwise complete observations (as opposed to limiting analysis to observations complete on all variables).
The wtd.cor
function is imported from the weights package. See wtd.cor
documentation for details.
Usage
correlateC(x, w, data, digits = 3, stats = FALSE, printC = FALSE,
plot = FALSE, jitter = FALSE, ...)
Arguments
x |
A list of variables for correlation analysis, variables must be numeric. Should be entered as list(dataset$var1, dataset$var2, dataset$var3 ... ) form unless dataset specified in optional data argument. |
w |
(Optional) Sampling weights variable, must be numeric; should be in dataset$weightvar form unless dataset specified in optional data argument. |
data |
(Optional) Name of dataset that contains x (and w) variable (optional). |
digits |
(Optional) Number of decimal places reported in result (defaults to 3). |
stats |
(Optional) Do you want the inferential statistics (standard errors, t-statistics, and p-values)? Default is FALSE. Set to TRUE for inferential statistics. |
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 scatterplot(s)? Default is FALSE. |
jitter |
(Optional) Do you want scatterplot pointed jittered? By default, points jittered when there are more than 500 observations, but you can set this arguments to TRUE/FALSE to override the default. |
... |
(Optional) Additional arguments passed to |
Details
Makes use of the wtd.cor function, part of the weights package.
Value
Returns the coefficients of correlation among x variables; if stats=TRUE
, inferential statistics returned in tables as well.
RCPA3 Package Tutorial Videos
-
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), Chapter 11.
Philip H. Pollock and Barry C. Edwards, The Essentials of Political Analysis, 6th Edition (Thousand Oaks, CA: Sage Publications, 2020), pp. 240-244. ISBN-13: 978-1506379616; ISBN-10: 150637961.
Online Resources
-
R Tutorials & Resources for Correlation and Bivariate Regression, 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)
correlateC(x=list(abortlaws, women.stateleg), data=states, plot=FALSE)
# with weighted observations and inferential statistics
correlateC(x=list(nes$ft.rep, nes$ft.trump.pre, nes$ft.dem, nes$ft.biden.pre),
w=nes$wt, stats=TRUE)