简体   繁体   English

双向方差分析-在r中重复测量,缺少预期效果

[英]Two way ANOVA - repeated measure in r, missing a desired effect

I am trying to do a two way mixed factorial ANOVA with repeated measures. 我正在尝试使用重复测量方法进行两因素混合方差分析。 From: 从:

aov(Estimate ~ Dose*Visit, data = AUClast) 

I get 3 sums of squares: two main effects (Visit and Dose) and their interaction (Dose:Visit) which I figured out by hand are correct. 我得到3个平方和:手工算出的两个主要效果(“访问”和“剂量”)及其相互作用(“剂量:访问”)是正确的。

Both Dose and Visit are explanatory variables with Dose being a between subject variable with 4 levels, 3, 10, 30, 100 and Visit being a within subjects variable (repeated measure) of 2 levels, 1 and 28. Also, the subjectID variable is 'Animal' Dose和Visit都是说明性变量,Dose是介于4、3、10、30、100个级别的主题变量之间,而Visit是介于2个级别1和28的主题变量(重复度量)之内。而且,subjectID变量是'动物'

I want to include one more effect into the result but do not know how. 我想在结果中再增加一种效果,但不知道如何。 The desired effect is variance between Animal within Dose, or how SAS puts it Animal(Dose). 所需的效果是剂量内动物之间的差异,或SAS如何将其置于动物(剂量)中。 The SS is calculated by: SS通过以下方式计算:

sum((mean(Animal(ik))-mean(Dose(i))^2)

Where k is the animal of a dose i (averaging the Estimates of the observation in Visit 1 and Visit 28 for each Animal and subtracting the mean Estimate of animals in that Dose quantity squared for all Animals in this study). 其中k是剂量为i的动物(对每只动物进行第1次访问和第28次访问的观察估计值的平均值,然后减去该研究中所有动物剂量的平方的动物平均估计值)。

Does anyone know how to adjust the formula accordingly to include the Animal(Dose) effect? 有谁知道如何相应地调整公式以包括动物(剂量)效应?

Thanks in advance for the help and sorry if all of this is too unspecific. 在此先感谢您的帮助,对于所有这些都不太明确的内容,我们深感抱歉。

If I understand you correctly, I have a suggestion. 如果我对您的理解正确,那么我有个建议。 First, a sample data set 首先,样本数据集

#sample data
set.seed(15)
AUClast<-data.frame(
    expand.grid(
    Animal=1:3,
    Dose=c(3,10,30,100),
    Visit=c(1,28)
    ), Estimate=runif(24)
)

Now we calculate the interaction term as requested. 现在,我们根据要求计算交互作用项。 First, we split the data into dosage groups, then for each does, we subtract the overall mean from the mean for each animal. 首先,我们将数据分为剂量组,然后对每个剂量组,从每只动物的平均值中减去总体平均值。 Then we sum the squared of those differences. 然后,我们将这些差异的平方求和。 Finally, we expand them back out to does group using unsplit . 最后,我们将它们扩展回使用unsplit进行的分组。

animaldose<-unsplit(lapply(split(AUClast, AUClast$Dose), function(x) {
    rep(
        sum((tapply(x$Estimate, x$Animal, mean) - mean(x$Estimate))^2)
    , nrow(x))
}), AUClast$Dose)

And we can see what that looks like next to the original data.frame 我们可以看到原始data.frame旁边的样子

cbind(AUClast, animaldose)

Which gives the result 给出结果

   Animal Dose Visit   Estimate animaldose
1       1    3     1 0.60211404  0.1181935
2       2    3     1 0.19504393  0.1181935
3       3    3     1 0.96645873  0.1181935
4       1   10     1 0.65090553  0.1641363
5       2   10     1 0.36707189  0.1641363
6       3   10     1 0.98885921  0.1641363
7       1   30     1 0.81519341  0.0419291
8       2   30     1 0.25396837  0.0419291
9       3   30     1 0.68723085  0.0419291
10      1  100     1 0.83142902  0.1881314
11      2  100     1 0.10466936  0.1881314
12      3  100     1 0.64615091  0.1881314
13      1    3    28 0.50909039  0.1181935
14      2    3    28 0.70662857  0.1181935
15      3    3    28 0.86231366  0.1181935
16      1   10    28 0.84178515  0.1641363
17      2   10    28 0.44744372  0.1641363
18      3   10    28 0.96466695  0.1641363
19      1   30    28 0.14118707  0.0419291
20      2   30    28 0.77671251  0.0419291
21      3   30    28 0.80372740  0.0419291
22      1  100    28 0.79334595  0.1881314
23      2  100    28 0.35756312  0.1881314
24      3  100    28 0.05800106  0.1881314

So you can see each does group has it's own adjustment. 这样您就可以看到每个工作组都有自己的调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM