2

I am going to winsorize my dataset to get rid of some outliers with the package robustHD. It is the first time I ran into this error. The dataset contains 50+ variables and 100+ observations.

How can I fix this? And why matrix singularity matters for a calculation like winsorize? Thanks.

df_win<-winsorize(df,prob=0.95)
Error in solve.default(R) : system is computationally singular: reciprocal condition number = 1.26103e-18
lsl__
  • 75
  • 3
  • 12
  • 1
    Hi, welcome to StackOverflow. It would be really helpful if the example was reproducible. Could you provide a minimal dataset that replicates this error? Could you also note from which package you got the `winsorize` function? Multiple packages provide one. – slamballais Apr 04 '16 at 13:17
  • @Laterow Thanks! I used the package 'robustHD'. Sorry I can't upload the data since it's related to work... – lsl__ Apr 04 '16 at 15:24

1 Answers1

2

The reason for this is that winsorize in robustHD uses solve. If you look deeper into the code, winsorize on a data frame calls the winsorize.data.frame method, which is simply a script that runs as.matrix and then uses the winsorize.matrix method. This in turns does a bunch of things, but the problem here is that it uses the solve function.

The error you get is from solve. The error probably occurs because you included some variables/columns that are very highly correlated, or rather, they are linear combinations of each other. You may want to check if you have duplicated variables or variables that are transformations of each other.

There are several things you can do:

  1. Remove one of the highly correlated variables and try again.
  2. Check out a different package to use winsorize from.
  3. Write your own winsorize function.

The quickest way to do the second step:

require(sos)
findFn("winsorize")

This will produce an overview of all functions that have the word "winsorize" in their description. Just look for functions that are described to be used for winsorization.

slamballais
  • 3,161
  • 3
  • 18
  • 29