全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1500 3
2013-04-10
假设一个班有30人,生日跨度为3年(一年365天),求任意两个学生同年同月同日生的概率。(在R中运行)
求编程……
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-4-11 01:37:35
3年的跨度(1095 days)下一个班30人中至少有两个人一天生日的概率:

1-choose(1095,30)*factorial(30)/(1095^30)
=0.3302673
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-4-11 04:51:45
In case birthday is not equally distributed,  R code is as following:

#----------------------Start----------------------
N <- 365*3
m <- 30

# birthday is equally distributed
pbirth_equal <- function(x) {
  return(1.0/N)
}

# birthday is normally distributed
pbirth_norm <- function(x) {
  mu <- (N+1)/2
  #Note:
  #   1. In order to avoid too much truncate error: delta need to be less than N/6
  #   2. In order to maintain positive sign of sumPi in the following calculation, delta need to be greater than (m-1)/sqrt(2*pi)
  delta <- N/6  
  px <- (x-mu)/delta
  pbirth <- 1/sqrt(2*pi)*exp(-px*px/2)
  return(pbirth/delta)
}

Pbirthday <- 0
for (i in 1:N) {  
  Pi <- pbirth_norm(i)
  sumPi <- Pi
  
  for (j in 1:(m-1)) {
    sumPi <- sumPi * (1-j*Pi)
  }
  Pbirthday <- Pbirthday + sumPi
}

(1-Pbirthday)    # probability output
#----------------------End----------------------

Basically you need to implement your own birthday piror function. If the birthday is normall distributed with mean: (N+1)/2 and standard deviation: N/6, the probability will be 0.478.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-4-12 13:14:53
cemcem 发表于 2013-4-11 01:37
3年的跨度(1095 days)下一个班30人中至少有两个人一天生日的概率:

1-choose(1095,30)*factorial(30)/(1 ...
Thank you very much!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群