前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >统计学02: 二项分布

统计学02: 二项分布

原创
作者头像
生信探索
发布2023-05-06 13:53:08
910
发布2023-05-06 13:53:08
举报
文章被收录于专栏:生信探索生信探索

n 次伯努力事件(发生和不发生概率和为1)

发生r次的概率$P(x=r)=C_{n}^{r} p^{r}(1-p)^{n-r}$

期望:$E(x)=np$,方差:$D(x)=np(1-p)$

代码语言:text
复制
using Distributions
d=Binomial(4, 0.35);
mean(d) == 4*0.35
var(d) == 4*0.35(1-0.35)

Example

We asked various probability questions regarding the number of people out of 4 with blood type O+. We verified that the scenario was binomial and that each problem could be solved using the binomial formula. Instead of looking at it piecewise, we could describe the entire distribution of possible values and their corresponding probabilities. Since there are 4 people, there are several possible outcomes for the number who might have blood type O+: 0, 1, 2, 3, 4. We can make a distribution table with these outcomes. Recall that the probability of a randomly sampled person being blood type O+ is about 0.35.

pdf(distribution, x)计算分布密度(概率质量)函数在x处的值, 如果x是数组,结果返回数组; 如果x是数组且函数写成pdf!(distribution, x),则结果保存在x中返回。 logpdf()计算其密度函数的自然对数值。

使用pdf实现发生0、1、2、3、4次的概率计算。

代码语言:text
复制
using CairoMakie,Distributions
CairoMakie.activate!()

let
    d=Binomial(4, 0.35);
    x = 0:4
    y = pdf.(d, x)
    barplot(x, y)
end

Mississippi问题

mississippi字母有多少种排列组合方式。

字母长度的阶乘除以s、i、p字母重复个数的阶乘,简单的例子是kis、kiss、kisss字母有多少种排列组合方式,可以使用枚举法、填空法求解。

$$

\frac{11!}{4!\ 4!\ 2!}

$$

代码语言:text
复制
using Combinatorics
multiset_permutations("mississippi",11) |> length == 34650
factorial(11)/(factorial(4)*factorial(4)*factorial(2)) == 34650.0

如果认为重复的字母是不一样的

代码语言:text
复制
permutations("mississippi") |> length == 39916800

Reference

代码语言:text
复制
https://www.bilibili.com/video/BV1CA411P7bL

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Example
  • Mississippi问题
  • Reference
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档