Exercise

Simulate a mixture of two Gaussian distributions

Mixture models can be very difficult to understand, so let's start by simulating a simple mixture model, and then we will advance from there. In this exercise, you will create a Gaussian Mixture Model with two components.

Instructions

100 XP
  • Simulate 500 samples from a binary variable using sample() with a probability of 0.8 for the value 1 and save the results into the object coin.
  • Then, create a vector mixture which samples from two different Gaussian distributions depending on the values of coin in the following way:
    • When the values of coin are 1, sample from a normal distribution with a mean of 5 and sd of 2.
    • Otherwise, sample from a standard normal distribution.