Possible Duplicate:
Making a standard normal distribution in R
Using R, draw a standard normal distribution. Label the mean and 3 standard deviations above and below the (10) mean. Include an informative title and labels on the x and y axes.
This is a homework problem. I'm not sure how to get going with the code. How should I get started?
A standard normal distribution is the type of distribution that has mean equals to zero with standard deviation 1. If we want to generate standard normal random numbers then rnorm function of R can be used but need to pass the mean = 0 and standard deviation = 1 inside this function.
A basic histogram can be created with the hist function. In order to add a normal curve or the density line you will need to create a density histogram setting prob = TRUE as argument.
rnorm is the R function that simulates random variates having a specified normal distribution. As with pnorm , qnorm , and dnorm , optional arguments specify the mean and standard deviation of the distribution.
I am pretty sure this is a duplicate. Anyway, have a look at the following piece of code
x <- seq(5, 15, length=1000)
y <- dnorm(x, mean=10, sd=3)
plot(x, y, type="l", lwd=1)
I'm sure you can work the rest out yourself, for the title you might want to look for something called main=
and y-axis
labels are also up to you.
If you want to see more of the tails of the distribution, why don't you try playing with the seq(5, 15, )
section? Finally, if you want to know more about what dnorm
is doing I suggest you look here
By the way, instead of generating the x and y coordinates yourself, you can also use the curve()
function, which is intended to draw curves corresponding to a function (such as the density of a standard normal function).
see
help(curve)
and its examples.
And if you want to add som text to properly label the mean and standard deviations, you can use the text()
function (see also plotmath
, for annotations with mathematical symbols) .
see
help(text)
help(plotmath)
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