Verifying large number theorems with R language

Source: Internet
Author: User

I am very interested in mathematics, suffering from the mathematical theorem formula to be afraid of life, have always wanted to use a simple, popular way to show the charm of mathematics, Learning R language for a period of time, feel can use this tool to verify some mathematical theorem, also is a kind of fun, say dry, first a simple point

Large number theorem:

In the large number of repeated occurrences of random events, it tends to show almost inevitable law, which is the law of large numbers. In layman's terms, the theorem is that, under the condition of constant experimentation, repeated experiments have several times, and the frequency of random events approximates its probability. For example, we throw a coin upwards, which side of the coin falls on it is accidental, but when we have enough to toss a coin, tens of thousands of times or even hundreds of thousands of millions of times, we will find that the number of coins each face up to about one-second of the total number of times, accidental inclusion of some inevitable.

Verification Code:

Big_num<-function (n=1000)
{
count<-0

For (i in 1:n)
{
if (sample (C (0,1), 1) ==1) count<-count+1 # #随机从0, 1 sample, Count equals 1

}

Return (count/n) # #返回1出现的频率
}

Operation Result:

> Big_num ()
[1] 0.49
> Big_num (10000)
[1] 0.5027
> Big_num (100000)
[1] 0.49872
> Big_num (1000000)
[1] 0.499487
> Big_num (10000000)
[1] 0.4997597
>

Sure enough, as the number of experiments increases, the frequency of 1 appears to be approximately the probability of each experiment (0.5)

Verifying large number theorems with R language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.