0

I have two variables I want to compare: one containing a variable on age (continuous) and one containing a variable on stroke status (did or did not have stroke, factor). I can do this happily using

wilcox.test (allcoding$age~allcoding$stroketia)

However, I struggle with doing this in sjPlot as it wants both to be numeric

sjt.mwu(mwu(allcoding$age, allcoding$stroketia))
Performing Mann-Whitney-U-Test...
---------------------------------
showing statistics between groups (x|y)
Error in wilcox.test.default(xsub, ysub.n, paired = TRUE) :
 'y' must be numeric

How do I do the equivalent of the "~" in sjPlot rather than ","?

Thanks for the help

Konrad
  • 17,740
  • 16
  • 106
  • 167
Ross M
  • 95
  • 1
  • 8
  • Could you provide sample data in your post? Also, `sjt.mwu` is to produce HTML output, I reckon that the problem is with the `mwu`; The `mwu` takes two numeric vectors. Leaving the data on side, the second question in your post is not clear to me at all. The `mwu` takes arguments `mwu(x = your numbers, grp = your groups, ...)`, the `~` is used in formula objects but why and where would you like to include it? – Konrad Apr 13 '16 at 08:57
  • Hi Konrad, thanks for your help. Its a difficult thing to give example data for unfortunately, because its esentially a xtab I want to do. Ive already done it for previous data, e.g. `sjt.xtab (allcoding$smoking, allcoding$stroketia, variableLabels = c("Smoking", "Stroke Status"), showColPerc = TRUE, tdcol.col = "black")` Ive used this to produce a chi-sq test as both variables are factors. Now instead, I want to essentially do the same thing but produce a xtab containing mean and standard deviation and the result of wilcoxon because one value is a factor and the other is continuous – Ross M Apr 13 '16 at 09:09
  • Then it would be difficult to help you. Could you just post the output from running the `mwu` without the `sjt.mwu`? It would be necessary to have a look at your variables, possibly you may be able to address the problem with use of `as.numeric` but it's not possible to say without having a look at the data. *Edit:* and all of those variables are numeric vectors? – Konrad Apr 13 '16 at 09:12
  • Using mwu I get `mwu(allcoding$age, allcoding$stroketia)` `Performing Mann-Whitney-U-Test...` `---------------------------------` `showing statistics between groups (x|y)` `Error in wilcox.test.default(xsub, ysub.n, paired = TRUE) : ` ` 'y' must be numeric` There are not all numeric no, one is numeric and the other is a factor. I can for example do wilcox.test, which gives me the desiered result, but I cant table it – Ross M Apr 13 '16 at 09:18
  • I basically want a table that looks like http://imgur.com/WDs6zjs – Ross M Apr 13 '16 at 09:21
  • Simple stuff to achieve, try with your grouping variables as *1, 0* for the groups. – Konrad Apr 13 '16 at 09:37
  • What does `str(allcoding$stroketia)` print? I suggest converting that vector into numeric. – Daniel Apr 13 '16 at 15:41
  • It's a bit strange because the grouping variable is automatically coerced to numeric if it's a factor. – Daniel Apr 13 '16 at 15:45

1 Answers1

0

I can only reproduce this error when the grouping variable is of type character.

library(sjmisc)
library(sjPlot)
a <- runif(50, 10, 30)
b <- sample(LETTERS[1:3], size = 50, replace = T)
# throws an error
mwu(a, b)

However, when you coerce to factor, it works:

mwu(a, as.factor(b))
sjt.mwu(mwu(a, as.factor(b)))

Could you try this?

Daniel
  • 7,252
  • 6
  • 26
  • 38