I am using the "sm" package for studying distributions in my datasets. For those curious I am looking at recruitment practices as a function of age and trying to identify if the age distribution change for groups change due to attributes such as gender or education.
The SM package is a new experience for me and I am trying to find a function describing the most likely density function generating the dataset provided that the null hypotheis is true (that both density plots are generated by random samples taken from the same distribution). I do not have the reputation necessary to post images but I found this one on Imgur that also is generated with sm.density.compare.
What we see in the image is two kernel density plots and a teal area that I understand to be the reference band containing the 95 % likelihood of containing the true density plot provided that the two lines have been generated by data coming from the same distribution.
What I would like to find out is a way to calculate a vector going through the most likely point within the reference band for each value on the x-axis. As per the rules I am of course open to suggestions that I am either crazy or should use another package.
Apparently there is some bug in either Rstudio or R that prevented me from solving the problem in the most obvious way. As everything else in R sm.density.compare generates an object but for me it failed when I tried to save it.
The problem automagically went away when I first plotted the object (default behaviour when sm.density.compare is executed) and then did the same thing but also creating a new object.
So:
sm.density.compare(a, b, model="equal", xlab=Year of Birth")
DensityObject = sm.density.compare(a, b, model="equal", xlab=Year of Birth")
And then the actual line can be calculated by:
DensityObject$average = rowMeans(cbind(DensityObject$upper, DensityObject$lower), na.rm=TRUE)