covs_test {quest} | R Documentation |
Covariances Test of Significance
Description
covs_test
computes sample covariances and tests for their significance
with the Pearson method assuming multivariate normality of the data. Note,
the normal-theory significance test for the covariance is much more sensitive
to departures from normality than the significant test for the mean. This
function is the covariance analogue to the psych::corr.test()
function
for correlations.
Usage
covs_test(data, vrb.nm, use = "pairwise", ci.level = 0.95, rtn.dfm = FALSE)
Arguments
data |
data.frame of data. |
vrb.nm |
character vector of colnames specifying the variables in
|
use |
character vector of length 1 specifying how missing values are
handled. Currently, there are only two options: 1) "pairwise" for pairwise
deletion (i.e., |
ci.level |
numeric vector of length 1 specifying the confidence level. It must be between 0 and 1 - or it can be NULL in which case confidence intervals are not computed and the return object does not have "lwr" or "upr" columns. |
rtn.dfm |
logical vector of length 1 specifying whether the return object should be an array (FALSE) or data.frame (TRUE). If an array, then the first two dimensions are the matrix dimensions from the covariance matrix and the 3rd dimension (aka layers) contains the statistical information (e.g., est, se, t). If data.frame, then the first two columns are the matrix dimensions from the covariance matrix expanded and the rest of the columns contain the statistical information (e.g., est, se, t). |
Value
If rtn.dfm = FALSE
, an array where its first two dimensions
are the matrix dimensions from the covariance matrix and the 3rd dimension
(aka layers) contains the statistical information detailed below. If
rtn.dfm = TRUE
, a data.frame where its first two columns are the
expanded matrix dimensions from the covariance matrix and the rest of the
columns contain the statistical information detailed below:
- cov
sample covariances
- se
standard errors of the covariances
- t
t-values
- df
degrees of freedom (n - 2)
- p
two-sided p-values
- lwr
lower bound of the confidence intervals (excluded if
ci.level = NULL
)- upr
upper bound of the confidence intervals (excluded if
ci.level = NULL
)
See Also
cov
for covariance matrix estimates,
corr.test
for correlation matrix significant testing,
Examples
# traditional use
covs_test(data = attitude, vrb.nm = names(attitude))
covs_test(data = attitude, vrb.nm = names(attitude),
ci.level = NULL) # no confidence intervals
covs_test(data = attitude, vrb.nm = names(attitude),
rtn.dfm = TRUE) # return object as data.frame
# NOT same as simple linear regression slope
covTest <- covs_test(data = attitude, vrb.nm = names(attitude),
ci.level = NULL, rtn.dfm = TRUE)
x <- covTest[with(covTest, rownames == "rating" & colnames == "complaints"), ]
lm_obj <- lm(rating ~ complaints, data = attitude)
y <- coef(summary(lm_obj))["complaints", , drop = FALSE]
print(x); print(y)
z <- x[, "cov"] / var(attitude$"complaints")
print(z) # dividing by variance of the predictor gives you the regression slope
# but the t-values and p-values are still different
# NOT same as correlation coefficient
covTest <- covs_test(data = attitude, vrb.nm = names(attitude),
ci.level = NULL, rtn.dfm = TRUE)
x <- covTest[with(covTest, rownames == "rating" & colnames == "complaints"), ]
cor_test <- cor.test(x = attitude[[1]], y = attitude[[2]])
print(x); print(cor_test)
z <- x[, "cov"] / sqrt(var(attitude$"rating") * var(attitude$"complaints"))
print(z) # dividing by sqrt of the variances gives you the correlation
# but the t-values and p-values are still different