Question: In R studio # Normal Distribution We will plot the density of a random variable with the normal distribution for different choices of parameters. Note:

In R studio

# Normal Distribution

We will plot the density of a random variable with the normal distribution for different choices of parameters.

Note:

1) The values for this random variable lie in the interval $(-\infty, \infty)$, however, since the density curve rapidly goes to zero as we move away from the mean, we will only need to choose values 4 standard deviations from the mean.

2) The density is determined by two parmeters the mean -$\mu$, and the standard deviation -$\sigma$. Please note that in R, the normal distribution parameters are $N(\mu, \sigma)$ (instead of $N(\mu, \sigma^2)$ like in the textbook).

a) Write a function "plot_norm" that takes input: mu, sigma and outputs the probablity plot of the density of the normal distribution N(mu, sig) with a vertical line at mu.

```{r}

plot_norm <- function(mu, sig){

x <- seq(-4, 4, length.out = 10000)*sig + mu #formula for x-score

y <- dnorm(x, mean = mu, sd = sig) #density formula

plot(x, y, type = 'l',

main = paste("Normal density: mean = ", mu ,"std dev = ", sig),

xlab = "x", ylab = "f(x)")

abline(h = 0) #add horizontal line at y=0.

abline(v = ____ ,col = _____) #add red vertical line at the mu

}

```

Now fix $\mu = 5$. For the following six values of $\sigma$: 0.001, 0.01, 0.1, 1, 10, 100 - plot for the corresponding normal distributions:

```{r}

sigs <- ________

par(mfrow = c(3,3))

for (sig in sigs){

plot_norm(5, _____ )

}

```

Note at least two observations that you notice.

Now writea new function 'plot_norm_det' (normal plot with details) that takes input: mu, sig, and outputs a plot of the normal density with vertical lines at 1, 2, and 3 standard deviations away from the mean.

```{r}

plot_norm_det <- function(mu, sig){

x <- ___________#formula for x-score

y <- ___________ #formula for density

plot(x, y, type = 'l',

main = paste("Normal density: mean = ", mu ,"std dev = ", sig),

xlab = "x", ylab = "f(x)")

abline(h =0) #add horizontal line at y=0.

abline(v = mu_X, col = 'red') #add vertical line at the mean

abline(v = mu+ 1*sig*c(-1, 1), col = "blue") #add vertical blue line 1 sd from the mean

abline(v = __________, col = _____) #add vertical purple line 2 sd from the mean

abline(v = __________, col = ______) #add vertical green line 2 sd from the mean

}

```

Now fix $\mu = 5$. For the following six values of $\sigma$: 0.001, 0.01, 0.1, 1, 10, 100 - plot the detailed plots for the corresponding normal distribution:

```{r}

sigs <- _____________

par(mfrow = c(3,3))

for (sig in sigs){

plot_norm_det(5, ________ )

}

```

Note at least two observations that you notice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!