I'm very new to the world of R
. I have the following test data:
A<-tibble(parasite=sample(0:1,10,rep=TRUE),L1=sample(0:1,10,rep=TRUE),
L2=sample(0:1,10,rep=TRUE),L3=sample(0:1,10,rep=TRUE),
L4=sample(0:1,10,rep=TRUE))
Looks like:
parasite L1 L2 L3 L4
1 0 0 1 0 0
2 1 0 1 1 1
3 1 1 1 0 1
4 0 1 1 1 0
5 1 1 1 1 0
...10 rows total
What I want to do is to run 4 chisq tests:
1.parasite vs L1
2.parasite vs L2
3.parasite vs L3
4.parasite vs L4
I want to then produce a summary tibble that lists the Y component of each table (L1,L2...), chisq values, and pvalues (rounded to a reasonable extent) of the tests. Like:
variable chisq pvalue
L1 1.475 0.0892
L2 18.453 0.0000E8
L3 2.4781 0.0012
L4 0.6785 0.2755
I've seen the use of map
to do something similar but I can't get it to work, but since I'm learning, any concise method of doing this would be greatly appreciated.
e.g.
map(~chisq.test(.x, data$column)) %>%
tibble(names = names(.), data = .) %>%
mutate(stats = map(data, tidy))
unnest(data,stats)
Can anyone show me how to do this?
Thanks!