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.
Bu egzersiz
Mixture Models in R
kursunun bir parçasıdırEgzersiz talimatları
- 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
mixturesamples from a Gaussian with ameanof 5 andsdof 2, whenassignmentsis 1. Ifassignmentsis 2, themeanis 10 andsdis 1. Otherwise, is a standard normal distribution. - Plot the histogram with 50 bins.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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..), ___ = ___)