I'm trying to make a histogram in [R], and the normal curve that describes the histogram as follows:
w<-rnorm(1000)
hist(w,col="red",freq=F,xlim=c(-5,5))
curve(dnorm(w),-5,5,add=T,col="blue")
But when I try to plot the normal curve by curve function shows me the following error:
Error en curve(dnorm(w), -5, 5, add = T, col = "blue") :
'expr' must be a function, or a call or an expression containing 'x'
What am I doing wrong?
The normal distribution is produced by the normal density function, p(x) = e−(x−μ)2/2σ2/σ √2π. In this exponential function e is the constant 2.71828…, is the mean, and σ is the standard deviation.
Any point (x) from a normal distribution can be converted to the standard normal distribution (z) with the formula z = (x-mean) / standard deviation.
Simple...
curve(dnorm(w, mean=mean(w), sd=sd(w)), y = 5, to = 15, add=T, col="blue")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With