[R] Normal Curve

Nutter, Benjamin NutterB at ccf.org
Tue Dec 30 14:17:18 CET 2008


Abou,

I presume this may be a task you will need to perform with some
regularity.  I took the liberty of turning Duncan Murdoch's suggested
code into a function for you (I hope you don't mind, Duncan).  Good
luck.

On a personal note, it's good to see a familiar name.  I hope all is
well with you.  Tell everyone at USM I said hello and happy New Year.

Benjamin Nutter

#*** fill.normal function plots a Normal Distribution Curve and shades
the
#*** region between two limits.


fill.normal <- function(lower, upper, m=0, sd=1, sd.to.show=3, ... ){
 #*** Error checks.  If both lower and upper are missing, stop the
function
  if(missing(lower) && missing(upper))
    stop("At least on of 'lower' or 'upper' must be specified")

 #*** If lower is missing, set shading to extend below the range of the
graph
  if(missing(lower) && !missing(upper))
    lower <- m - sd * (sd.to.show + 1)

 #*** If upper is missing, set shading to extend above the range of the
graph
  if(!missing(lower) && missing(upper))
    upper <- m + sd * (sd.to.show + 1)

 #*** Plot the Normal Curve
  x <- seq(m - sd * sd.to.show, m + sd * sd.to.show, by=.01)
  plot(x, dnorm(x, mean=m, sd=sd), type="l", ...)

 #*** Shade the area between lower and upper
  x <- seq(lower, upper, by=.01)
  y <- dnorm(x, mean=m, sd=sd)
  polygon(c(x, x[length(x)], x[1]), c(y, 0, 0), col="gray")
}



#*** To get the example given by Duncan Murdoch
> fill.normal(lower=90, upper=110, m=100, sd=15, sd.to.print=2)

#*** To shade between -1 and 1 on the Standard Normal Curve
> fill.normal(lower=-1, upper=1)

#*** To shade above 1.5 on the Standard Normal Curve
> fill.normal(lower=1.5)

#* Arguments
#* lower:      the lower limit of the shaded region.  If this is left
missing,
#*             shading will extend below the range of the plot.
#* upper:      the upper limit of the shaded region.  If this is left
missing, 
#*             shading will extend avove the range of the plot.
#* m:          Mean of the Normal Distribution to be plotted.  
#*             Defaults to zero.
#* sd:         Standard Deviation of the Normal Distribution to be
plotted.  
#*             Defaults to 1.
#* sd.to.show: The number of standard deviations to be visible on the
plot.
#*             Defaults to 3.  For example, if the Standard Normal 
#*             Distribution is to be plotted, under default conditions,
the
#*             plot will extend from -3 to 3.

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of AbouEl-Makarim Aboueissa
Sent: Monday, December 29, 2008 4:26 PM
To: Roland Rau; wwwhsd at gmail.com; tuechler at gmx.at; S.Ellison at lgc.co.uk;
pgoikoetxea at neiker.net; Patrick Burns; r-help at r-project.org;
Megan.Davies at snh.gov.uk; r-help at stat.math.ethz.ch;
r-help-request at stat.math.ethz.ch;
Charles.Annis at StatisticalEngineering.com; jrkrideau at yahoo.ca
Subject: [R] Normal Curve

Dear ALL:
 
How I show the area under the normal curve for example for the following
example:
 
Assume X has N(100,15). How to show the area corresponding to the
probability:
 
 
P(90<X<110)
 
 
With many thanks
 
Abou
 
 
 
==========================
AbouEl-Makarim Aboueissa, Ph.D.
Assistant Professor of Statistics
Department of Mathematics & Statistics
University of Southern Maine
96 Falmouth Street
P.O. Box 9300
Portland, ME 04104-9300
 

Tel: (207) 228-8389
Fax: (207) 780-5607
Email: aaboueissa at usm.maine.edu 
          aboueiss at yahoo.com
 
  http://www.usm.maine.edu/~aaboueissa/ 

 
Office: 301C Payson Smith
 

	[[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.



P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}



More information about the R-help mailing list