Closed ChristelSwift closed 2 years ago
The code is in https://github.com/kaz-yos/tableone/blob/master/R/modules-smd.R
The implementation is based on Yang and Dalton. You may be right about this could be ordering sensitive.
i did see the code but found it hard to follow... also there is a section with a double for loop, with the comment "room for improvement". I'm wondering if it wouldn't be faster using a matrix multiplication approach as described above instead of a double for loop?
If I remember correctly the technical paper has an error in the off-diagonal part: https://github.com/kaz-yos/tableone/blob/master/R/modules-smd.R#L28
ha yes!! that's what it was. Now i'm matching the tableOne result. Thank you! Also, with this correction, i get the same result whichever level of the multinomial i drop which is reassuring :)
hi there, i'm trying to understand how the reported SMD is calculated in the case of a multinomial variable.
The only detailed example i could find is here: http://support.sas.com/resources/papers/proceedings12/335-2012.pdf
It uses a Mahalanobis distance method so if we have a variable with k levels, and a treated vs control group, then:
where C and T are the vectors of proportions for the levels 2:k for control and for treated, and S is a (k-1) covariance matrix, where each element is calculated in this way:
so it seems to suggest we should remove the first level of the variable, but then wouldn't the result be different if we removed a different level?
The calculations can be done in matrix form using the probability vectors for the treated / control groups, so to illustrate the point, let's consider the
lalonde
dataset:=> using tableOne we get an SMD of 1.7 on race which has 3 levels.
If i implement the solution given in the SAS paper:
This gives a smd of 1.45 which is different from the tableOne result. Also, the result changes depending on the level that is dropped. So i also tried not dropping any level, but this time i got a result of 4.03:
which again is different from the result given by tableOne...
Would you be able to explain what formula is implemented in tableOne?
many thanks!