楼主: 1+1=3
1542 3

[程序分享] r语言编程 [推广有奖]

  • 1关注
  • 0粉丝

初中生

9%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
419 点
帖子
7
精华
0
在线时间
7 小时
注册时间
2011-10-25
最后登录
2015-3-5

楼主
1+1=3 发表于 2013-4-10 21:57:25 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
假设一个班有30人,生日跨度为3年(一年365天),求任意两个学生同年同月同日生的概率。(在R中运行)
求编程……
二维码

扫码加我 拉你入群

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

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

关键词:R语言编程 语言编程 R语言 生日 语言编程

我是添乱的90后

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

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

藤椅
cemcem 发表于 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.

板凳
1+1=3 发表于 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!!!
我是添乱的90后

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 01:03