Anova test in the loop and outputing the p-value in separate column

Posted by Juanhijuan on Stack Overflow See other posts from Stack Overflow or by Juanhijuan
Published on 2013-10-24T15:48:34Z Indexed on 2013/10/24 15:53 UTC
Read the original article Hit count: 218

Filed under:

Once again I'm trying to get an answer. I am already stuck for like 5h with that so that's why I keep trying to get an answer.

That's my data:

    id          Sequence         variable      value
    75   AAAAGAAAVANQGKK BiotinControl1_2 3893050.50 
   192   AAAAGAAAVANQGKK BiotinControl1_2  900604.61 
  3770     AAFTKLDQVWGSE BiotinControl1_2   90008.14

The code which I am trying to use to calculate the p-value:

My Code:

tbl_anv <- tbl_all_onlyK[,c("id", "BiotinControl1_2", "BiotinControl2", "BiotinControl3", "BiotinTreatment1_2", "BiotinTreatment2", "BiotinTreatment3", "Sequence")]

tbl_reo <- melt(tbl_anv, measure.vars=2:7)

set.seed(1)
vars <- c("id", "BiotinControl1_2", "BiotinControl2", "BiotinControl3",   
      "BiotinTreatment1_2", "BiotinTreatment2", "BiotinTreatment3",
      "Sequence")

tbl_reo <- as.data.frame(tbl_reo)

by(tbl_reo,tbl_reo$Sequence,function(x){ 
  anova(lm(value ~ variable, data = x))$"Pr(>F)"[1]
  })

An error ocurs:

There were 50 or more warnings (use warnings() to see the first 50)

Anyway, how can I do that and export the p-value in the separate column.

That's what I tried to do on my own:

aov_test <- by(tbl_reo,tbl_reo$Sequence,function(x){ 
anova(lm(value ~ variable, data = x))$"Pr(>F)"[1]
})
tbl_reo[,5]  <- aov.test[[1]]$'Pr(>F)'[1]

© Stack Overflow or respective owner

Related posts about r