Peatherfed
Peatherfed

Reputation: 210

How to plot the Standard Normal CDF in R?

As the title says, I'm trying to plot the CDF of a N(0,1) distribution between some values a, b. I.e. Phi_0,1 (a) to Phi_0,1 (b). For some reason I'm having issues finding information on how to do this.

Upvotes: 1

Views: 5391

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 146174

You can use curve to do the plotting, pnorm is the normal probability (CDF) function:

curve(pnorm, from = -5, to = 2)

enter image description here

Adjust the from and to values as needed. Use dnorm if you want the density function (PDF) instead of the CDF. See the ?curve help page for a few additional arguments.

Or using ggplot2

library(ggplot2)
ggplot(data.frame(x = c(-5, 2)), aes(x = x)) +
  stat_function(fun = pnorm)

enter image description here

Generally, you can generate data and use most any plot function capable of drawing lines in a coordinate system.

x = seq(from = -5, to = 2, length.out = 1000)
y = pnorm(x)

Upvotes: 2

Related Questions