嵌套方差分析在R与4个样本



这类问题以前有人问过,但没有一个能给我一个提示来解决我的问题(基本上他们缺乏样本数据)。我很抱歉,我的问题打扰了社区,但请一些指导将帮助我。

我想要执行嵌套方差分析的样本数据文件是:

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") )

请帮助

谢谢

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

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

或者只是一些

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

或与交互等

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

您的症结是数据操作(网站使用的方法看起来有点复杂……)。为了便于分析,最好把这个网站另外称为@Jimbou。

 ## 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) )

最新更新