0

I'm using kruskal.test in R. The problem I'm having is that I wanted to find p-values for each categorical variable (ie. gender, separated by female and male). If I have data:

Type month ethnicity length age sex
A    1     White     20     35  F
B    3     White     35     45  F
A    2     Hispanic  40     50  M
B    2     Hispanic  43     33  M

Something like this, and if I want to calculate p-values for the each ethnicity type by Type, what should I do?

Right now the code is:

kruskal.test(length~ Type, data=df)

but I can't do

kruskal.test(sex$M~ Type, data=df)

The data is not normally distributed. I appreciate any suggestions

Joe
  • 8,073
  • 1
  • 52
  • 58
Sun
  • 157
  • 11
  • 1
    You must provide two groups to `kruskal.test`, could you try to be more specific what you are trying to test. Do you mean to do `sex=="M"` instead of `sex$M`? – emilliman5 Dec 18 '18 at 19:10
  • Yes, in the end, i want to show the p value for the mean of males in type a and b. like testing if the mean of males are different between A and B – Sun Dec 18 '18 at 19:15
  • 1
    The mean of what? – emilliman5 Dec 18 '18 at 19:29
  • 1
    Maybe `kruskal.test(length ~ Type, data = subset(df, sex == "M"))`. – Rui Barradas Dec 18 '18 at 19:42
  • Note that the outcome should be numeric for `kruskal.test()` to make sense. Also, note that it is not testing means but shifts in the distribution conditional on the shape being the same in all groups. – ekstroem Dec 18 '18 at 23:03

0 Answers0