[R] density plot of simulated exponential distributed data

Greg Snow Greg.Snow at imail.org
Wed Apr 27 19:54:52 CEST 2011


You might want to use the logspline package instead of the density function, it allows you to specify bounds on a distribution.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Juanjuan Chai
> Sent: Tuesday, April 26, 2011 4:19 PM
> To: r-help at r-project.org
> Subject: [R] density plot of simulated exponential distributed data
> 
> Hi all,
> 
> I tried to plot the density curve using the data from simulation. I am
> sure that the data should be exponentially distributed, but the plot
> of density curve always starts from (0,0) which is not the case for
> exponential distribution. Is there any way around this, to keep the
> curve dropping at 0?
> 
> Thanks.
> 
> The following are the codes I tested:
> 
> data <- vector()
> rate <- 3
> i <- 1
> for(i in 1:1000){
> 	r <- runif(1)
> 	data[i] <- log(1-r)/(-rate)
> 	i <- i+1
> }
> plot(density(data))
> 
> -JJ
> 
> ______________________________________________
> 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.



More information about the R-help mailing list