Statistics with R--Introduction to data--week 3 Probability--Notes

 目的:用R模拟,验证每一次科比每一次投篮是不是独立事件

首先,拿到科比的133次投篮数据,数steak数(遇到miss就算一个)

calc_streak函数是用来数steak的,并根据结果画出直方图

Statistics with R--Introduction to data--week 3 Probability--Notes

 

但是,要想知道科比的投篮数据是不是每次独立的,需要与独立投篮比较,但我们无法知道哪个球员的投篮是不是每一次都是完全独立的,所以用R做模拟。

下面是一个抛硬币的例子

Statistics with R--Introduction to data--week 3 Probability--Notes

 将 hands 和 tails 两个结果赋值给 outcomes

sample函数的作用是:从outcomes里选出一个结果(heads or tails),size=1,拿一次(实验次数),replace=true, 拿出后放回。

如果要模拟实验,需要多次重复实验,那么改变size

Statistics with R--Introduction to data--week 3 Probability--Notes

并定义新的对象sim_fair_coin,

Statistics with R--Introduction to data--week 3 Probability--Notes 

 运行对象得到结果。

如果要对各个结果计数,需要用到table函数

Statistics with R--Introduction to data--week 3 Probability--Notes

 

模拟一个不规则的抛硬币实验,赋予两种结果不一样的可能性,heads20%,tails80%

Statistics with R--Introduction to data--week 3 Probability--Notes 

结果是这样的 

Statistics with R--Introduction to data--week 3 Probability--Notes 

 现在用同样的方法模拟Kobe的投篮模型(假设他投篮是独立的)

已知Kobe篮球生涯中投中的比例约为45%

Statistics with R--Introduction to data--week 3 Probability--Notes

 Statistics with R--Introduction to data--week 3 Probability--Notes

模拟了133次 

Statistics with R--Introduction to data--week 3 Probability--Notes 

 Statistics with R--Introduction to data--week 3 Probability--Notes

根据模拟结果画出直方图

现在要做的就是将科比的实际投篮数据与独立模拟模型作比较 

emmm怎么说呢,这两个图看起来趋势是差不多的,都是单峰,并且右边。(但是我觉得比例好像不太一样?)

因此最后的结论就是,科比的投篮数据steak分布趋势和独立投篮模拟结果的steak分布趋势大致相同,说明科比的每次投篮是相对独立的,即不存在所谓的“hot hand phenomenon”