티스토리 뷰
Q. 몬테카를로 시뮬레이션을 사용하여 몬티홀 문제를 푸시오
( 참고 : 몬티홀 문제 )
Suppose you’re on a game show, and you’re given the choice of three doors. Behind one door is a car, behind the others, goats. You pick a door, say #1, and the host, who knows what’s behind the doors, opens another door, say #3, which has a goat. He says to you, "Do you want to pick door #2?" Is it to your advantage to switch your choice of doors?
당신이 한 게임 쇼에 참여하여 세 문들 중 하나를 고를 기회를 가졌다고 생각해봐라. 한 문 뒤에는 자동차가 있으며, 다른 두 문 뒤에는 염소가 있다. 당신은 1번 문을 고르고, 문 뒤에 무엇이 있는지 아는 사회자는 염소가 있는 3번 문을 연다. 그는 당신에게 "2번 문을 고르고 싶습니까?"라고 묻는다. 당신의 선택을 바꾸는 것은 이득이 되는가?
A.
doors<-c("A","B","C")
N<-10000
xdata=c()
for(i in 1:N){
prize<-sample(doors)[1] # prize door
pick<-sample(doors)[1] # original choice
open<-sample(doors[which(doors!=pick & doors!=prize)])[1] # open one door
switch<-doors[which(doors!=pick & doors!=open)] # swich decision
if(switch == prize){xdata=c(xdata,"switchwin")}
if(pick==prize){xdata=c(xdata,"holdwin")}
}
paste0(" 바꿔서 이길 확률 = " , length(which(xdata=="switchwin"))/N)
paste0(" 안바꿔서 이길 확률 = ", length(which(xdata=="holdwin"))/N )
===> 수행 결과
> paste0(" 바꿔서 이길 확률 " , length(which(xdata=="switchwin"))/N)
[1] " 바꿔서 이길 확률 = 0.6676" > paste0(" 안바꿔서 이길 확률 = ", length(which(xdata=="holdwin"))/N )
[1] " 안바꿔서 이길 확률 = 0.3324"
'Simulation 방법' 카테고리의 다른 글
몬테카를로(Monte Carlo) 시뮬레이션 - 표본 분산 ( n 혹은 n-1 ) (0) | 2019.09.22 |
---|---|
몬테카를로(Monte Carlo) 시뮬레이션 - 원 면적 구하기 (0) | 2019.05.27 |