CodeInfoNet

Learn programming on the go!

Home » Law of Large Numbers

Law of Large Numbers

In this article we are going to assess the law of large numbers. We are going to do the practical implementation to check how it actually works.


Our previous article was about various loops and conditional statements. In case you have missed it, here is the link while loop, for loop, conditional statements in R

In this short article we will see how actually the law works.

First of all, it is important to know what the law of large numbers is.

Law of Large Numbers:

According to the law, the average of the results obtained from a large number of trials should be close to the expected value, and will tend to become closer as more trials are performed.

You can read the full Wikipedia article about it here.

Below is the mathematical representation of law of large numbers.

Law of Large Number
Law of Large Number

Now, to implement it in R programming, we are going to consider few things. We will use the rnorm() function to get the normally distributed random numbers.

We have,

Mean = 0

Standard deviation = 1

μ=68.2%

We will analyze the percentage of numbers fall between -1 and 1.

We will pass various input values e.x 100, 1000, 10000, 100000 etc. to rnorm() function to analyze the result.

Let’s see the code.

N <- 100    # Input

Counter <- 0

for(i in rnorm(N)){

  if(i > -1 & i < 1){

    Counter <- Counter + 1

  }

}

Counter / N

Compare the counter value with 68.2% or 0.682.

Perform this operation for multiple times and keep changing the value of N. you will notice that the output value of counter will come closer as you increase the value of N.

Hence, we can say that the law of large number works perfectly.

Thanks for reading. Keep reading. Keep Coding !!

Let me know if you like the article. Let me know if anything is wrong. You can fill the feedback form given below or mail us directly at admin@codeinfo.net.

[wpforms id=”22″]

Sumit Rajguru

Back to top