![]() ![]() ![]() The syntax of qnorm is as follows: qnorm(p, # Integer or vector of probabilities Hence, the qnorm function is the inverse of the pnorm function. The qnorm function allows you to find the quantile (percentile) Q for any probability p. Plot(x, pnorm(x, mean = 1, sd = 1), type = "l", Lines(x, pnorm(x, mean = 3, sd = 1), col = "blue", lty = 1, lwd = 2) Plot(x, pnorm(x, mean = 0, sd = 1), type = "l", With the pnorm function you can also plot the cumulative density function of the Gaussian or Normal distribution in R: par(mfrow = c(1, 2)) Plot normal cumulative distribution function in R Plot(x, dnorm(x, mean = 1, sd = 1), type = "l", # Same mean, different standard deviation Title = expression(paste(mu, " ", sigma)), Lines(x, dnorm(x, mean = 3, sd = 1), col = "blue", lty = 1, lwd = 2) Plot(x, dnorm(x, mean = 0, sd = 1), type = "l", # Same standard deviation, different mean In the following example we show how to plot normal distributions for different means and variances. You just need to create a grid for the X-axis for the first argument of the plot function and pass as input of the second the dnorm function for the corresponding grid. In the following example, the value of even elements are from \mu = 1, \sigma = 3 and odds are from \mu = 2, \sigma = 4. You can also specify vectors to the mean and sd arguments of the function. In order to calculate it, you could type: x <-4:4 Log = FALSE) # If TRUE, probabilities are given as logĬonsider, for instance, that you want to obtain the PDF for x \in (-4, 4), with mean 1 and standard deviation of 3. Sd = 1, # Integer or vector representing the standard deviation/s Mean = 0, # Integer or vector representing the mean/s In R, you can make use of the dnorm function to calculate the density function with mean \mu and standard deviation \sigma for any value of x, \mu and \sigma. Quantile function of the Normal distribution ![]() Normal distribution (Cumulative Distribution Function) Normal density (Probability Density Function) The following table summarizes the functions related to the normal distribution: Function In addition, the rnorm function allows obtaining random observations that follow a normal distibution. In R there exist the dnorm, pnorm and qnorm functions, which allows calculating the normal density, distribution and quantile function for a set of values. ![]()
0 Comments
Leave a Reply. |