官术网_书友最值得收藏!

Measures of central tendency

What if you had to describe the center of a distribution within a single number? Most people would appeal to one of these three estimators: mean, median, or mode. Those are probably the most popular measures of central tendency. Let's begin by sampling data from an arbitrary distribution. Get into your R console and try the following code:

set.seed(10)
small_sample <- rnorm(n = 10, mean = 10, sd = 5)
big_sample <- rnorm(n = 10^5, mean = 10, sd = 5)

The first line is setting the seed number to work with our random number generator (RNG). Every time there's a need to rely on a pseudo-random process, the set.seed() function will make sure your code is reproducible (at least at some level). By setting it to 10 you will get the same numbers that I'm getting from the preceding code lines.

Some people would advise you to set a new seed (with set.seed()) every single time you load a package.

The two last lines are sorting pseudo-random numbers from a normally distributed variable. Call the rnom() function to sort variables from a normal distribution. Choose the number of observations sorted by adjusting the n parameter. Modify the mean and sd parameters if you want a mean and standard deviation different from 0 and 1 respectively.

In the real world, you will hardly know for sure what underlying process is ruling your data, but here we do know beforehand that our numbers come from a normally distributed variable with a mean of 10 and a standard deviation of 5 units. We gathered two samples. The one called small_sample has only 10 observations, while big_sample sums up to 100,000 observations. Even though both come from similar distributions we will see how estimates behave with respect to sample sizes.

主站蜘蛛池模板: 清水河县| 玉树县| 定西市| 黑山县| 油尖旺区| 渝中区| 洛阳市| 朔州市| 成武县| 齐齐哈尔市| 彰武县| 襄城县| 平度市| 武功县| 五寨县| 康定县| 汽车| 平潭县| 柳州市| 鸡西市| 赤壁市| 阿勒泰市| 松阳县| 岳阳县| 阿瓦提县| 泰安市| 龙门县| 新营市| 辽阳县| 珲春市| 泰宁县| 江西省| 双城市| 榆中县| 台中县| 甘泉县| 水城县| 营山县| 东山县| 岱山县| 和龙市|