Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 840
franvergara66 Avatar asked Jan 28 '12 16:01

franvergara66


People also ask

What is the function for the normal curve?

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.

How do we translate the general curve to the standard normal curve?

Any point (x) from a normal distribution can be converted to the standard normal distribution (z) with the formula z = (x-mean) / standard deviation.


1 Answers

Simple...

curve(dnorm(w, mean=mean(w), sd=sd(w)), y = 5, to = 15, add=T, col="blue")
like image 121
Manoj Kumar Avatar answered Oct 19 '22 09:10

Manoj Kumar