Reputation: 21
I have been asked to plot the density of the Cauchy distribution with mean 0, bewteen -5 and 5, and to overlay this with the density of the normal distribution with mean 0 and standard deviation 1.2. And I don't even know where to start.. any help?
Upvotes: 1
Views: 8850
Reputation: 8893
Look at the documentation for the Cauchy distribution with ?dcauchy
. In fact, that's the function which calculates the Cauchy density function at a location x0, not a mean (as @Dason and @iTech) mention; it is certainly defined for x0=0 though.
The equivalent function for the normal distribution is dnorm
, and a plot might look like this:
x<-seq(-10,10,by=0.1)
plot(x, dnorm(x),type="l")
lines(x, dcauchy(x),col="red")
Note the seq
command is somewhat arbitrary: it just creates a vector with evenly spaced values from -10 to 10, at intervals of 1/10.
Good luck on the rest of your homework.
Update:
Here's a simpler way using plot.function
:
plot(dnorm, -10, 10, n=1001)
plot(dcauchy, -10, 10, n=1001, col='red', add=TRUE)
Upvotes: 7