我在R语言方面还是很新,而在stackoverflow中还是很新的。
我想在对数据框中的不同组执行ANOVA之后,不对数据进行子集设置并重复多次相同的操作,然后进行成组的事后测试(例如Tukey,SNK)。最好的显示结果的方法是再次使用带有变量“ by_group”,“ group”,“ letter”的数据框。为了显示字母,我使用了agricolae软件包
我尝试了其他操作,例如管道运算符或group_by,但均未成功。
我希望清楚我想要什么,并且有人可以帮助我。
# create dataframe with 10 diffrent experiments (that should analysed seperately)
Exp.No<-10 #number of experiments
s.size<- 6 # sample size per experiment play with it
k<- 5 # Number of categories
pop.mean<-370 ;pop.sd=38 #define population parameters
#sample data form population
dv<-rnorm(n=Exp.No*s.size*k,mean=pop.mean,sd=pop.sd)
#construct dataframe for the experiments
my.df<- data.frame(expand.grid(k=as.factor(1:k),rep=(1:s.size),Exp=(1:Exp.No)),y=dv)
View(my.df)
#perform ANOVA for each experiment and evaluate result
#define by group create a "grouped dataframe"
by.Exp<-group_by(my.df,Exp);str(by.Exp)
anova.by.exp<-by.Exp%>% do(tidy(Anova(aov(y~k,data=.))))#%>% filter(term=="k")
#for a single experiment I could use the aov model and perform a post hoc test like this
modExp1<- aov(y~k,data=subset(my.df, Exp==1))
library(agricolae)
lines<-HSD.test(modExp1,"k");lines$groups
#I would like some thing like this but with an additional variable for the Experiment