簡體   English   中英

如何使用[R]中的函數曲線繪制正態曲線?

[英]How to use the function curve in [R] to graph a normal curve?

我正在嘗試在[R]中創建直方圖,並且描述該直方圖的法線如下:

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

但是,當我嘗試通過曲線函數繪制法線曲線時,會顯示以下錯誤:

Error en curve(dnorm(w), -5, 5, add = T, col = "blue") : 
  'expr' must be a function, or a call or an expression containing 'x'

我究竟做錯了什么?

您只需要將“ w”自變量dnorm curve

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

要使用除“單位法線”以外的其他值,請提供“均值”和“ sd”自變量(並且切記同時更改histcurve的繪圖限制:

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")

在此處輸入圖片說明

簡單...

curve(dnorm(w, mean=mean(w), sd=sd(w)), y = 5, to = 15, add=T, col="blue")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM