svycor
extends the survey
package by calculating correlations
with syntax similar to the original package, which for reasons unknown lacks
such a function.
svycor(formula, design, na.rm = FALSE, digits = getOption("jtoolsdigits", default = 2), sig.stats = FALSE, bootn = 1000, mean1 = TRUE, ...)
formula  A formula (e.g., ~var1+var2) specifying the terms to correlate. 

design  The 
na.rm  Logical. Should cases with missing values be dropped? 
digits  An integer specifying the number of digits past the decimal to
report in the output. Default is 2. You can change the default number of
digits for all jtools functions with

sig.stats  Logical. Perform nonparametric bootstrapping
(using 
bootn  If 
mean1  If 
...  Additional arguments passed to 
If significance tests are not requested, there is one returned value:
The correlation matrix (without rounding)
A matrix of p values
A matrix of t values
A matrix of standard errors
This function extends the survey
package by calculating the
correlations for userspecified variables in survey design and returning a
correlation matrix.
Using the wtd.cor
function, this function also
returns standard errors and pvalues for the correlation terms using a
sampleweighted bootstrapping procedure. While correlations do not require
distributional assumptions, hypothesis testing (i.e., \(r > 0\)) does.
The appropriate way to calculate standard errors and use them to define a
probability is not straightforward in this scenario since the weighting
causes heteroskedasticity, thereby violating
an assumption inherent in the commonly used methods for converting Pearson's
correlations into tvalues. The method provided here is defensible, but if
reporting in scientific publications the method should be spelled out.
This function was designed in part on the procedure recommended by Thomas Lumley, the author of the survey package, on Stack Overflow. However, he has not reviewed or endorsed this implementation. All defects are attributed to the author.
Other survey package extensions: svysd
Other survey tools: pf_sv_test
,
svysd
, weights_tests
,
wgttest
if (requireNamespace("survey")) { library(survey) data(api) # Create survey design object dstrat < svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, fpc = ~fpc) # Print correlation matrix svycor(~api00 + api99 + dnum, design = dstrat) # Save the results, extract correlation matrix out < svycor(~api00 + api99 + dnum, design = dstrat) out$cors }#> api00 api99 dnum #> api00 1.0000000 0.9759047 0.2543484 #> api99 0.9759047 1.0000000 0.2441910 #> dnum 0.2543484 0.2441910 1.0000000