rankCorrCluster {rankCorr}R Documentation

Total, between-, and within-cluster Spearman rank correlations for clustered data

Description

rankCorrCluster computes the total, between-, and within-cluster Spearman 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.

Usage

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
)

Arguments

x

a numeric or factor vector.

y

a numeric or factor vector.

cluster

a vector of cluster index corresponding to x and y.

link.x, link.y

the link family to be used for the ordinal models of x and y on cluster index. Defaults to ‘⁠logit⁠’. Other options are ‘⁠probit⁠’, ‘⁠cloglog⁠’, ‘⁠cauchit⁠’, and ‘⁠logistic⁠’ (equivalent with ‘⁠logit⁠’).

weights

a character string indicating which weighting method is used. Should be one of the strings "obs" and "clusters". Default is "obs". See Details.

methods_between_corr

a character string indicating which estimation method of the between-cluster correlation is used. Should be one of the strings "cluster-median", "approx", and "both". Default is "cluster-median". See Details.

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?

Details

The weighting method "obs" assigns equal weights to observations; w_{ij} = 1/N, where N is the total number of observations. The weighting method "clusters" assigns equal weights to clusters; w_{ij} = 1/(nk_i), 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 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 rank correlation using the approximated linear relationship between the total, between-, and within-cluster Spearman rank correlations.

Value

a list with following components.

'Total' the total Spearman 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 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 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.

References

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 rank correlations.

Examples

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")

[Package rankCorr version 1.0.1 Index]