Search code examples
rdensity-plot

sm.density.compare() plot not showing anything


I'm using sm.density.compare() function to visualize if my variable of interest helps distinguish categorical outcome variable (a variable of 13 classes) using the following code:

library(sm)
load("~/df.Rdata")
sm.density.compare(df$X, df$Y, col=rainbow(13))
But as it turned out, this density plot doesn't show anything. Did I omit some code in sm.density.compare() or simply because the X is uninformative?

enter image description here

FYI, the data can be accessed here and I referenced this thread from another forum.

Thank you.


Solution

  • In your data, only two points have df$Y ==2 and both have the same X value, so there is no good way to define the density for those points. If you leave out the Y==2 points, the plot works fine.

    SUB = which(df$Y != 2)
    sm.density.compare(df$X[SUB], df$Y[SUB])
    

    Density plot