[R] A simple resampling problem
dimitris.rizopoulos at med.kuleuven.be
Fri Sep 22 13:17:22 CEST 2006
try the following:
B <- 10000
index <- rowSums(matrix(rbinom(B*2, 1, 0.5), ncol = 2))
sum(index == 2) / sum(index > 0)
I hope it helps.
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
----- Original Message -----
From: "Jacob van Wyk" <jlvw at na.rau.ac.za>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, September 22, 2006 12:57 PM
Subject: [R] A simple resampling problem
> Dear UseRs
> I would like to show my students how to use "resampling" to solve
> following simple problem:
> If a family has two children of which one is a boy, what is the
> probability that the other child is also a boy.
> The answer is (obviously) 1/3, and can be show easily using the
> But I would like to get the students to think of resampling, by
> the following:
> Flip two coins repeatedly, denoted 0 and 1 (1 for boy, say). Discard
> those pairs that both contain 0.
>>From those left over, count how many pairs are (1,1).
> Divide this number by the number available to choose from (i.e. all
> pairs, except (0,0)).
> This will then give 1/3 (more or less of course).
> Can somebody help me to code this efficiently, or elegantly (and
> smartly) in R, without loops etc.
> It is intended for first year students that are only starting to
> about statistics (or probability theory), and R of course.
> Thank you for your time.
> Jacob L van Wyk
> Department of Statistics
> University of Johannesburg, APK
> P O Box 524
> Auckland Park 2006
> South Africa
> Tel: +27 11 489 3080
> Fax: +27 11 489 2832
> [[alternative HTML version deleted]]
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help