[R] Constrain density to 0 at 0?

Greg Snow Greg.Snow at imail.org
Sat Jul 24 20:55:18 CEST 2010


Look at the logspline package.  This is a different approach to density estimation from the kernel densities used by 'density', but does allow you to set fixed boundaries.

-- 
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 Farley, Robert
> Sent: Monday, July 19, 2010 7:57 PM
> To: r-help at r-project.org
> Subject: [R] Constrain density to 0 at 0?
> 
> I'm plotting some trip length frequencies using the following code:
> 
> plot( density(zTestData$Distance, weights=zTestData$Actual),
>     xlim=c(0,10),
>     main="Test TLFD",
>     xlab="Distance",
>    col=6  )
> lines(density(zTestData$Distance, weights=zTestData$FlatWeight), col=2)
> lines(density(zTestData$Distance, weights=zTestData$BrdWeight ), col=3)
> 
> which works fine except the distances are all positive, but the
> densities don't drop to 0 until around -2 or -3.
> 
> Is there a way for me to "force" the density plot to 0 at 0?
> 
> 
> 
> Thanks
> 
> 
> 
> Robert Farley
> Metro
> 1 Gateway Plaza
> Mail Stop 99-23-7
> Los Angeles, CA 90012-2952
> Voice: (213)922-2532
> Fax:    (213)922-2868
> www.Metro.net
> 
> 
> 
> 	[[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.



More information about the R-help mailing list