[英]Nested ANOVA in R with 4 samples
This category of question has been asked before but none of them could provide me with a hint to solve my problem (basically they lack sample data). 之前曾提出过此类问题,但没有一个可以为我提供解决我的问题的提示(基本上他们没有样本数据)。 I am sorry that I am bothering the community with my question but please bit of guidance will help me.
很抱歉让我困扰我的问题,但是请提供一些指导会对我有所帮助。
My sample data files on which I want to perform nested ANOVA are: 我要对其执行嵌套方差分析的样本数据文件是:
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
The above are four files with observations in four samples. 上面是四个文件,其中包含四个样本中的观察结果。
My approach: 我的方法:
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)
Problem to proceed further to get: 要进一步获得的问题:
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
I had a look at this page http://www.math.wustl.edu/~victor/classes/ma322/r-eg-11.txt 我浏览了此页面http://www.math.wustl.edu/~victor/classes/ma322/r-eg-11.txt
But I am stuck at this step (as put in the webpage) : 但是我被困在这一步(如网页所示):
gender <- gl(2,3*4,2*3*4, labels=c("Male", "Female") )
Kindly help 请帮助
Thank you 谢谢
For all the the variables with out interaction effect 对于所有没有交互作用的变量
data.aov <- aov(a ~ . , data= dat)
Or just some 或者只是一些
data.aov <- aov(a ~ b+c,data = data)
Or with interaction etc. 或与互动等
data.aov <- aov( a ~ b + c + b*c, data.dat)
Your sticking point is a data manipulation (a method that site uses looks a bit complex and ...). 您的症结在于数据操作(站点使用的一种方法看起来有点复杂……)。 For analyze, it would be better to refer additionally to this site as @Jimbou mentioned
为了进行分析,最好另外引用此站点,如@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
Because I packed all data in data.frame
, you need to write data = df
in the function. 因为我将所有数据打包在
data.frame
,所以您需要在函数中写入data = df
。
1) Model I (fixed-effects) ANOVA for all effects and interactions 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) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.