当每个变量都通过独立重复测量时,如何评估相关性?

机器算法验证 回归
2022-04-15 14:24:59

我经常在许多站点测量多个变量,在多个重复中。例如,我可能会在许多地点测量细菌丰度和细菌生长速率,每个重复 3 次。每个重复都是独立采样的每个变量都是在不同的样本中测量的(即,我无法同时测量同一样本中的细菌丰度和生长速率)。

我想测试这些变量之间的相关性。问题是,由于变量是独立测量的,因此变量不是成对的。变量 A 的重复 1 与变量 B 的重复 1 无关,与变量 B 的重复 2 无关。

我可以测试每个站点的复制平均值之间的相关性 - 但这似乎很生硬,因为您会丢失有关每个参数的复制之间变化的信息。我可以想象某种重采样方法,我在每个站点为每个变量随机选择一个副本。有没有更好的办法?

1个回答

根据您的描述,我认为唯一可行的方法是您不想做的事情:使用存储桶作为分析级别。也就是说,聚合每个桶中的 3 个测量值,您就有了配对。使用这种方法,您应该有效地汇总测量误差。

我做了一个小型模拟,并将这种方法与第二种方法进行了比较,在第二种方法中,我使用每个桶的所有可能配对来估计相关性。结果表明,聚合方法在恢复原始相关性方面效果更好:

# I use R and the mvtnorm library to generate the data
library(mvtnorm)

set.seed(12345) # make reproducible

nbuckets <- 50  #number of buckets
r.buckets <- 0.5  # correlation across buckets

# generate data
Cor <- array(c(1, r.buckets, r.buckets, 1), dim=c(2,2))
d.bucket <- rmvnorm(nbuckets, sigma = Cor)
measurement.error = 0.5 # size of eror in relation to sd of the data
data <- vector("list", nbuckets)

for (bucket in seq_len(nbuckets)) {
    data[[bucket]] <- list(x = rep(d.bucket[bucket, 1], 3) + rnorm(3, measurement.error), y = rep(d.bucket[bucket, 2], 3) + rnorm(3, sd = measurement.error))
}
# Note that there are separate error terms for the two types of measurements 

# aggregating per bucket:
data.agg <- lapply(data, function(x) data.frame(x = mean(x[[1]]), y = mean(x[[2]])))
data.agg <- do.call("rbind", data.agg)
cor(data.agg$x, data.agg$y) # should give .408

# using all pairs:
all.pairs <- lapply(data, function(x) data.frame(x = x[[1]], y = x[[2]][c(1:3,3:1,2,1,3,2,3,1,1,3,2,3,1,2)]))
all.pairs <- do.call("rbind", all.pairs)
cor(all.pairs$x, all.pairs$y) # should give .321

如果您允许更大的测量误差(尽管它已经很大),差异仍然存在。如果您在每个桶中允许单个误差项,则结果将更接近 r 的实际值,并且方法之间的差异将减小。但是,聚合仍然是更好的策略。

我建议你用更现实的值来玩弄它。您甚至可以按照最初的想法实施引导方法。