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

Computing confidence intervals for proportions

The sample proportion is computed by counting the number of successes and dividing this by the total sample size. This can be better explained using the following formula:

Here, N is the sample size and M is the number of success variables; this gives you the sample proportion of successes.

Now, we want to be able to make a statement about the population proportion, which is a fixed, yet unknown, quantity. We will construct a confidence interval for this proportion, using the following formula:

Here, zp is the 100 × pth percentile of the normal distribution.

Now, let's suppose that, on a certain website, out of 1,126 visitors, 310 clicked on a certain ad. Let's construct a confidence interval for the population proportion of visitors who clicked on the ad. This will allow us to predict future clicks. We will use the following steps to do so:

  1. Let's first load the data in the statsmodels package and actually compute the sample proportion, which, in this case, is 310 out of 1,126:

You can see that appropriately 28% of the visitors to the website clicked on the ad on that day.

  1. Our next step is to actually construct a confidence interval using the proportion_confint() function. We assign the number of successes in the count variable, the number of trials in the nobs variable, and the confidence in the alpha variable, as shown in the following code snippet:

As you can see here, with 95% confidence, the proportion is between approximately 25% and 30%.

  1. If we wanted a larger confidence interval, that is, a 99% confidence interval, then we could specify a different alpha, as follows:
主站蜘蛛池模板: 黎平县| 凤阳县| 黄骅市| 永顺县| 岑溪市| 万山特区| 阿尔山市| 县级市| 彰武县| 乐安县| 公安县| 贵德县| 佛冈县| 古蔺县| 綦江县| 城步| 盐山县| 报价| 龙江县| 聂拉木县| 台南县| 湟中县| 库尔勒市| 佳木斯市| 永康市| 克东县| 甘德县| 九江县| 临朐县| 南昌县| 泾川县| 齐齐哈尔市| 潢川县| 泰州市| 屏东市| 辉南县| 阜新市| 潼南县| 阿合奇县| 濮阳县| 西青区|