2016-10-04 33 views
0

这个类别的问题已经被问到过,但他们都不能提供给我一个提示来解决我的问题(基本上他们缺少样本数据)。我很抱歉,我用我的问题打扰了社区,但请稍微指点一下会对我有所帮助。在其上我想执行嵌套ANOVAR中有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")) 

请帮助

谢谢

+0

不[此](http://conjugateprior.org/2013/01/formulae-in-r-anova/ ) 帮你? – Jimbou

+0

@Jimbou:在将问题提交到此处之前,我查看了该页面。对于没有提出明确问题的道歉,请查看更新的帖子。 – Angelo

+0

@墨鱼鱼是的,a,b,c,d对应于物种和样本数据,四个区块对应于性别。 a.txt用于第一个块。 – Angelo

回答

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

您的问题在于数据操作(网站使用的方法看起来有点复杂,...)。对于分析,这将是更好的附加参考this site作为@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(固定效果)ANOVA所有效应和相互作用

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