且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用[R]中的函数曲线绘制正态曲线?

更新时间:2023-02-18 07:47:55

您只需要在curve中将"w"参数放到dnorm:

You just need to drop the "w" argument to dnorm in curve:

w<-rnorm(1000) 
hist(w,col="red",freq=F,xlim=c(-5,5))
curve(dnorm,-5,5,add=T,col="blue")

要使用除普通单位"之外的其他内容,请提供"mean"和"sd"自变量(并且切记要同时更改histcurve的绘图限制:

To use something other than the "unit Normal" you supply "mean" and "sd" arguments (and do remember to change the plot limits for both hist and curve:

w<-rnorm(1000, mean=10, sd=2) 
hist(w, col="red", freq=F, xlim=10+c(-5,5))
curve( dnorm(x, mean=10,sd=2), 5, 15, add=T, col="blue")