Title: | Total, Between-, and Within-cluster Spearman's Rank Correlations for Clustered Data |
---|---|
Description: | Estimates the total, between-, and within-cluster Spearman's rank correlations between two variables with clustered data. |
Authors: | Shengxin Tu [aut, cre], Chun Li [aut], Bryan Shepherd [aut] |
Maintainer: | Shengxin Tu <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2024-11-17 04:25:25 UTC |
Source: | https://github.com/shengxintu/rankcorr |
rankCorrCluster
computes the total, between-, and within-cluster Spearman's rank correlations between two variables using two-level clustered data. It can be used with any orderable variable, including continuous and discrete variables. Two weighting methods are provided, including assigning equal weights to observations or to clusters.
rankCorrCluster( x, y, cluster, link.x = c("probit", "logistic", "cauchit", "loglog", "cloglog"), link.y = c("probit", "logistic", "cauchit", "loglog", "cloglog"), weights = c("obs", "clusters"), methods_between_corr = c("cluster-median", "approx", "both"), conf.int = 0.95, fisher = FALSE, na.rm = FALSE )
rankCorrCluster( x, y, cluster, link.x = c("probit", "logistic", "cauchit", "loglog", "cloglog"), link.y = c("probit", "logistic", "cauchit", "loglog", "cloglog"), weights = c("obs", "clusters"), methods_between_corr = c("cluster-median", "approx", "both"), conf.int = 0.95, fisher = FALSE, na.rm = FALSE )
x |
a numeric or factor vector. |
y |
a numeric or factor vector. |
cluster |
a vector of cluster index corresponding to |
link.x , link.y
|
the link family to be used for the ordinal models of
|
weights |
a character string indicating which weighting method is used.
Should be one of the strings |
methods_between_corr |
a character string indicating which estimation method of the between-cluster correlation is used.
Should be one of the strings |
conf.int |
numeric specifying confidence interval level. |
fisher |
logical, indicating whether to apply Fisher transformation to compute confidence intervals. |
na.rm |
logical. Should missing values be removed? |
The weighting method "obs"
assigns equal weights to observations; , where N is the total number of observations. The weighting method
"clusters"
assigns equal weights to clusters; , where n is the total number of clusters and k_i is the cluster size.
The estimation method
"cluster-median"
estimates the between-cluster Spearman's rank correlation using the coefficients from the cumulative probability models of x
and y
on cluster index cluster
. The estimation method "approx"
estimates the between-cluster Spearman's rank correlation using the approximated linear relationship between the total, between-, and within-cluster Spearman's rank correlations.
a list with following components.
'Total' |
the total Spearman's rank correlation, including the estimate (Estimate ), the standard error (SE ), the lower and upper bounds of the confidence interval (Lower, Upper ). |
'Within' |
the within-cluster Spearman's rank correlation, including the estimate (Estimate ), the standard error (SE ), the lower and upper bounds of the confidence interval (Lower, Upper ). |
'Between' |
the between-cluster Spearman's rank correlation estimated, including the estimation method name, the estimate (Estimate ), the standard error (SE ), the lower and upper bounds of the confidence interval (Lower, Upper ). |
'Rank ICC' |
the rank intraclass correlation coefficients of x and y . It would be presented in the output if 'approx' is used. |
Tu, S., Li, C., Zeng, D., and Shepherd, B. E. (2023). Rank intraclass correlation for clustered data. Statistics in Medicine 42, 4333-4348. |
Shih, J. H. and Fay, M. P. (2017). Pearson's chi-square test and rank correlation inferences for clustered data. Biometrics 73, 822-834. |
Tu S, Li C, Shepherd BE (2023) Between- and within-cluster Spearman's rank correlations for clustered data. |
if(!('mvtnorm' %in% installed.packages()[,"Package"])) install.packages('mvtnorm') library(mvtnorm) k <- 50; m <- 5 sigma.u <- matrix(c(1, 0.6, 0.6, 4), ncol=2); sigma.e <- matrix(c(1, 0.6, 0.6, 1), ncol=2) u <- rmvnorm(k, c(1, -1), sigma.u) x1 <- matrix(NA, k, m) y1 <- matrix(NA, k, m) for (i in 1:k){ r <- rmvnorm(m, c(0, 0), sigma.e) x1[i,] <- u[i, 1] + r[, 1] y1[i,] <- u[i, 2] + r[, 2] } x <- as.vector(t(x1)) y <- as.vector(t(y1)) cluster <- rep(1:k, each=m) rankCorrCluster(x, y, cluster, link.x = "probit", link.y = "probit", methods_between_corr = "approx") idx <- sample(1:250, 200, replace = TRUE) rankCorrCluster(x[idx], y[idx], cluster[idx], link.x = "probit", link.y = "probit", weights = "clusters")
if(!('mvtnorm' %in% installed.packages()[,"Package"])) install.packages('mvtnorm') library(mvtnorm) k <- 50; m <- 5 sigma.u <- matrix(c(1, 0.6, 0.6, 4), ncol=2); sigma.e <- matrix(c(1, 0.6, 0.6, 1), ncol=2) u <- rmvnorm(k, c(1, -1), sigma.u) x1 <- matrix(NA, k, m) y1 <- matrix(NA, k, m) for (i in 1:k){ r <- rmvnorm(m, c(0, 0), sigma.e) x1[i,] <- u[i, 1] + r[, 1] y1[i,] <- u[i, 2] + r[, 2] } x <- as.vector(t(x1)) y <- as.vector(t(y1)) cluster <- rep(1:k, each=m) rankCorrCluster(x, y, cluster, link.x = "probit", link.y = "probit", methods_between_corr = "approx") idx <- sample(1:250, 200, replace = TRUE) rankCorrCluster(x[idx], y[idx], cluster[idx], link.x = "probit", link.y = "probit", weights = "clusters")