0

I have this solution which allows me to look at values of my type column individually in a fisher test. (can also swap out fisher for chisq.test)

But i tried to apply this to an anova test and had errors.

This is my original version


# fisher test status on types individually 
fish = lapply(unique(df$type),function(i){
  ctest = fisher.test(table(df$type == i, df$status))
  data.frame(type = i, pvalue = ctest$p.value)
})

And i get this output which is my same desired output for an anova test

type        pvalue

warning     7.94658438e-23
noncontact  5.84265922e-01
issue       4.18245681e-04
success     1.67653259e-09

This is an attempt I tried for anova test but got this error

anov = lapply(unique(df$numtype),function(i){
  atest = aov(table(df$numtype == i ~ df$status))
  data.frame(numtype = i, pvalue = atest$p.value)
})


Error: unique() applies to only vectors

And I am using a dataframe, which i didn't think would be a problem.

My columns used are like this (numeric columns only intended for anova ofcourse)

afluence type numtype status
1 noncontact 1 positive
2 warning 2 declined
3 issue 3 positive
4 success 4 positive
5 success 1 NA
6 success 5 positive

Does anyone know how to make this work for an anova test?

1 Answers1

1

Do you need this?

lapply(split(df, df$numtype),function(x){
  atest = aov(numtype~status, x)
  data.frame(numtype = x$numtype[1], pvalue = atest$p.value)
}) -> result

result
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thanks a lot but I get an error :/ "'Error in data.frame(numtype = x$numtype[1], pvalue = atest$p.value': Arguments imply differing number of rows: 1,0" – i_love_whiteboards Apr 01 '21 at 16:30
  • @i_love_whiteboards Can you provide data in a reproducible format so that I can test my code against the data. Edit your post by including output of `dput(df)`. – Ronak Shah Apr 02 '21 at 01:31