[R] Density Estimation

Wolski wolski at molgen.mpg.de
Wed Sep 15 16:00:05 CEST 2004


The function density returns you a object of class density.
This object has an x and an y attribute which you can access by x y,

Use approx and runif.



Using the function ?approx you can compute the density value for any x.
#the x is a dummy here.
		tmp <- runif(1,min=min(dd$x),max=max(dd$x))
		lev <- approx(dd$x,dd$y,tmp)$y
		if(runif(1,c(0,1)) <= lev)

x <- 0



*********** REPLY SEPARATOR  ***********

On 9/15/2004 at 12:36 PM Brian Mac Namee wrote:

>>>Hi there,
>>>Sorry if this is a rather loing post. I have a simple list of single
>>>feature data points from which I would like to generate a probability
>>>that an unseen point comes from the same distribution. To do this I am
>>>trying to estimate the probability density of the list of points and
>>>use this to generate a probability for the new unseen points. I have
>>>managed to use the R density function to generate the density estimate
>>>but have not been able to do anything with this - i.e. generate a
>>>rpobability that a new point comes from the same distribution. Is
>>>there a function to do this, or am I way off the mark using the
>>>density function at all?
>>>Thanks in advance,
>>>R-help at stat.math.ethz.ch mailing list
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Dipl. bio-chem. Witold Eryk Wolski             @         MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin                'v'    
tel: 0049-30-83875219                        /   \       
mail: witek96 at users.sourceforge.net        ---W-W----    http://www.molgen.mpg.de/~wolski 
      wolski at molgen.mpg.de

More information about the R-help mailing list