测试两组的最大值时间是否不同

机器算法验证 假设检验 重复测量 群体差异
2022-04-12 17:06:51

假设我对一个定量变量进行了 10 次重复测量X两组中的个人(我们称他们为 A 和 B)。对于每个组,我都有变量的估计均值X在 10 个时间点,即

μ^1A,μ^2A,,μ^10A
μ^1B,μ^2B,,μ^10B,
和相应的10×10这些估计的方差 - 协方差矩阵。

的测试

H0:μtA=μtB
(为了t=1,,10) 可以很容易地使用 Wald 型测试(对多重测试进行适当的校正)进行:
z=μ^tAμ^tBVar(μ^tA)+Var(μ^tB).

现在我想测试每组内最大值的时间点在两组之间是否不同。我想原假设可以写成

H0:t=tformax(μtA)andmax(μtB).
有什么方法可以测试它?

编辑:一些 R 代码来模拟要玩的数据。

library(MASS)

### number of individuals in the two groups
n1 <- 50
n2 <- 50

### assume a flat trajectory with a single peak at times 4 and 6 in the respective groups
mu1 <- rep(0,10)
mu2 <- rep(0,10)
mu1[4] <- 1
mu2[6] <- 1

### make the raw data autocorrelated with an AR1 structure
V1 <- 5 * toeplitz(ARMAacf(ar=.7, lag.max=9))
V2 <- 5 * toeplitz(ARMAacf(ar=.7, lag.max=9))

### simulate raw data
X1 <- mvrnorm(n1, mu1, V1)
X2 <- mvrnorm(n2, mu2, V2)

### observed means over time in each group
m1 <- apply(X1, 2, mean)
m2 <- apply(X2, 2, mean)

### find time of the maximum mean in each group
tmax1 <- which(m1 == max(m1))
tmax2 <- which(m2 == max(m2))

### plot means over time in each group
plot(1:10, m1,  type="o", pch=19, ylim=range(c(m1,m2)), col="red", xlab="Time", ylab="Mean")
lines(1:10, m2, type="o", pch=19, ylim=range(c(m1,m2)), col="blue")
points(tmax1, max(m1), pch=19, cex=2, col="red")
points(tmax2, max(m2), pch=19, cex=2, col="blue")

以及结果图的示例。

两组随时间变化的平均值

1个回答

好吧,我不完全确定我是否找到了答案……但我的想法不适合发表评论。所以我会发帖看看这里的聪明人指出了什么。

正如我上面评论的那样,我会引导每个组内的最大时间,但按个人分层 - 通过重新采样X1X2

library(boot)
b1 <- boot(X1,statistic=function(X,index)which.max(apply(X[index,],2,mean)),10000)
b2 <- boot(X2,statistic=function(X,index)which.max(apply(X[index,],2,mean)),10000)

然后我们可以查看自举最大值的差异分布:

foo <- b1$t-b2$t
ecdf(foo)(0)
hist(foo,breaks=seq(-10.5,10.5))

直方图

现在,零时的 ecdf 告诉我们 96.89% 的差异小于零,这在某些圈子中足以声称并称其为一天;-) 但是,我真的不明白这两个峰值在哪里在直方图中来自。有人有想法吗?p<0.05

(无论如何,有趣的问题......)


编辑:只是为了踢,这是可以合理采取的另一种方法 - 按组列出每个人的最大时间并执行测试:χ2

incidence <- cbind(
    table(factor(apply(X1,1,which.max),levels=1:10)),
    table(factor(apply(X2,1,which.max),levels=1:10)))
chisq.test(incidence)