If I use the ecdfplot()
function of the latticeExtra
package how do I get the actual values calculated i.e. the y-values which correspond to the ~x|g
input?
I've been looking at ?ecdfplot
but there's not discription to it. For the usual highlevel function ecdf()
it works with the command plot=FALSE
but this does not work for ecdfplot()
.
The reason I want to use ecdfplot()
rather than ecdf()
is that I need to calculate the ecdf()
values for a grouping variable. I know I could do this handish too but I'm quite convinced that there is a highroad too.
Here a small expample
u <- rnorm(100,0,1)
mygroup <- c(rep("group1",50),rep("group2",50))
ecdfplot(~u, groups=mygroup)
I would like to extract the y-values given each group for the corresponding x-values.
If you stick with the ecdf() function in the base package, you can simply do as follows:
Create ecdf function with your data:
Now use this "ecdf function" to generate the cumulative probabilities of any vector you feed it, including your original, sorted data:
I know you said you don't want to use
ecdf
, but in this case it is much easier to use it than to get the data out of the trellis object thatecdfplot
returns. (After all, that's all thatecdfplot
is doing- it's just doing it behind the scenes).In the case of your example, the following will get you a matrix of the y values (where
x
is your entire inputu
, though you could choose a different one) for each ECDF:ETA: If you just want each column to correspond to the 50 x-values in that column, you could do:
(Note that if the number of values in each group aren't identical, this will end up as a list rather than a matrix with columns).