I need to compute a statistical analysis that compares control vs treatment for each gene, I've identified the type of stats that I need and it works if performed to one gene:
df <- data.frame(Gene = c("A","A","A","A","A","A","B","B","B","B","B","B"),
Value =c(12.554595492,13.554595492,14.554595492,8.554595492,2.554595492,3.554595492,13.554595492,8.554595492,16.5444425154,11.5444425154,3.5444425154,4.5444425154),
Treat=c("tre1","tre1","tre2","tre2","Control","Control","tre1","tre1","tre2","tre2","Control","Control"))
df$Treat <- as.factor(df$Treat)
A <- df %>% filter("A"== Gene)
model <- aov(Value ~ Treat, data = A)
summary(model)
model_1 <- glht(model = model,linfct = mcp(Treat="Dunnett"))
summary(model_1)
output<-capture.output(summary(model_1), file=NULL, append=FALSE)
output_df <-as.data.frame(output)
I would like to automate this operation to all the genes in the df and generate a final df that collects the results of all summaries.
When I try to perform the code in a for loop, I get the error "Error in eval(predvars, data, env) : object 'Value' not found". Where is the code wrong?
df_list <- split(df,f=df$Gene)
df_final <- data.frame()[1:16, ]
for(i in length(df_list)){
model <- aov(Value ~ Treat, data = i)
summary(model)
model_1 <- glht(model = model,linfct = mcp(Treat="Dunnett"))
summary(model_1)
output<-capture.output(summary(model_1), file=NULL, append=FALSE)
output_df <-as.data.frame(output)
df_final <- cbind (df_final,output_df)
}
The only difference I found between the dataframe A and those in the list is the Value as number in A and as double in the list. Is this the reason? how to fix it?
Any help or suggestion is appreciated! Thanks.