#' Graphs and calculates the lower tail probability of a in a normal distribution.
#'
#' @param a The number for which the probability of the lower tail will be found
#' @param mu The mean of the normal distribution
#' @param sigma The standard deviation of the normal distribution
#'
#' @return Lower tail probability of a. Prints graph visualizing the lower tail.
#' @export
#'
#' @examples
#' myncurve(0) -> 0.5
myncurve = function(a, mu=0, sigma=1){
## This is a code snippet taken from my Lab 6 Task 2 implementation and altered.
#Define constants
lowlim = mu-3*sigma
upplim = mu+3*sigma
#Plot base curve
curve(dnorm(x, mean=mu,sd=sigma),xlim=c(lowlim, upplim))
#Add polygon section of area.
xcurve=seq(lowlim,a,length=1000)
ycurve=dnorm(xcurve,mean=mu,sd=sigma)
polygon(c(lowlim,xcurve,a),c(0,ycurve,0),col="Red")
#Return accurate calculation of probability
pnorm(a,mu,sigma)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.