wtd.cor: Produces weighted correlations with standard errors and...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/wtd.cor.r

Description

wtd.cor produces a Pearsons correlation coefficient comparing two variables or matrices. Note that weights run with the default parameters here treat the weights as an estimate of the precision of the information. For survey data, users should run this code with bootstrapped standard errors bootse=TRUE, which are robust to heteroskadesticity, although these will vary slightly each time the weights are run. A prior version of this software was set to default to mean1=FALSE and bootse=FALSE.

Usage

1
2
wtd.cor(x, y=NULL, weight=NULL, mean1=TRUE, collapse=TRUE, bootse=FALSE,
bootp=FALSE, bootn=1000)

Arguments

x

x should be a matrix or vector which the researcher wishes to correlate with y.

y

y should be a numerical vector or matrix which the researcher wishes to correlate with x. If y is NULL, x will be used instead

weight

weight is an optional vector of weights to be used to determining the weighted mean and variance for calculation of the correlations.

mean1

mean1 is an optional parameter for determining whether the weights should be forced to have an average value of 1. If this is set as false, the weighted correlations will be produced with the assumption that the true N of the data is equivalent to the sum of the weights.

collapse

collapse is an indicator for whether the data should be collapsed to a simpler form if either x or y is a vector instead of a matrix.

bootse

bootse is an optional parameter that produces bootstrapped standard errors. This should be used to address heteroskadesticity issues when weights indicate probabilities of selection rather than the precision of estimates.

bootp

bootp is an optional parameter that produces bootstrapped p values instead of estimating p values from the standard errors. This parameter only operates when bootse=TRUE.

bootn

bootn is an optional parameter that is used to indicate the number of bootstraps that should be run for bootse and bootp.

Value

A list with matrices for the estimated correlation coefficient, the standard error on that correlation coefficient, the t-value for that correlation coefficient, and the p value for the significance of the correlation. If the list can be simplified, simplification will be done.

Author(s)

Josh Pasek, Assistant Professor of Communication Studies at the University of Michigan (www.joshpasek.com).

See Also

wtd.cors stdz wtd.t.test wtd.chi.sq

Examples

1
2
3
4
5
6
7
test <- c(1,1,1,1,1,1,2,2,2,3,3,3,4,4)
t2 <- rev(test)
weight <- c(.5,.5,.5,.5,.5,1,1,1,1,2,2,2,2,2)

wtd.cor(test, t2)
wtd.cor(test, t2, weight)
wtd.cor(test, t2, weight, bootse=TRUE)

Example output

Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package:HmiscThe following objects are masked frompackage:base:

    format.pval, units

Loading required package: gdata
sh: 1: /usr/bin/perl: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package:gdataThe following object is masked frompackage:stats:

    nobs

The following object is masked frompackage:utils:

    object.size

The following object is masked frompackage:base:

    startsWith

Loading required package: mice

Attaching package:miceThe following object is masked frompackage:stats:

    filter

The following objects are masked frompackage:base:

    cbind, rbind

Warning message:
In system(cmd, intern = TRUE) :
  running command ''/usr/bin/perl' '/usr/lib/R/site-library/gdata/perl/supportedFormats.pl'' had status 126
  correlation   std.err  t.value      p.value
Y  -0.8312236 0.1604855 -5.17943 0.0002295519
  correlation   std.err   t.value      p.value
Y  -0.8108894 0.1689325 -4.800078 0.0004334788
  correlation bootcor std.err t.value p.value
Y  -0.8108894      NA      NA      NA      NA
Warning messages:
1: In cor(x[q, ], y[q, ], use = "pairwise.complete.obs") :
  the standard deviation is zero
2: In cor(x[q, ], y[q, ], use = "pairwise.complete.obs") :
  the standard deviation is zero

weights documentation built on June 11, 2021, 1:06 a.m.

Related to wtd.cor in weights...