Problem to code an AOV

Hi,
I am beginning on R and I am struggleling a bit ^^.
It is my first post, so I may have forgot/don't undertstand some rules. I am sorry if it's the case.
If it's not in the right place, let me know it.
I try to build a little tool for data analysis and I am stuck. It is on a data set including (Name of the proteins/Normalized expression/What organism has been used/with what it has been infected/Organismpathogen***/number of replica/if it has been treat by placebo or real pathogen)


library(dplyr)

#>

#> Attachement du package : 'dplyr'

#> The following objects are masked from 'package:stats':

#>

#> filter, lag

#> The following objects are masked from 'package:base':

#>

#> intersect, setdiff, setequal, union

library(tidyverse)

#Building an AOV

data%>%aov(formula=formula("Norm~Strain*Cultivar*rep"))%>%tidy()%>%mutate(contribVariance=paste(round(100*meansq/sum(meansq),0),"%"))->aov

#> Error in tidy(.): impossible de trouver la fonction "tidy"

summary(aov)

#> Error in object[[i]]: objet de type 'closure' non indiçable

Created on 2021-03-03 by the reprex package (v1.0.0)

I don't understand why he doesn't find tidy (I took the formula from a lesson)

Furthermore I would like to comput a lot of Anova (I want to see wich protein have a significative differential of expression)

I was thniking something like :

library(dplyr)
#> 
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tidyverse)
#Building an AOV for every protein
data%>%filter(Protein=="TraesCS1A01G002200.1")->data_premiere_prot
#> Error in UseMethod("filter"): pas de méthode pour 'filter' applicable pour un objet de classe "function"
data_premiere_prot%>%aov(formula=formula("Norm~Strain*Cultivar*rep"))->aovprot
#> Error in terms.formula(formula, "Error", data = data): objet 'data_premiere_prot' introuvable
summary(aovprot)
#> Error in summary(aovprot): objet 'aovprot' introuvable

Created on 2021-03-03 by the reprex package (v1.0.0)
How can I do for build a loop able to change automatically the name of my protein ?
ps : on my R I don't have any problem with filter, I don't know why the reprex found one ^^''.

In your first example, I think R cannot find the tidy() function because it is part of the broom package and that package is not loaded as part of tidyverse. Try running

library(broom)

For you question about doing many tests, I would write a function to return the result of aov() and then use the map() function from purrr to iterate over a vector of protein names.

library(purrr)
library(dplyr)

DF <- data.frame(Protein = rep(c("A", "B"), each = 30),
                 Treatment = c(rep(c("T", "Placebo"), each = 15),rep(c("T", "Placebo"), each = 15) ),
                 Value = c(rnorm(15, 1, .3), rnorm(15, 1.4, .3), rnorm(15, 2, .3), rnorm(15, 2.2, .3)))
head(DF)
#>   Protein Treatment     Value
#> 1       A         T 1.1328789
#> 2       A         T 0.7137068
#> 3       A         T 0.8887848
#> 4       A         T 0.6592692
#> 5       A         T 1.0194686
#> 6       A         T 0.6457387
Proteins <- c("A", "B")
AOVfunc <- function(P) {
  tmp <- filter(DF, Protein == P)
  aov(Value ~ Treatment, data = tmp)
}
Tests <- map(Proteins, .f = AOVfunc)
map(Tests, summary)
#> [[1]]
#>             Df Sum Sq Mean Sq F value   Pr(>F)    
#> Treatment    1  1.356  1.3560   20.68 9.55e-05 ***
#> Residuals   28  1.836  0.0656                     
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> [[2]]
#>             Df Sum Sq Mean Sq F value Pr(>F)
#> Treatment    1  0.000 0.00000       0  0.998
#> Residuals   28  2.724 0.09727

Created on 2021-03-03 by the reprex package (v0.2.1)

Finally, the reprex cannot find an object called data but there is a function called data, so it tries to pass that to the filter() function and filter() does not know how to process a function. I suggest you do not call your data object data because of the existing function. If you had defined data within the reprex, it would have worked.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.