Re: [R] A simple resampling problem

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Fri 22 Sep 2006 - 11:17:22 GMT

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

Address: Kapucijnenvoer 35, Leuven, Belgium

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


> 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@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 22 21:21:11 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 22 Sep 2006 - 12:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.