# [R] family question

Douglas Bates bates at stat.wisc.edu
Wed Aug 30 20:44:00 CEST 2000

```Troels Ring <tring at mail1.stofanet.dk> writes:

> Dear friends. Please see the program below and answer if it does simulate a
> population of 1.000.000 families, each with at max 20000 children (typical
> in Denmark, you know), constructed such that each family stops having
> children when more boys than girls are present ? Equal numbers of boys and
> girls are got in the population, according to the simulation, is that obvious ?

I am not an expert in probability or in stochastic processes so I
can't say that it is "obvious".  I can say it is not unreasonable if
you consider the sizes of families.  Basically what happens is that
large families have nearly equal numbers of girls and boys and also
have a high weight in the calculation of the population proportion.
(You can only get odd numbered family sizes according to your rule and
for a family of size 2K + 1 there will be K girls and K + 1 boys.)

>From simulation it seems that there is a non-negligible probability of
very large family sizes.  If you get a high proportion of girls early
then it can take a long time for the number of boys to catch up.
Most of the families have only 1 or 3 children but about 1% or
2% of the time you get families of size 500 or more.

In fact when I simulated 1000 families with a maximum allowable family size of
999, I got 23 families that would have had more than 999 children.

> famsz <- double(1000)
> ind <- 1:1000
> for (i in seq(along = famsz)) famsz[i] <- min(ind[cumsum(ifelse(runif(1000) > 0.5, 1, 0)) > (ind/2)])
There were 23 warnings (use warnings() to see them)
> table(famsz)
famsz
1          3          5          7          9         11         13
497        141         62         25         31         24         17
15         17         19         21         23         25         27
15          9          6         12          8         10          6
29         31         33         35         37         39         41
2          6          7          2          2          3          3
43         45         47         51         55         57         59
2          1          4          3          5          2          1
61         63         65         69         71         73         75
2          3          1          1          1          1          1
77         91         97         99        103        107        109
5          1          2          3          1          2          1
111        113        121        127        137        139        143
1          1          1          1          2          1          1
147        163        167        169        173        177        191
1          1          1          3          1          1          2
215        235        243        251        275        279        281
1          1          1          1          1          1          1
293        307        321        359        401        411        421
1          1          1          1          1          1          1
459        467        489        537        573        581        603
1          1          1          1          1          1          1
629        631        661        771        839        863        929
1          1          1          1          1          1          1
2147483647
23

> ND <- NP <- NULL #ND - number boys, P: girls
> for (j in 1:1000000) # number of families
> {
> n1 <- n2 <- NULL
> for (i in 1:20000)  {
> n1[i] <- rbinom(1,1,0.5) # each equally likely - here number of boys
> n2[i] <- 1- n1[i] # and girls
> if(sum(n1)>sum(n2)) break
> }
> ND[j] <- sum(n1)
> NP[j] <- sum(n2)
> }
> sum(ND)/sum(NP)
> j
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

--
Douglas Bates                            bates at stat.wisc.edu
Statistics Department                    608/262-2598
University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```