Closed bogie closed 4 years ago
Just at a quick glance, the formulas are backwards for table layout than how they would go into a model function. The problem is that one has a choice between the following having
Rows ~ Cols or Cols ~ Rows
If one choses Rows ~ Cols, then it corresponds to R formula order for Dependent ~ Independent for statistical functions. But then the formula going into the table looks like y1 + y2 + ... yn ~ x.
If one choses Cols ~ Rows, then it is backwards to the normal R formula order, Independent ~ Dependent, but the formula says x ~ y1 + y2 + ... yn. Which seems more natural for specifying a table, however the text in each from is yi ~ x as you noticed.
It's been published for sometime with this choice, it would be a breaking change for users if I were to flip at this point.
So you are saying this is the expected output/formula?
tangram(Age ~ Group_DM2_Pre, Patients, test=TRUE)
===============================================================
N Age [years] Test Statistic
(N=132)
---------------------------------------------------------------
Group_DM2_Pre F_{2,115}=2.77, P=0.07^1
Non-Diabetic 49 57 *65* 74
Pre-Diabetic 55 58.7 *65.0* 76.0
Diabetic 56 60.0 *72.5* 81.2
===============================================================
N is the number of non-missing value. ^1 Kruskal-Wallis. ^2 Pearson. ^3 Wilcoxon.
The example suggests that this is not at all what would be the expected formula and format.
All I am saying is that the spearman2 function appears to receive the wrong values and this is exclusive to the summarize_kruskal_HORZ method, as the _vert method does not put c() around datar and datac and delivers the expected result and statistics. removing c() yields the appropriate result.
Please help me understand what the proper approach would be, as to my understanding using a wilcoxon test in a three sample data set would be wrong as you would need to do a kruskal-wallis test, right?
I was in hurry before and misread what you were saying. I've confirmed that Hmisc returns the behavior you describe, and the horz is wrong. The commit that changed this was fe7a9c91adf5c3ce9d3dd3af350f29ecf14f57b5. I remember now, there was a very huge file with a lot of data and spearman2 was very slow in performance without this change, but it was because someone passed in labelled integers and this was stripping the label. The problem is now, this is impacting factors. I don't know why labels made it slower, but I'm going to revert this change.
@bogie I'm always open to providing more transforms with different statistical goals. If your dissertation leads to some useful transforms, I would love to include them.
Tangram version: 0.7.1
I have the following dataframe:
Which yields the following table:
Patients %>% tangram(x=Group_DM2_Pre ~ Age, test=TRUE)
As you can see it has a degree of freedom of 1 and parses that as a Wilcoxon test, replicating the
spearman2()
function I notice the following:it uses the second formula(thus df=1) for approximating the K-W statistic(or in this case wilcoxon), however if I understand the concept behind spearman2 correctly it should use the first formula instead. With three groups in Group_DM2_Pre the df should be df=k-1=3-1=2 right?
Doing the K-W test manually I get the following result:
Which is what I would expect and is also in line with the spearman2 approximation from the first formula.
Using
tangram(Age ~ Group_DM2_Pre, Patients, test=TRUE)
I get the expected p-values but obviously a completely different layout:Help would be greatly appreciated, since I would really like to use tangram for my doctoral thesis.
Modifying
summarize_kruskal_horz
and removing the "c()" around datac and datar this way:yields the expected results:
publication() holds a near copy-paste of the lancet style and hmisc functions while solely overwriting summarize_kruskal_horz
is this a known bug or am I misunderstanding the whole process? :D