Search code examples
rpsych

Winsor returns function


The below is an extract of a zoo object which I am trying to winsorize using winsor from psych package:

x <- structure(c(0.0400337546529555, -0.0320371743076633, 0.0106006766976862, 
-0.011406282992093, -0.018676165248018, 0.0275956214868875, 0.00473575019758404, 
0.0986083620222542, 0.00615420656427005, 0.00709069372334476), .Names = c("1984-01", 
"1984-02", "1984-03", "1984-04", "1984-05", "1984-06", "1984-07", 
"1984-08", "1984-09", "1984-10"), index = structure(c(5113, 5144, 
5173, 5204, 5234, 5265, 5295, 5326, 5357, 5387), class = "Date"), class = c("zooreg", 
"zoo"), frequency = 1)

I use:

winsor(x, trim=0.1)

I get the following:

function () 
.Last.value
<environment: namespace:gdata>

I tried the function with the following data which has the same class (i.e. zoo and zooreg):

a <- structure(c(1, 2, 3), .Dim = c(3L, 1L), .Dimnames = list(NULL, 
        "a"), index = structure(c(5113, 5144, 5173), class = "Date"), frequency = 1, class = c("zooreg", 
    "zoo"))

It worked fine with a but not sure why it returns the above for that specific type of data x.


Solution

  • x in winsor must be vector, matrix or data.frame. Does not support zoo objects. Convert/extract your data first, e.g.:

    winsor(coredata(x), trim=0.1)
    

    gives

    > winsor(coredata(x), trim=0.1)
         1984-01      1984-02      1984-03      1984-04      1984-05      1984-06 
     0.040033755 -0.020012266  0.010600677 -0.011406283 -0.018676165  0.027595621 
         1984-07      1984-08      1984-09      1984-10 
     0.004735750  0.045891215  0.006154207  0.007090694
    

    Update

    the x in OP question is missing dimenstion, adding dim(x)=c(10,1) makes it work:

    > dim(x)=c(10,1)
    > winsor(x)
                          X
    1984-01-01  0.030083248
    1984-02-01 -0.012860259
    1984-03-01  0.010600677
    1984-04-01 -0.011406283
    1984-05-01 -0.012860259
    1984-06-01  0.027595621
    1984-07-01  0.004735750
    1984-08-01  0.030083248
    1984-09-01  0.006154207
    1984-10-01  0.007090694