R/myncurve.R

Defines functions myncurve

Documented in myncurve

#' myncurve
#'
#' @param mu The population mean
#' @param sigma The population standard deviation
#' @param a Right bound on area calculation
#'
#' @return A graph of the curve and an overlaid polygon representing the specified area calculation
#' @export
#'
#' @examples
#'
#' myncurve(mu=10,sigma=5, a=6)
myncurve = function(mu, sigma, a)
{
  curve(dnorm(x,mean=mu,sd=sigma), xlim = c(mu-3*sigma, mu + 3*sigma))

  #  x values corresponding to the x - cords of the points on the curve
  xcurve=seq(mu-3*sigma,a,length=2000)
  # Y values corresponding t0 the x values
  ycurve=dnorm(xcurve,mean=mu,sd=sigma)

  # Fill in the polygon with the given vertices
  polygon(c(mu-3*sigma,xcurve,a),c(0,ycurve,0),col="Red")
  # Put in the text with the appropriate area
  #Area
  prob=pnorm(mu-3*sigma,mean=mu,sd=sigma)-pnorm(a,mean=mu,sd=sigma)
  prob=round(prob,4)
  text((mu-3*sigma)/a,(dnorm(mu-3*sigma,mu,sigma)+dnorm(a,mu,sigma))/a, paste("Area = ", prob, sep=""))
}
nafryer97/MATH4753PROJ1 documentation built on Feb. 23, 2020, 7:49 a.m.