Re: [R] question on graphs and finding area under a curve
Also see function rocdemo.sca in the ROC package. The area under the 45 degree line in an ROC curve has an area of 0.5. Regards, Adai On Tue, 2005-08-02 at 09:24 -0400, Ravi Varadhan wrote: Hi, To find the area lying between the curve y = y(x) and 45 degree line (which, assuming it goes through the origin, is y = x), you can use the following function based on trapezoidal rule: trap.rule - function(x,f) {sum(diff(x)*(f[-1]+f[-length(f)]))/2} trap.rule(x,f=y-x) This area will be negative if y(x) is below the 45 degree line. However, your question is not complete, I think. You need to specify the interval of integration. For this you may need to determine the points of intersection of the two curves, which involves the solution of a fixed point problem. Hope this helps, Ravi. -Original Message- From: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] On Behalf Of Renuka Sane Sent: Tuesday, August 02, 2005 8:51 AM To: r-help@stat.math.ethz.ch Subject: [R] question on graphs and finding area under a curve Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) - - there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? Thanks, Renuka -- Renuka Sane http://www.nyx.net/~rsane [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting- guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] question on graphs and finding area under a curve
On Tue, 2005-08-02 at 18:20 +0530, Renuka Sane wrote: Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? See ?par and take note of the 'xaxs' and 'yaxs' parameters. By default, these are set to 'r', where the axes are extended by 4% in each direction. Thus, set one or both parameters to 'i' to set the axes to exactly the ranges of xlim and/or ylim as you require. Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? See Frank Harrell's somers2() function in the Hmisc package on CRAN. Among other things, it outputs a value C, which is the AUC. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] question on graphs and finding area under a curve
Le 02.08.2005 14:50, Renuka Sane a écrit : Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? Hi, integrate.xy in sfsmisc package might help you. Romain Thanks, Renuka - visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] question on graphs and finding area under a curve
How about: trapz = function(x, y) { # computes the integral of y with respect to x using trapezoidal integration. idx = 2:length(x) return (as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1])) / 2) } Jarek \=== Jarek Tuszynski, PhD. o / \ Science Applications International Corporation \__,| (703) 676-4192 \ [EMAIL PROTECTED] `\ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Renuka Sane Sent: Tuesday, August 02, 2005 8:51 AM To: r-help@stat.math.ethz.ch Subject: [R] question on graphs and finding area under a curve Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) -- there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? Thanks, Renuka -- Renuka Sane http://www.nyx.net/~rsane [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] question on graphs and finding area under a curve
Hi, To find the area lying between the curve y = y(x) and 45 degree line (which, assuming it goes through the origin, is y = x), you can use the following function based on trapezoidal rule: trap.rule - function(x,f) {sum(diff(x)*(f[-1]+f[-length(f)]))/2} trap.rule(x,f=y-x) This area will be negative if y(x) is below the 45 degree line. However, your question is not complete, I think. You need to specify the interval of integration. For this you may need to determine the points of intersection of the two curves, which involves the solution of a fixed point problem. Hope this helps, Ravi. -Original Message- From: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] On Behalf Of Renuka Sane Sent: Tuesday, August 02, 2005 8:51 AM To: r-help@stat.math.ethz.ch Subject: [R] question on graphs and finding area under a curve Question on graphs: The default case for drawing a graph in R, is where a little space is left on the x and y axis before the first tick i.e. even if I say xlim=c(0,1) - - there will be some space between the edge of the x-axis and where 0 is placed. If I want 0 on the edge, how do I do it in R? Area under the curve: I have a 45 degree line and a curve above or below it. Is there a way in R to find the area between the two? Thanks, Renuka -- Renuka Sane http://www.nyx.net/~rsane [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting- guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html