
Last chance! 50% off unlimited learning
Sale ends in
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,
...
)
If significance tests are not requested, there is one returned value:
The correlation matrix (without rounding)
If significance tests are requested, the following are also returned:
A matrix of p values
A matrix of t values
A matrix of standard errors
A formula (e.g., ~var1+var2) specifying the terms to correlate.
The survey.design
or svyrep.design
object.
Logical. Should cases with missing values be dropped?
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
options("jtools-digits" = digits)
where digits is the desired number.
Logical. Perform non-parametric bootstrapping
(using wtd.cor
) to generate standard errors and
associated t- and p-values. See details for some considerations when doing
null hypothesis testing with complex survey correlations.
If sig.stats
is TRUE, this defines the number of
bootstraps to be run to generate the standard errors and p-values. For
large values and large datasets, this can contribute considerably to
processing time.
If sig.stats
is TRUE, it is important to know whether the
sampling weights should have a mean of 1. That is, should the standard
errors be calculated as if the number of rows in your dataset is the total
number of observations (TRUE) or as if the sum of the weights in your
dataset is the total number of observations (FALSE)?
Additional arguments passed to svyvar()
.
Jacob Long jacob.long@sc.edu
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.,
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
}
Run the code above in your browser using DataLab