【问题标题】:Nested ANOVA in R with 4 samplesR中的嵌套方差分析,有4个样本
【发布时间】:2016-10-04 09:25:58
【问题描述】:

此类问题以前曾被问过,但他们都无法为我提供解决问题的提示(基本上他们缺乏样本数据)。很抱歉我的问题打扰了社区,但请提供一些指导会对我有所帮助。

我要对其执行嵌套方差分析的示例数据文件是:

a       b       c       d
2079    3141    2849    4277
2080    3202    3498    3883
1852    3739    2427    3793
3317    2511    3504    2317
3015    2533    1852    3605
2452    2871    4891    3427
2445    3484    2307    1948
3007    5639    2838    2836
4468    2239    4207    1202
2760    8820    2214    3509

a        b       c      d
3414    4357    6449    3424
2963    1827    3018    3216
2816    4254    2386    6711
2196    3634    3520    3836
2492    5676    3093    2993
1948    10109   2783    3979
2298    9456    2821    2430
4937    3111    2436    4163
3956    4955    2598    5105

    a        b       c       d 
   3637   3724    2827    3661
    3011    3190    5502    4393
    3879    2087    2237    3517
    5057    4731    3324    4029
    4045    3521    2262    3168
    4396    2410    3096    4622
    3053    2252    4162    3427
    3408    1954    3127    2935
    2021    3359    2970    2229
    5723    3874    4981    2375
    3866    4250    2001    2409
    2838    6014    3121    2836

 a    b        c       d
 3213   4733    3084    2671
2071    5239    2395    4204
2687    4924    2992    5175
2321    4251    2646    3628
2125    5769    3868    6943
4118    7649    2403    2348
4383    3048    2998    2862
3808    5482    2986    2515
2455    2420    2292    2652
2656    4973    3892    2826
4589    2882    5800    2745
6701    6567    2196    3692
2292    3834    3776    5860
4173    2610    2313    2298
3247    6040    1853    3536
3383    3292    4134    3773
3805    3789    2172    3032

以上是四个样本中的四个文件。

我的做法:

rep1=read.table("a.txt", header=T, sep="\t")
rep2=read.table("b.txt", header=T, sep="\t")
rep3=read.table("c.txt", header=T, sep="\t")
rep4=read.table("d.txt", header=T, sep="\t")
lintmass <- c(rep1,rep2,rep3,rep4)

问题进一步得到:

1) Model I (fixed-effects) ANOVA for all effects and interactions
2) Model I (fixed-effects) ANOVA for just the single-factor effects
3) Model I ANOVA for just the factor interactions

我看过这个页面http://www.math.wustl.edu/~victor/classes/ma322/r-eg-11.txt

但我被困在这一步(如网页所示):

gender <- gl(2,3*4,2*3*4, labels=c("Male", "Female") )

请帮忙

谢谢

【问题讨论】:

  • this 对您有帮助吗?
  • @Jimbou:在将问题放在这里之前,我查看了该页面。很抱歉没有提出明确的问题,请查看更新后的帖子。
  • @cuttlefish44 是的,a,b,c,d 对应物种,样本数据四块对应性别。 a.txt 用于第一个块。

标签: r anova


【解决方案1】:

对于所有没有交互作用的变量

data.aov <- aov(a ~ . , data= dat)

或者只是一些

data.aov <- aov(a ~  b+c,data = data)   

或与交互等。

data.aov <- aov( a ~ b + c + b*c, data.dat)

【讨论】:

    【解决方案2】:

    您的症结在于数据操作(网站使用的一种方法看起来有点复杂......)。为了进行分析,最好另外参考@Jimbou 提到的this site

     ## read the data
    rep1 = read.table("a.txt", header=T, sep="\t")
    rep2 = read.table("b.txt", header=T, sep="\t")
    rep3 = read.table("c.txt", header=T, sep="\t")
    rep4 = read.table("d.txt", header=T, sep="\t")
    
     ## add a factor information (I called it *gender*) and combine
    rep1$gender <- "JJ"
    rep2$gender <- "KK"
    rep3$gender <- "LL"
    rep4$gender <- "MM"
    
    data <- rbind(rep1, rep2, rep3, rep4)
    
     ## chage data into long format using `melt()` and change `colnames`
    library(reshape2)
    
    df <- melt(data)
    names(df) <- c("gender", "species", "lintmass")
    
    # > head(df, n=3)
    #   gender species lintmass
    # 1     JJ       a     2079
    # 2     JJ       a     2080
    # 3     JJ       a     1852   # finishing a data manipulation
    

    因为我把所有数据都打包在data.frame中,所以需要在函数中写data = df

    1) 所有效应和交互作用的模型 I(固定效应)方差分析

    model1.1 <- aov(lintmass ~ species * gender, data = df)
    summary(model1.1)
      # this is equivalent to anova( lm(lintmass ~ species * gender, data = df) )
    

    【讨论】:

      猜你喜欢
      • 2014-02-06
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2014-03-20
      • 1970-01-01
      相关资源
      最近更新 更多