Mixture of three Gaussian distributions
What will change if we incorporate another distribution into our simulation? You will see that increasing the number of components will spread the mass density to include the extra distribution, but the logic still follows from the previous exercise.
Este ejercicio forma parte del curso
Mixture Models in R
Instrucciones del ejercicio
- Create
assignments
, which takes the values 0, 1 and 2 with a probability of 0.3, 0.4 and 0.3, respectively. - The data frame
mixture
samples from a Gaussian with amean
of 5 andsd
of 2, whenassignments
is 1. Ifassignments
is 2, themean
is 10 andsd
is 1. Otherwise, is a standard normal distribution. - Plot the histogram with 50 bins.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
number_observations <- 1000
# Create the assignment object
assignments <- sample(
c(0,1,2), size = number_observations, replace = TRUE, prob = c(0.3, ___, 0.3)
)
# Simulate the GMM with 3 distributions
mixture <- data.frame(
x = ifelse(___ == 1, rnorm(n = number_observations, mean = ___, sd = ___), ifelse(assignments == 2, rnorm(n = number_observations, mean = ___, sd = ___), rnorm(n = ___)))
)
# Plot the mixture
mixture %>%
ggplot() + ___(aes(x = x, y = ..density..), ___ = ___)