Simulation:0

I honestly did not know what to expect form this lesson. It just sounded complicated. Apparently it was going to teach common probability distributions in respect to random number generation.

In this lesson, we first created a dice using the sample() command:

 sample(1:6, 4, replace = TRUE)

This command basically selects four numbers between 1 and 6 with replacement, which means that all 4 numbers are replaced the next time you role the dice, allowing numbers to be repeated on subsequent rolls. Each time you run this line, the combination of numbers is different and there is only a 0.00077 chance of getting the same combination.

Followingly we simulated an unfair coin flip

flips<-sample(c(0,1), 100, replace = TRUE, prob = c(0.3, 0.7))

Since the outcome can be either 0 or 1, it is a binary outcome and rbinom() can be used to represent the number of successes given in a number of trials. for this, we need to specify the number of flips and the probability of them being successful (heads which we assigned to 1 in the binomial code).

rbinom(1, size = 100, prob = 0.7)

To simulate random numbers from other probability distributions that are not binary, we can use rnorm(). This command has a default mean of 0 and sd of 1, implying a standard normal distribution.

Followingly we used the poison distribution, which honestly wasn't very clear to me.

what I could understand is that we used colMeans() to calculate the means of each column and then hist() to represent them in a histogram.

So this was an interesting introduction to simulation but, I think I need to study more to get to understand what it can be applied for in terms of bioinformatics:)

Posted Jun 18, 2024, 12:46 PM UTC

10
Loading comments…