Learn R Programming

RCPA3 (version 1.3.1)

wtd.cor: Calculates Correlation Coefficient Between Two Numeric Variables Makes use of the wtd.cor function, part of the weights package.

Description

Given two numeric variables, wtd.cor reports correlation coefficient, works with sampling weights. The wtd.cor function is imported from the weights package. See wtd.cor documentation for details.

Usage

wtd.cor(x1, x2, w = NULL, data, digits = 3, stats = FALSE, ...)

Value

Returns the coefficient of correlation between x1 and x2 variables, a numeric value.

Arguments

x1

A variable (must be numeric), should be in dataset$var form unless dataset specified in optional data argument.

x2

Another variable, different than x1 (must be numeric), should be in dataset$var form unless dataset specified in optional data argument.

w

(Optional) Sampling weights of 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.

digits

(Optional) Number of decimal places reported in result (defaults: 3).

stats

(Optional) Do you want inferential statistics for correlation coefficient? (default: FALSE)

...

(Optional) Additional arguments passed to weights::wtd.cor function.

Examples

Run this code
   library(RCPA3)
   
   wtd.cor(x1=nes$ft.rep, x2=nes$ft.pence.pre, w=nes$wt)
   wtd.cor(x1=ft.dem, x2=ft.harris.pre, w=wt, data=nes)

Run the code above in your browser using DataLab