[R] Distribution Graph Idea/Help

From: Derek Ogle <DOgle_at_northland.edu>
Date: Fri, 18 Apr 2008 18:16:37 -0500

For pedagogical reasons (i.e., moving a way from tables of distributions) I want to plot a probability density or distribution function with a shaded area corresponding to the calculated value or user input. For example, I want a plot to visually demonstrate the result of

pnorm(1.3)

I have seen the interactive examples in TeachingDemos and rPanel but am interested in using the function from the "command line" rather than from a "GUI". I have generated code to construct this type of graph, but my question is now how best to implement it. My initial solution was to add a plot=TRUE argument to pnorm() but that requires altering a base function and I now think that this is not a good idea (although it worked nicely from the student's perspective). Thus, I have considered three new options ...

  1. making a new function called something like pnorm1() which would return what pnorm() returns but also would construct the graphic. This implementation would be simple given the function that I have already made but it feels clumsy and inelegant.
  2. creating a generic plot() function that would take, for example, an object returned from pnorm(). However, this does not seem immediately possible as, it appears to me, that pnorm() just returns a numeric.
  3. creating a general function that would take the name of a distribution, type of calculation ("p" or "q" type), value of interest (x value or probability), and distribution parameters as arguments and then call the specific distribution functions and my graphing function to produce the results. I would likely implement this just for distributions that I use regularly in my classes.

Has anybody already implemented a solution to this idea? Does anyone have a suggestion on which of my three options above is best for this code? Better ideas?

Thanks in advance for any help.



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. Received on Fri 18 Apr 2008 - 23:19:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 Apr 2008 - 23:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive