我觉得我错过了一些明显的东西,但我们开始吧。我有两次(或更多)治疗的一式三份测量的自相关数据。像这样的东西:
t <- 3:20 #times in my real dataset are possibly not always equidistant
a <- structure(c(0.652492388457625, 0.905172522010166, 1.23437705454616,
1.48003667490842, 1.77876898946135, 1.99175317367897, 2.31666502140984,
2.43520651415548, 2.67903421794922, 2.84115747823017, 2.89693734873647,
2.91199679761145, 2.85645436179354, 2.99371033437697, 2.99965220711105,
2.84984814715963, 2.64275376547326, 2.64060469520379, 0.481029734912324,
0.8466803252367, 1.31126162780809, 1.56745630574946, 1.74865844658142,
1.80367117155375, 2.06688393210808, 2.24500095501872, 2.52978288460243,
2.69073206006205, 2.89657418056785, 2.93759772556246, 2.99305951550274,
2.89146932307489, 2.88890777189028, 2.7974672802907, 2.70933381639295,
2.66799551352975, 0.624178180970784, 0.867127935268765, 1.09752295578438,
1.35037796202753, 1.60094288950107, 1.97949255710341, 2.15496378191076,
2.42556913246041, 2.54331160179646, 2.67440414122285, 2.84249532365163,
2.95278639560433, 3.06192227561515, 3.03297885461444, 3.04101341059534,
3.01736966686846, 2.80061410999215, 2.69852643323913),
.Dim = c(18L, 3L), .Dimnames = list(NULL, c("a1", "a2", "a3")))
b <- structure(c(0.516527990622755, 0.84883434472028, 1.04202664437099,
1.3100841689546, 1.48050413266838, 1.7824492800856, 1.96557179831706,
2.17419105778186, 2.2453178060978, 2.35460428313729, 2.49308342865959,
2.62343038370418, 2.70831189685371, 2.79459971623943, 2.94938536147398,
3.04822554887815, 3.00287042052314, 2.91673487674283, 0.589490441973075,
0.751768045201717, 0.917973959434798, 1.17617337222852, 1.39497560590896,
1.65920945485901, 1.87749014780468, 2.11880355292648, 2.372755207219,
2.46211141942227, 2.59688733749884, 2.72270421752644, 2.79848710425447,
2.81134394947587, 2.75390203306788, 2.78499114431362, 2.86001341271914,
2.95652300178809, 0.558662398944567, 0.834996005844121, 0.988238211915554,
1.27569591423003, 1.38577342414377, 1.62664982549252, 1.83299700801392,
2.04943560731628, 2.22950648854987, 2.38533269800646, 2.49845003387994,
2.60036098089373, 2.61941602504858, 2.71298500309883, 2.78126388719353,
3.04792375845498, 3.02691814463875, 3.06667590650438),
.Dim = c(18L, 3L), .Dimnames = list(NULL, c("b1", "b2", "b3")))
matplot(t,a,pch=1,xlab="",ylab="",col="blue")
matlines(t,a,col="blue", lty=2)
matpoints(t,b,pch=16,col="red")
matlines(t,b,col="red", lty=2)
我想知道治疗不同的时间段。我想避免拟合任何类型的模型。(我的科学数据有模型,但已知它们只是我的某些数据范围的近似值,我担心模型错误可能会掩盖差异。)我的想法是计算平均值并构建置信度像这样的间隔(使用正态性假设):
a_means <- apply(a,1,mean)
a_sds <- apply(a,1,sd)
a_lwr <- a_means-qt(0.975,3)*a_sds/sqrt(3)
a_upr <- a_means+qt(0.975,3)*a_sds/sqrt(3)
b_means <- apply(b,1,mean)
b_sds <- apply(b,1,sd)
b_lwr <- b_means-qt(0.975,3)*b_sds/sqrt(3)
b_upr <- b_means+qt(0.975,3)*b_sds/sqrt(3)
DF <- data.frame(treat=factor(rep(1:2, each=length(t))),
time=rep(t, 2),
mean=c(a_means,b_means),
lwr=c(a_lwr,b_lwr),
upr=c(a_upr,b_upr))
library(ggplot2)
p <- ggplot(DF, aes(x=time, y=mean, ymin=lwr, ymax=upr)) +
geom_ribbon(aes(fill=treat), alpha=0.3) +
geom_line(aes(color=treat))
print(p)
我构建置信区间的方式显然没有考虑自相关。
- 有没有办法构建某种“自相关置信区间”?
- 我可以使用“不相关的置信区间”吗?与自相关置信区间相比,我能否以某种方式估计它是否太窄或太宽?
- 有没有更好的方法来解决我的问题?