R/myncurve.R

Defines functions myncurve

Documented in myncurve

#' Normal Density Distribution and Probability Plotter
#'
#' Plots the Density of a normal distribution and shades the area and calculates probability of X being equal to or less than 'a'
#'
#' @param mu Mean of the Normal Distribution
#' @param sigma Standard devation of the Normal Distribution
#' @param a Number X is equal to or less than, X<=a
#'
#' @return A Density Distribution Plot with Area under the code shaded and probability, P(X<=a)
#' @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))

  xcurve = seq(mu-3*sigma-10,a,length = 1000)
  ycurve = dnorm(xcurve, mean = mu, sd = sigma)

  polygon(c(mu-3*sigma-10,xcurve,a),c(0,ycurve,0),col = "pink")

  Area = pnorm(a, mean = mu, sd = sigma)-pnorm(mu-3*sigma-10, mean = mu, sd = sigma)
  Area = round(Area,4)

  text(x = mu ,y = 0.02, paste0("Area=", Area))
}
sche97/MATH4753 documentation built on April 17, 2020, 9:39 a.m.