# [R] A simple resampling problem

Dimitris Rizopoulos 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.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm

----- 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
> the
> 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
> usual
> methods.
> But I would like to get the students to think of resampling, by
> doing
> 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
> learn
> about statistics (or probability theory), and R of course.
>
> Thank you for your time.
> Regards
> Jacob
>
>
>
>
> 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
> https://stat.ethz.ch/mailman/listinfo/r-help