[R] density(): obtaining p-values

Pfaff, Bernhard Bernhard.Pfaff at drkw.com
Mon Mar 3 12:41:03 CET 2003


Dear R-List-Member,

is there a more elegant way to obtain p-values of a vector x, whose
empirical density has been estimated with density(), than summing up the
rectangles as an approximation of the area beneath the empirical
distribution function and interpolating the values of x by using approx()?

pval.emp <- function(x)
  {
   df <- density(x,from=min(x),to=max(x),kernel="gaussian")
   width <- df$x[2]-df$x[1]
   rect <- df$y*width
   cdf.emp <- cumsum(rect)
   approx(df$x,cdf.emp,x)$y
  }

Many thks in advance,
Bernhard




----------------------------------------------------------------------
If you have received this e-mail in error or wish to read our e-mail 
disclaimer statement and monitoring policy, please refer to 
http://www.drkw.com/disc/email/ or contact the sender.
----------------------------------------------------------------------




More information about the R-help mailing list