2016-10-04 81 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))