I have reproducible example here
library(Hmisc)
set.seed(173)
sex <- factor(sample(c("m","f"), 500, rep=TRUE))
country <- factor(sample(c('US', 'Canada'), 500, rep=TRUE))
age <- rnorm(500, 50, 5)
sbp <- rnorm(500, 120, 12)
label(sbp) <- 'Systolic BP'
units(sbp) <- 'mmHg'
treatment <- factor(rep(c("PreTretment","PostTretment"), 250))
f <- summaryM(age + sex + sbp ~ treatment, test=TRUE)
SummaryM function from Hmisc package has test argument which as default applies Wilcoxon test to continues variable assuming they are independent. Now I would like to pass paired=TRUE
to Wilcoxon. How can I do it?
Thanks
My current effort at making a paired Wilcoxon test with Hmisc summary methods:
The summaryM method splits its grouping variables and is therefore not appropriate for paired tests. The
summary.formula
set of methods does allow a "reverse" method where the continuous variable is on the RHS of the formula:Trying to print
f
throws an error (claiming falsely that the p-value is not numeric) but you can look inside to see that the pairedwilcox.test
results were passed into the object and the are the same as if you had done them "by hand":Efforts to fix the error that gets thrown by putting in hard-coded numbers for the "df" values are failing. I have not succeeding in following the traceback which I paste in only the top of: