简体   繁体   English

如何在 R 中绘制标准正态 CDF?

[英]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.正如标题所说,我试图绘制一些值 a、b 之间的 N(0,1) 分布的 CDF。 Ie Phi_0,1 (a) to Phi_0,1 (b).即 Phi_0,1 (a) 到 Phi_0,1 (b)。 For some reason I'm having issues finding information on how to do this.出于某种原因,我在查找有关如何执行此操作的信息时遇到问题。

You can use curve to do the plotting, pnorm is the normal probability (CDF) function:您可以使用curve进行绘图, pnorm是正态概率 (CDF) 函数:

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

在此处输入图片说明

Adjust the from and to values as needed.根据需要调整fromto值。 Use dnorm if you want the density function (PDF) instead of the CDF.如果您想要密度函数 (PDF) 而不是 CDF,请使用dnorm See the ?curve help page for a few additional arguments.有关其他一些参数,请参阅?curve帮助页面。

Or using ggplot2或者使用ggplot2

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

在此处输入图片说明

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM