# Re: [R] Random number from density()

From: Greg Snow <Greg.Snow_at_intermountainmail.org>
Date: Mon 02 Apr 2007 - 19:59:31 GMT

One approach (there are probably many others), is to use the logspline package and use logspline densitiy estimation rather than kernel density estimation (the density function). You can then use the rlogspline function to generate random values from the density estimate. The logspline approach also has the advantage that you can tell it where the ends of the chromosome are and it will not put any positive probability on observations off the chromosome.

Hope this helps,

```--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow@intermountainmail.org
(801) 408-8111

> -----Original Message-----

> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Arianne ALBERT
> Sent: Monday, April 02, 2007 8:31 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Random number from density()
>
> Hello,
>
> I'm writing some genetic simulations in R where I would like
> to place genes along a chromosome proportional to the density
> of markers in a given region. For example, a chromosome can
> be presented as a list of marker locations:
>
> Chr1<-c(0, 6.5, 17.5, 26.2, 30.5, 36.4, 44.8, 45.7, 47.8,
> 48.7, 49.2, 50.9, 52.9, 54.5, 56.5, 58.9, 61.2, 64.1)
>
> Where the numbers refer to the locations of markers along the
> chromosome. As you can see, there are a lot of markers around
> 50, but they are less dense elsewhere. I would like to take
> this information to randomly select a location on the
> chromosome to put a gene, where we are more likely to pick a
> location with high marker density (instead of using a uniform
> distribution between 0 and 64.1).
>
> So far I've used density(Chr1) to generate the probability
> density, but can this also be used to generate a random
> number? All the help I can find suggests getting the quantile
> function (the reciprocal of the integral of the pdf),
> however, it doesn't seem as though density() returns a pdf
> that can be manipulated in this way. Any suggestions?
>
>
> Arianne
>
> --
> passerelle antivirus du campus CNRS de Montpellier
> --
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help