# Winsorizing in Mathematica and the R package DescTools yields differing results

I am currently trying to winsorize several datasets up to 1000 datapoints in R and in Mathematica for using those in regression estimations afterwards. Following the suggestion in the question http://mathematica.stackexchange.com/questions/152936/list-with-inadequate-structure-in-the-output-of-a-defined-function, I used

Clip[grate16, Quantile[grate16, {.05, .95}]]


to winsorize my data in Mathematica. Yet, if I use the Winsorize function from the package 'DescTools' in R with the code

Winsorize(grate16, probs = c(0.05, 0.95))


for exactly the same datasets, the results differ for some observations from about the 3 decimal-digit level which leads to heavily differing end results. Cursory documentation for this function can be found here. The code (in GitHub) for this function can be found here.

Since the deviations are so large for the same datasets, I do not think this is a numerical accuracy issue. I tried differing levels of precision and accuracy in Mathematica which, however, did not improve the situation. What am I missing?

• I have very little experience with R; I think that discrepancies are due to the implicit method used in R's quantile function; perhaps taking a look at how WinsorizedMean works, you can infer which method better suits your data and needs – user42582 Feb 3 '18 at 10:18
• Both Mathematica and R list the same 9 methods for estimating quantiles (Quantile in Mathematica and quantile in R). The default methods just happen to be different. So you just need to set the desired method in both to get the same results. – JimB Feb 5 '18 at 15:35
• Can you post your grate16 somewhere, so that potential answerers can experiment with it? – J. M. will be back soon Mar 18 '18 at 12:19
• @JimB Looking at the code here Winsorize does not use Quantile by the DescTools but quantile by base. – Anton Antonov Mar 18 '18 at 22:25
• @AntonAntonov Good observation. I see from the link you provided that quantile is called by Winsorize without specifying one the 9 types so the default (type=7 in R) is used. This is the "mode-based estimate" in Mathematica. So to match what R does the following should be used: Clip[grate16, Quantile[grate16, {.05, .95}, {{1, -1}, {0, 1}}]]. – JimB Mar 18 '18 at 23:07