svycor | R Documentation |
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("jtools-digits", 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 non-parametric bootstrapping
(using |
bootn |
If |
mean1 |
If |
... |
Additional arguments passed to |
This function extends the survey
package by calculating the
correlations for user-specified variables in survey design and returning a
correlation matrix.
Using the wtd.cor
function, this function also
returns standard errors and p-values for the correlation terms using a
sample-weighted 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 t-values. The method provided here is defensible, but if
reporting in scientific publications the method should be spelled out.
If significance tests are not requested, there is one returned value:
cors |
The correlation matrix (without rounding) |
If significance tests are requested, the following are also returned:
p.values |
A matrix of p values |
t.values |
A matrix of t values |
std.err |
A matrix of standard errors |
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.
Jacob Long jacob.long@sc.edu
wtd.cor
, svymean()
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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.