Visual comparison of distribution between groups: how is the scale changed for "asymmetric beanplots"?

Recently I came across an R-package beanplot and offered the opportunity to build a distribution of two subgroups in one separate plot (special asymmetric beanplot). You will find the package description in the Journal of Statistical Software and cran.r-project.org .

I created an asymmetric beanplot using the following CODE :

library(psych) library(beanplot) var1 <-c(20,33,NA,39,NA,40,34,33,NA,38,NA,8,7,NA,NA,40,34,24,25,36,40,37,34,NA,35) var2 <- c(1,0,1,1,1,0,1,0,1,NA,1,0,0,0,0,1,1,0,1,0,1,1,NA,0,1) mydata<-data.frame(var1,var2) table(mydata) par(lend = 1, mai = c(0.8, 0.8, 0.5, 0.5)) beanplot(var1 ~ var2, data= mydata, side = "both",log="", what=c(1,1,1,0), border = NA, col = list("black", c("grey", "white"))) legend("bottomleft", fill =c("black", "grey"), legend = c("no", "yes")) 

The plot produced shows well the different form of distribution of the two subgroups.

Asymmetric beanplot

PROBLEM

The dependent variable is measured on a scale of 7 to 40. However, the y axis, apparently, goes from -1 to +55.

It would be great if someone could explain how the scale changes, i.e. what is actually depicted here. Is there a way to build a distribution using the original scale?

Thank you very much!

+4
source share
1 answer

beanplot uses density . Estimated density can give mass to areas outside the range of observed data. You can try this to understand what density does - plot(density(1:2)) , and you should see that it just takes the average value of the Gaussian density concentrated in the data points (note that you can use a different core , since beanplot allows you to specify a kernel parameter). How he chooses the deviation for this Gauss is up to you, but by default it looks like this: beanplot uses bw.SJ with the "dpi" method to select the bandwidth.

You can use cutmin and cutmax to control the range that the beanplot actually displays, but that does not actually change the density estimate.

+4
source

All Articles