[R] length of a density curve (or any curve)
Hello R users, When I type d - density(MyData$x) I obtain a density object I can plot, But I wonder if there is a way to easily compute the length of the density curve ? ( I imagine I could compute the distances between the 512 equally spaced points using their x and y, but does it exist a smarter way ?) Regards, SW __ R-help@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.
Re: [R] length of a density curve (or any curve)
hi Sylvain, did you try ?density regards milton On Fri, Dec 4, 2009 at 7:19 AM, sylvain willart sylvain.will...@gmail.comwrote: Hello R users, When I type d - density(MyData$x) I obtain a density object I can plot, But I wonder if there is a way to easily compute the length of the density curve ? ( I imagine I could compute the distances between the 512 equally spaced points using their x and y, but does it exist a smarter way ?) Regards, SW __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] length of a density curve (or any curve)
Yes, sure (and I just did it again) but I can't see an answer... did I miss sthg ? regards, SW 2009/12/4 milton ruser milton.ru...@gmail.com: hi Sylvain, did you try ?density regards milton On Fri, Dec 4, 2009 at 7:19 AM, sylvain willart sylvain.will...@gmail.com wrote: Hello R users, When I type d - density(MyData$x) I obtain a density object I can plot, But I wonder if there is a way to easily compute the length of the density curve ? ( I imagine I could compute the distances between the 512 equally spaced points using their x and y, but does it exist a smarter way ?) Regards, SW __ R-help@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. __ R-help@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.
Re: [R] length of a density curve (or any curve)
True enough -- ?density does not address the issue of computing the length pf the curve! One simple way of implementing the idea you first thought of would be on the following lines: d - density(MyData$x) sum(sqrt(diff(d$x)^2 + diff(d$y)^2)) which simply sums the lengths of the line-segments. You would get a better approximation to the ideal length by increasing the value of 'n' in the call to density() (perhaps as a separate calculation, since a relatively small value of 'n' is likely to be adeqaute for plotting, but possibly inadequate for the accurate computation of the length). Hpoing this helps, Ted. On 04-Dec-09 12:41:22, sylvain willart wrote: Yes, sure (and I just did it again) but I can't see an answer... did I miss sthg ? regards, SW 2009/12/4 milton ruser milton.ru...@gmail.com: hi Sylvain, did you try ?density regards milton On Fri, Dec 4, 2009 at 7:19 AM, sylvain willart sylvain.will...@gmail.com wrote: Hello R users, When I type d - density(MyData$x) I obtain a density object I can plot, But I wonder if there is a way to easily compute the length of the density curve ? ( I imagine I could compute the distances between the 512 equally spaced points using their x and y, but does it exist a smarter way ?) Regards, SW __ R-help@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. __ R-help@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. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 04-Dec-09 Time: 13:02:27 -- XFMail -- __ R-help@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.
Re: [R] length of a density curve (or any curve)
Thanks for your answer, @Dennis Murphy: no, I don't know the functionnal form, this is purely empirical data @ Ted Harding: Thank you for your lines of code, they are actually a pretty smart way... SW 2009/12/4 Ted Harding ted.hard...@manchester.ac.uk: True enough -- ?density does not address the issue of computing the length pf the curve! One simple way of implementing the idea you first thought of would be on the following lines: d - density(MyData$x) sum(sqrt(diff(d$x)^2 + diff(d$y)^2)) which simply sums the lengths of the line-segments. You would get a better approximation to the ideal length by increasing the value of 'n' in the call to density() (perhaps as a separate calculation, since a relatively small value of 'n' is likely to be adeqaute for plotting, but possibly inadequate for the accurate computation of the length). Hpoing this helps, Ted. On 04-Dec-09 12:41:22, sylvain willart wrote: Yes, sure (and I just did it again) but I can't see an answer... did I miss sthg ? regards, SW 2009/12/4 milton ruser milton.ru...@gmail.com: hi Sylvain, did you try ?density regards milton On Fri, Dec 4, 2009 at 7:19 AM, sylvain willart sylvain.will...@gmail.com wrote: Hello R users, When I type d - density(MyData$x) I obtain a density object I can plot, But I wonder if there is a way to easily compute the length of the density curve ? ( I imagine I could compute the distances between the 512 equally spaced points using their x and y, but does it exist a smarter way ?) Regards, SW __ R-help@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. __ R-help@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. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 04-Dec-09 Time: 13:02:27 -- XFMail -- __ R-help@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.