In this section we will explore the normal distribution.
Set \(\mu = 5\). For values of \(\sigma\) given by \(0.2, 0.4, 0.8, 1, 1.3, 1.8, 2\), plot the densities of \(N(\mu, \sigma)\) in the same plot. It might help if (1) you have the densities of \(N(\mu = 5, \sigma = 0.2)\) and \(N(\mu = 5, \sigma = 2)\) to be blue in color and the rest to be red. (2) choose appropriate limits for the x-axis (use x_lim parameter in the plot funtion) and y-axis (use y_lim).
mu <- 0.5
std <- c(0.4, 0.8, 1, 1.3, 1.8)
#dnorm(0, mean = mu, sd = 0.2)
x <- seq(-5, 6, length.out = 1000)
plot(x, dnorm(x),type = 'l', ylim = c(0, 2))
for(std_dev in std){
lines(x, dnorm(x, mean = mu, sd = std_dev),col = "red")
}
lines(x, dnorm(x, mean = mu, sd = 0.2),col = "blue")
lines(x, dnorm(x, mean = mu, sd = 2),col = "blue")
#abline(v = mu, h=0)
What do you notice about the plot? Comment about how the width changes. Since the mean is the same throughout all of the plots, the mean is centered at the same area. The higher the standard deviation is, the wider the width of the graph
Set \(\sigma = 0.4\). For values of \(\mu\) given by \(-1, -0.5, 0, 0.4, 0.9, 2.5, 4\) plot the densities of \(N(\mu, \sigma)\) in the same plot. You might need to choose appropriate limits for the x-axis.
sigma <- 0.4
mu <- c(-1, -0.5, 0, 0.4, 0.9, 2.5, 4)
x <- seq(-5, 6, length.out = 1000)
plot(x, dnorm(x),type = 'l', ylim = c(0, 2))
for(mean in mu){
lines(x, dnorm(x, mean = mu, sd = sigma))
}
We will plot the Gamma distibution for different shapes and scales. You might need to adjust the limits of x and y axes appropriately.
Set \(\alpha = 1\), vary \(\beta\) over \(0.2, 0.6, 1, 1.5, 2\). Plot the densities of \(Gamma(\alpha, \beta)\) in a single plot.
alpha <- 1
beta <- c(0.2,0.6,1,1.5,2)
x <- seq(0,50, length.out = 1000)
y <- dgamma(x, shape = 1, scale = beta )
plot(x,y, type ="l",
ylim =c(0,0.75))
lines(x, dgamma(x, shape = 1, scale = 0.2),
col = 'red')
lines(x, dgamma(x, shape = 1, scale = 0.6),
col = 'blue')
lines(x, dgamma(x, shape = 1, scale = 1),
col = 'black')
lines(x, dgamma(x, shape = 1, scale = 1.5),
col = 'pink')
lines(x, dgamma(x, shape = 1, scale = 2),
col = 'yellow')
abline( h=0, v=0 )
plot(x, dgamma(x, shape = 1, scale = beta),
col = 'red')
Set \(\alpha = 0.6\), vary \(\beta\) over \(0.2, 0.6, 1, 1.5, 2\). Plot the densities of \(Gamma(\alpha, \beta)\) in a single plot.
alpha <- 0.6
beta <- c(0.2,0.6,1,1.5,2)
x <- seq(0,50, length.out = 1000)
y <- dgamma(x, shape = 1, scale = beta )
plot(x,y, type ="l",
ylim =c(0,0.75))
lines(x, dgamma(x, shape = 0.6, scale = 0.2),
col = 'red')
lines(x, dgamma(x, shape = 0.6, scale = 0.6),
col = 'blue')
lines(x, dgamma(x, shape = 0.6, scale = 1),
col = 'black')
lines(x, dgamma(x, shape = 0.6, scale = 1.5),
col = 'pink')
lines(x, dgamma(x, shape = 0.6, scale = 2),
col = 'yellow')
abline( h=0, v=0 )
plot(x, dgamma(x, shape = 0.6, scale = beta),
col = 'red')
Set \(\alpha = 2\), vary \(\beta\) over \(0.2, 0.6, 1, 1.5, 2\). Plot the densities of \(Gamma(\alpha, \beta)\) in a single plot.
alpha <- 2
beta <- c(0.2,0.6,1,1.5,2)
x <- seq(0,50, length.out = 1000)
y <- dgamma(x, shape = 1, scale = beta )
plot(x,y, type ="l",
ylim =c(0,0.75))
lines(x, dgamma(x, shape = 2, scale = 0.2),
col = 'red')
lines(x, dgamma(x, shape = 2, scale = 0.6),
col = 'blue')
lines(x, dgamma(x, shape = 2, scale = 1),
col = 'black')
lines(x, dgamma(x, shape = 2, scale = 1.5),
col = 'pink')
lines(x, dgamma(x, shape = 2, scale = 2),
col = 'yellow')
abline( h=0, v=0 )
plot(x, dgamma(x, shape = 2, scale = beta),
col = 'red')
Set \(\alpha = 5\), vary \(\beta\) over \(0.2, 0.6, 1, 1.5, 2\). Plot the densities of \(Gamma(\alpha, \beta)\) in a single plot.
alpha <- 5
beta <- c(0.2,0.6,1,1.5,2)
x <- seq(0,50, length.out = 1000)
y <- dgamma(x, shape = 1, scale = beta )
plot(x,y, type ="l",
ylim =c(0,0.75))
lines(x, dgamma(x, shape = 5, scale = 0.2),
col = 'red')
lines(x, dgamma(x, shape = 5, scale = 0.6),
col = 'blue')
lines(x, dgamma(x, shape = 5, scale = 1),
col = 'black')
lines(x, dgamma(x, shape = 5, scale = 1.5),
col = 'pink')
lines(x, dgamma(x, shape = 5, scale = 2),
col = 'yellow')
abline( h=0, v=0 )
plot(x, dgamma(x, shape = 5, scale = beta),
col = 'red')