[R] geometric mean of probability density functions

David Winsemius dwinsemius at comcast.net
Wed Mar 18 19:33:26 CET 2009


If you make your calls to density with common lenth and interval  
parameters you should be able to get better "registration":

  ?density
# this example sums the squared differences
  x <- rnorm(200,1,1)
  x2 <- rnorm(200,1,1)
  d1 <- density(x, n=512, from=-1, to= 4)
  d2 <- density(x2, n=512, from=-1, to= 4)
  ssq <- sum( (d1$y - d2$y)^2 )
  ssq

-- 
David Winsemius

On Mar 18, 2009, at 1:54 PM, Aaron Spivak wrote:

> Hi,
> This is my first time posting to the mailing list, so if I'm doing  
> something
> wrong, just let me know.  I've taken ~1000 samples from 8 biological
> replicates, and I want to somehow combine the density functions of the
> replicates.  Currently, I can plot the density function for each  
> biological
> replicate, and I'd like to see how pool of replicates compares to a
> simulation I conducted earlier.  I can compare each replicate to the
> simulation, but there's a fair amount of variability between  
> replicates.
> I'd like to take the geometric mean of the density functions at each  
> point
> along the x-axis, but when I compute:
>
>> a<-density(A[,1][A[,1]>=0], n=2^15)
>> b<-density(A[,3][A[,3]>=0], n=2^15)
>> a$x[1]
> [1] -70.47504
>> b$x[1]
> [1] -69.28902
>
> So I can't simply compute the mean across y-values, because the x- 
> values
> don't match.  Is there a way to set the x-values to be the same for  
> multiple
> density plots?  Also, there are no negative values in the dataset,  
> so I'd
> like to bound the x-axis at 0 if at all possible?  Is there a  
> standard way
> to combine density functions?  Thanks for the advice.
> -Aaron Spivak
>
> ps. I thought about just pooling all measurements, but I don't think  
> that's
> appropriate because they are from different replicates and the  
> smoothing
> kernel depends on the variance in the sample to calculate the  
> distribution.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list