<TeXmacs|1.0.6>

<style|generic>

<\body>
  \;

  <section|Lecture 9 - Lists, Bootstrap and Jackknife>

  Till now we learned about vectors, matrices, and dataframes, and we also
  leared about classes. Let us look a bit deeper into R.

  <subsubsection|Lists>

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=c(x=1,y=5)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      x y\ 

      1 5\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=c(1:4,10:14)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      [1] \ 1 \ 2 \ 3 \ 4 10 11 12 13 14
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=c(x=1:4,y=10:14)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      x1 x2 x3 x4 y1 y2 y3 y4 y5\ 

      \ 1 \ 2 \ 3 \ 4 10 11 12 13 14\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=list(x=1:4,y=10:14)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      $x

      [1] 1 2 3 4

      \;

      $y

      [1] 10 11 12 13 14
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a$x
    </input>

    <\output>
      [1] 1 2 3 4
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a$y
    </input>

    <\output>
      [1] 10 11 12 13 14
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[["x"]]
    </input>

    <\output>
      [1] 1 2 3 4
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[["y"]]
    </input>

    <\output>
      [1] 10 11 12 13 14
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=list(x=1:4,y=c("a","b"),z=1:10)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      $x

      [1] 1 2 3 4

      \;

      $y

      [1] "a" "b"

      \;

      $z

      \ [1] \ 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 \ 9 10
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[1]
    </input>

    <\output>
      $x

      [1] 1 2 3 4
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[1:2]
    </input>

    <\output>
      $x

      [1] 1 2 3 4

      \;

      $y

      [1] "a" "b"
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[[1]]
    </input>

    <\output>
      [1] 1 2 3 4
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Using <verbatim|[]> will give us a sublist of the list, which is still a
  list. Using <verbatim|[[]]> will give us elements of the list.

  We already learned about <verbatim|sapply>, there is also a function called
  <verbatim|lapply>.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      lapply(1:10,function(x) x^2)
    </input>

    <\output>
      [[1]]

      [1] 1

      \;

      [[2]]

      [1] 4

      \;

      [[3]]

      [1] 9

      \;

      [[4]]

      [1] 16

      \;

      [[5]]

      [1] 25

      \;

      [[6]]

      [1] 36

      \;

      [[7]]

      [1] 49

      \;

      [[8]]

      [1] 64

      \;

      [[9]]

      [1] 81

      \;

      [[10]]

      [1] 100
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=lapply(1:10,function(x) x^2)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[1:3]
    </input>

    <\output>
      [[1]]

      [1] 1

      \;

      [[2]]

      [1] 4

      \;

      [[3]]

      [1] 9
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[[3]]
    </input>

    <\output>
      [1] 9
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a[[1:3]]
    </input>

    <\output>
      Error: recursive indexing failed at level 2
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  sapply and lapply are very similar, except that sapply will turn its output
  into a matrix or vector in the end.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=lapply(31:40,c);a
    </input>

    <\output>
      [[1]]

      [1] 31

      \;

      [[2]]

      [1] 32

      \;

      [[3]]

      [1] 33

      \;

      [[4]]

      [1] 34

      \;

      [[5]]

      [1] 35

      \;

      [[6]]

      [1] 36

      \;

      [[7]]

      [1] 37

      \;

      [[8]]

      [1] 38

      \;

      [[9]]

      [1] 39

      \;

      [[10]]

      [1] 40
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      names(a)=c("a","b","c","d","e","f","g","h","i","j")
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      $a

      [1] 31

      \;

      $b

      [1] 32

      \;

      $c

      [1] 33

      \;

      $d

      [1] 34

      \;

      $e

      [1] 35

      \;

      $f

      [1] 36

      \;

      $g

      [1] 37

      \;

      $h

      [1] 38

      \;

      $i

      [1] 39

      \;

      $j

      [1] 40
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a$d
    </input>

    <\output>
      [1] 34
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a["e"]
    </input>

    <\output>
      $e

      [1] 35
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b=lapply(a,function(x) x-20)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b
    </input>

    <\output>
      $a

      [1] 11

      \;

      $b

      [1] 12

      \;

      $c

      [1] 13

      \;

      $d

      [1] 14

      \;

      $e

      [1] 15

      \;

      $f

      [1] 16

      \;

      $g

      [1] 17

      \;

      $h

      [1] 18

      \;

      $i

      [1] 19

      \;

      $j

      [1] 20
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sapply(a,function(x) x-20)
    </input>

    <\output>
      \ a \ b \ c \ d \ e \ f \ g \ h \ i \ j\ 

      11 12 13 14 15 16 17 18 19 20\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  How to turn a list into a vector?

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b
    </input>

    <\output>
      $a

      [1] 11

      \;

      $b

      [1] 12

      \;

      $c

      [1] 13

      \;

      $d

      [1] 14

      \;

      $e

      [1] 15

      \;

      $f

      [1] 16

      \;

      $g

      [1] 17

      \;

      $h

      [1] 18

      \;

      $i

      [1] 19

      \;

      $j

      [1] 20
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      unlist(b)
    </input>

    <\output>
      \ a \ b \ c \ d \ e \ f \ g \ h \ i \ j\ 

      11 12 13 14 15 16 17 18 19 20\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Another extremely usefull function is <verbatim|tapply>

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      setwd("~/R-course-2006/lecture8")
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      list.files()
    </input>

    <\output>
      [1] "factorial.txt" \ \ \ \ \ \ \ \ \ "oneway.txt"
      \ \ \ \ \ \ \ \ \ \ \ \ "Rcourse8_no_output.tm"\ 

      [4] "Rcourse8_no_output.tm~" "Rcourse8.pdf"
      \ \ \ \ \ \ \ \ \ \ "Rcourse8.tm" \ \ \ \ \ \ \ \ \ \ 

      [7] "Rcourse8.tm~" \ \ \ \ \ \ \ \ \ \ "regression.txt"
      \ \ \ \ \ \ \ \ "twoway.txt" \ \ \ \ \ \ \ \ \ \ \ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact=read.table("factorial.txt",sep="\\t",head=T)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact
    </input>

    <\output>
      \ \ \ growth diet \ coat

      1 \ \ \ \ 6.6 \ \ \ A light

      2 \ \ \ \ 7.2 \ \ \ A light

      3 \ \ \ \ 6.9 \ \ \ B light

      4 \ \ \ \ 8.3 \ \ \ B light

      5 \ \ \ \ 7.9 \ \ \ C light

      6 \ \ \ \ 9.2 \ \ \ C light

      7 \ \ \ \ 8.3 \ \ \ A \ dark

      8 \ \ \ \ 8.7 \ \ \ A \ dark

      9 \ \ \ \ 8.1 \ \ \ B \ dark

      10 \ \ \ 8.5 \ \ \ B \ dark

      11 \ \ \ 9.1 \ \ \ C \ dark

      12 \ \ \ 9.0 \ \ \ C \ dark
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$diet,c)
    </input>

    <\output>
      $A

      [1] 6.6 7.2 8.3 8.7

      \;

      $B

      [1] 6.9 8.3 8.1 8.5

      \;

      $C

      [1] 7.9 9.2 9.1 9.0
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$coat,c)
    </input>

    <\output>
      $dark

      [1] 8.3 8.7 8.1 8.5 9.1 9.0

      \;

      $light

      [1] 6.6 7.2 6.9 8.3 7.9 9.2
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$diet,median)
    </input>

    <\output>
      \ \ \ A \ \ \ B \ \ \ C\ 

      7.75 8.20 9.05\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$coat,c)
    </input>

    <\output>
      $dark

      [1] 8.3 8.7 8.1 8.5 9.1 9.0

      \;

      $light

      [1] 6.6 7.2 6.9 8.3 7.9 9.2
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$coat,median,simplify=F)
    </input>

    <\output>
      $dark

      [1] 8.6

      \;

      $light

      [1] 7.55
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      tapply(fact$growth,fact$coat,median,simplify=T)
    </input>

    <\output>
      \ dark light\ 

      \ 8.60 \ 7.55\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  dataframe are also lists, but special lists.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact
    </input>

    <\output>
      \ \ \ growth diet \ coat

      1 \ \ \ \ 6.6 \ \ \ A light

      2 \ \ \ \ 7.2 \ \ \ A light

      3 \ \ \ \ 6.9 \ \ \ B light

      4 \ \ \ \ 8.3 \ \ \ B light

      5 \ \ \ \ 7.9 \ \ \ C light

      6 \ \ \ \ 9.2 \ \ \ C light

      7 \ \ \ \ 8.3 \ \ \ A \ dark

      8 \ \ \ \ 8.7 \ \ \ A \ dark

      9 \ \ \ \ 8.1 \ \ \ B \ dark

      10 \ \ \ 8.5 \ \ \ B \ dark

      11 \ \ \ 9.1 \ \ \ C \ dark

      12 \ \ \ 9.0 \ \ \ C \ dark
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact[["growth"]]
    </input>

    <\output>
      \ [1] 6.6 7.2 6.9 8.3 7.9 9.2 8.3 8.7 8.1 8.5 9.1 9.0
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact[["coat"]]
    </input>

    <\output>
      \ [1] light light light light light light dark \ dark \ dark \ dark
      \ dark \ dark\ 

      Levels: dark light
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      fact[1:2]
    </input>

    <\output>
      \ \ \ growth diet

      1 \ \ \ \ 6.6 \ \ \ A

      2 \ \ \ \ 7.2 \ \ \ A

      3 \ \ \ \ 6.9 \ \ \ B

      4 \ \ \ \ 8.3 \ \ \ B

      5 \ \ \ \ 7.9 \ \ \ C

      6 \ \ \ \ 9.2 \ \ \ C

      7 \ \ \ \ 8.3 \ \ \ A

      8 \ \ \ \ 8.7 \ \ \ A

      9 \ \ \ \ 8.1 \ \ \ B

      10 \ \ \ 8.5 \ \ \ B

      11 \ \ \ 9.1 \ \ \ C

      12 \ \ \ 9.0 \ \ \ C
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      lapply(fact,c)
    </input>

    <\output>
      $growth

      \ [1] 6.6 7.2 6.9 8.3 7.9 9.2 8.3 8.7 8.1 8.5 9.1 9.0

      \;

      $diet

      \ [1] 1 1 2 2 3 3 1 1 2 2 3 3

      \;

      $coat

      \ [1] 2 2 2 2 2 2 1 1 1 1 1 1
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      attributes(fact)
    </input>

    <\output>
      $names

      [1] "growth" "diet" \ \ "coat" \ 

      \;

      $class

      [1] "data.frame"

      \;

      $row.names

      \ [1] "1" \ "2" \ "3" \ "4" \ "5" \ "6" \ "7" \ "8" \ "9" \ "10" "11"
      "12"
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  The <verbatim|attributes> of an object can cause R to treat it differently.
  Two attributes that we already encountered are <verbatim|class>, and
  <verbatim|names>. fact is a list, but because the class is ``data.frame'',
  it is treated in a special way.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=matrix(1:12,3,4)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      \ \ \ \ \ [,1] [,2] [,3] [,4]

      [1,] \ \ \ 1 \ \ \ 4 \ \ \ 7 \ \ 10

      [2,] \ \ \ 2 \ \ \ 5 \ \ \ 8 \ \ 11

      [3,] \ \ \ 3 \ \ \ 6 \ \ \ 9 \ \ 12
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      attributes(a)
    </input>

    <\output>
      $dim

      [1] 3 3
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  all that seperates a vector from a matrix is the <verbatim|dim> attributes.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      attributes(a)$dim=c()
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      \ [1] \ 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 \ 9 10 11 12
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      attributes(a)$dim=c(3,4)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      \ \ \ \ \ [,1] [,2] [,3] [,4]

      [1,] \ \ \ 1 \ \ \ 4 \ \ \ 7 \ \ 10

      [2,] \ \ \ 2 \ \ \ 5 \ \ \ 8 \ \ 11

      [3,] \ \ \ 3 \ \ \ 6 \ \ \ 9 \ \ 12
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      attributes(a)$dim=c(4,3)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      \ \ \ \ \ [,1] [,2] [,3]

      [1,] \ \ \ 1 \ \ \ 5 \ \ \ 9

      [2,] \ \ \ 2 \ \ \ 6 \ \ 10

      [3,] \ \ \ 3 \ \ \ 7 \ \ 11

      [4,] \ \ \ 4 \ \ \ 8 \ \ 12
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  <subsection|Bootstrapping>

  The principle of the bootstrap method is that the data the we gathered can
  represent the external world.

  In order to get a distribution of possible values that we could have
  measured, we re-sample from the data.

  <subsection|Example: Median>

  Let us say that we have a population of 2000 people, whose heights are the
  following:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|<with|mode|math|\<succ\>><with|color|black|>> >
      population=c(rnorm(1500,mean=180,sd=10),rnorm(500,mean=140,sd=10))
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      hist(population,n=30);v()
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3135332E3634203237362E3934203434312E3634203536342E393420636C0A2F707320313420646566204220313420730A3020302030207267620A3330392E3634203533352E33322028486973746F6772616D206F6620706F70756C6174696F6E29202E352030203020740A2F707320313220646566205220313220730A3330392E3634203239322E35342028706F70756C6174696F6E29202E352030203020740A3136342E3434203432362E393420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3233302E3533203333382E3134206D0A3135382E32322030206C0A6F0A6E700A3233302E3533203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3237302E3038203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3330392E3634203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3334392E3139203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3338382E3735203333382E3134206D0A30202D362E3030206C0A6F0A2F707320313220646566205220313220730A3233302E3533203331362E3534202831323029202E352030203020740A3237302E3038203331362E3534202831343029202E352030203020740A3330392E3634203331362E3534202831363029202E352030203020740A3334392E3139203331362E3534202831383029202E352030203020740A3338382E3735203331362E3534202832303029202E352030203020740A6E700A3230322E3834203334342E3732206D0A30203136312E3232206C0A6F0A6E700A3230322E3834203334342E3732206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203337312E3539206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203339382E3436206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203432352E3333206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203435322E3230206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203437392E3037206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203530352E3934206D0A2D362E30302030206C0A6F0A3138382E3434203334342E373220283029202E35203020393020740A3138382E3434203337312E35392028353029202E35203020393020740A3138382E3434203339382E3436202831303029202E35203020393020740A3138382E3434203435322E3230202832303029202E35203020393020740A3138382E3434203530352E3934202833303029202E35203020393020740A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3231302E3735203334342E373220392E383920312E303720722070310A3232302E3634203334342E373220392E383920342E383420722070310A3233302E3533203334342E373220392E383920392E363720722070310A3234302E3432203334342E373220392E38392033302E303920722070310A3235302E3330203334342E373220392E38392033362E303120722070310A3236302E3139203334342E373220392E38392035352E383920722070310A3237302E3038203334342E373220392E38392035322E313320722070310A3237392E3937203334342E373220392E38392033312E373120722070310A3238392E3836203334342E373220392E38392033302E363320722070310A3239392E3735203334342E373220392E38392032372E393420722070310A3330392E3634203334342E373220392E38392033382E363920722070310A3331392E3533203334342E373220392E38392037352E323420722070310A3332392E3432203334342E373220392E3839203131322E383520722070310A3333392E3330203334342E373220392E3839203135342E373720722070310A3334392E3139203334342E373220392E3839203136342E343420722070310A3335392E3038203334342E373220392E3839203132392E353120722070310A3336382E3937203334342E373220392E38392037322E303120722070310A3337382E3836203334342E373220392E38392032372E343120722070310A3338382E3735203334342E373220392E38392031342E353120722070310A3339382E3634203334342E373220392E383920352E333720722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Now let us assume that we measure the heights of 20 randomly chosen people
  exactly:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|<with|mode|math|\<succ\>><with|color|black|>> >
      measurements=sample(population,20)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      measurements
    </input>

    <\output>
      \ [1] 182.6651 195.6872 182.5375 174.9788 183.1086 164.1614 127.4974
      178.6637

      \ [9] 184.6356 178.1290 179.3890 170.3763 138.7274 183.9492 182.9451
      181.6166

      [17] 191.0370 179.0268 124.8710 128.2074
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  We want to know the median of the distribution. To approximante that, we
  measure the median of the measurements:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|<with|mode|math|\<succ\>><with|color|black|>> >
      median(measurements)
    </input>

    <\output>
      [1] 179.2079
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  We know now the median of the mesurements. How wrong are we?

  If we had the whole population at our disposal, we could do the process of
  sampling many times, and see the distribution of the median:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|<with|mode|math|\<succ\>><with|color|black|>> >
      pop.samples=t(sapply(1:10000,function(i) sample(population,20) ))
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      dim(pop.samples)
    </input>

    <\output>
      [1] 10000 \ \ \ 20
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      pop.samples.medians=apply(pop.samples,1,median)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      hist(pop.samples.medians,n=30);v()
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3135332E3634203237362E3934203434312E3634203536342E393420636C0A2F707320313420646566204220313420730A3020302030207267620A3330392E3634203533352E33322028486973746F6772616D206F6620706F702E73616D706C65732E6D656469616E7329202E352030203020740A2F707320313220646566205220313220730A3330392E3634203239322E35342028706F702E73616D706C65732E6D656469616E7329202E352030203020740A3136342E3434203432362E393420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231302E3735203333382E3134206D0A3139372E37382030206C0A6F0A6E700A3231302E3735203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3235302E3330203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3238392E3836203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3332392E3432203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3336382E3937203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3430382E3533203333382E3134206D0A30202D362E3030206C0A6F0A2F707320313220646566205220313220730A3231302E3735203331362E3534202831343029202E352030203020740A3235302E3330203331362E3534202831353029202E352030203020740A3238392E3836203331362E3534202831363029202E352030203020740A3332392E3432203331362E3534202831373029202E352030203020740A3336382E3937203331362E3534202831383029202E352030203020740A3430382E3533203331362E3534202831393029202E352030203020740A6E700A3230322E3834203334342E3732206D0A30203136372E3436206C0A6F0A6E700A3230322E3834203334342E3732206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203338362E3539206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203432382E3435206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203437302E3332206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203531322E3138206D0A2D362E30302030206C0A6F0A3138382E3434203334342E373220283029202E35203020393020740A3138382E3434203338362E3539202835303029202E35203020393020740A3138382E3434203432382E343520283130303029202E35203020393020740A3138382E3434203437302E333220283135303029202E35203020393020740A3138382E3434203531322E313820283230303029202E35203020393020740A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3231302E3735203334342E373220372E393120302E303820722070310A3231382E3636203334342E373220372E393120302E313720722070310A3232362E3537203334342E373220372E393120302E323520722070310A3233342E3438203334342E373220372E393120302E333320722070310A3234322E3339203334342E373220372E393120302E303820722070310A3235302E3330203334342E373220372E393120302E363720722070310A3235382E3232203334342E373220372E393120312E303020722070310A3236362E3133203334342E373220372E393120312E343220722070310A3237342E3034203334342E373220372E393120312E363720722070310A3238312E3935203334342E373220372E393120322E383520722070310A3238392E3836203334342E373220372E393120332E313820722070310A3239372E3737203334342E373220372E393120352E393420722070310A3330352E3638203334342E373220372E39312031312E323220722070310A3331332E3539203334342E373220372E39312032312E323720722070310A3332312E3530203334342E373220372E39312034302E313120722070310A3332392E3432203334342E373220372E39312037322E323620722070310A3333372E3333203334342E373220372E3931203130332E363620722070310A3334352E3234203334342E373220372E3931203135352E333220722070310A3335332E3135203334342E373220372E3931203136342E343420722070310A3336312E3036203334342E373220372E3931203133372E313520722070310A3336382E3937203334342E373220372E39312037382E313220722070310A3337362E3838203334342E373220372E39312032392E333120722070310A3338342E3739203334342E373220372E393120362E303320722070310A3339322E3730203334342E373220372E393120302E353020722070310A3430302E3632203334342E373220372E393120302E323520722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      median(population)
    </input>

    <\output>
      [1] 176.1048
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>

    \;
  </session>>

  We can see that we're likely to be about 10cm off the real median.

  But we don't have the real population. We only have our samples. To
  estimate the distribution of medians, we sample from the sample, instead of
  from the real population:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sample.samples=t(sapply(1:10000,function(i)
      sample(measurements,20,rep=T) ))
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sample.samples.medians=apply(sample.samples,1,median)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      layout( matrix(1:2,2,1));par(cex=0.7);hist(pop.samples.medians,n=30,xlim=c(135,190)

      );hist(sample.samples.medians,n=30,xlim=c(135,190));v();layout(1)
    </input>

    <\input|<with|color|red|+ <with|color|black|>>>
      \;
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3135332E3634203432302E3934203434312E3634203536342E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203534342E31332028486973746F6772616D206F6620706F702E73616D706C65732E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203433312E38362028706F702E73616D706C65732E6D656469616E7329202E352030203020740A3136312E3230203439372E313420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231362E3637203436332E3738206D0A3139382E35392030206C0A6F0A6E700A3231362E3637203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3235362E3339203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3239362E3131203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3333352E3833203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3337352E3534203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203436332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3231362E3637203434382E3636202831343029202E352030203020740A3235362E3339203434382E3636202831353029202E352030203020740A3239362E3131203434382E3636202831363029202E352030203020740A3333352E3833203434382E3636202831373029202E352030203020740A3337352E3534203434382E3636202831383029202E352030203020740A3431352E3236203434382E3636202831393029202E352030203020740A6E700A3138382E3038203436362E3236206D0A302036322E3931206C0A6F0A6E700A3138382E3038203436362E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203438312E3938206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203439372E3731206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203531332E3434206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203532392E3137206D0A2D342E32302030206C0A6F0A3137382E3030203436362E323620283029202E35203020393020740A3137382E3030203438312E3938202835303029202E35203020393020740A3137382E3030203531332E343420283135303029202E35203020393020740A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3231362E3637203436362E323620372E393420302E303320722070310A3232342E3632203436362E323620372E393420302E303620722070310A3233322E3536203436362E323620372E393420302E303920722070310A3234302E3530203436362E323620372E393420302E313320722070310A3234382E3435203436362E323620372E393420302E303320722070310A3235362E3339203436362E323620372E393420302E323520722070310A3236342E3333203436362E323620372E393420302E333820722070310A3237322E3238203436362E323620372E393420302E353320722070310A3238302E3232203436362E323620372E393420302E363320722070310A3238382E3137203436362E323620372E393420312E303720722070310A3239362E3131203436362E323620372E393420312E323020722070310A3330342E3035203436362E323620372E393420322E323320722070310A3331322E3030203436362E323620372E393420342E323120722070310A3331392E3934203436362E323620372E393420372E393920722070310A3332372E3838203436362E323620372E39342031352E303720722070310A3333352E3833203436362E323620372E39342032372E313520722070310A3334332E3737203436362E323620372E39342033382E393420722070310A3335312E3731203436362E323620372E39342035382E333520722070310A3335392E3636203436362E323620372E39342036312E373820722070310A3336372E3630203436362E323620372E39342035312E353220722070310A3337352E3534203436362E323620372E39342032392E333520722070310A3338332E3439203436362E323620372E39342031312E303120722070310A3339312E3433203436362E323620372E393420322E323620722070310A3339392E3337203436362E323620372E393420302E313920722070310A3430372E3332203436362E323620372E393420302E303920722070310A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3135332E3634203237362E3934203434312E3634203432302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203430302E31332028486973746F6772616D206F662073616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203238372E3836202873616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A3136312E3230203335332E313420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231362E3637203331392E3738206D0A3139382E35392030206C0A6F0A6E700A3231362E3637203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3235362E3339203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3239362E3131203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3333352E3833203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3337352E3534203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203331392E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3231362E3637203330342E3636202831343029202E352030203020740A3235362E3339203330342E3636202831353029202E352030203020740A3239362E3131203330342E3636202831363029202E352030203020740A3333352E3833203330342E3636202831373029202E352030203020740A3337352E3534203330342E3636202831383029202E352030203020740A3431352E3236203330342E3636202831393029202E352030203020740A6E700A3138382E3038203332322E3236206D0A302036312E3336206C0A6F0A6E700A3138382E3038203332322E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203333322E3438206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203334322E3731206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203335322E3934206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203336332E3137206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203337332E3430206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203338332E3632206D0A2D342E32302030206C0A6F0A3137382E3030203332322E323620283029202E35203020393020740A3137382E3030203334322E373120283130303029202E35203020393020740A3137382E3030203337332E343020283235303029202E35203020393020740A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3139322E3834203332322E323620372E393420302E313420722070310A3230302E3739203332322E323620372E393420302E303220722070310A3230382E3733203332322E323620372E393420302E333720722070310A3231362E3637203332322E323620372E393420302E373220722070310A3232342E3632203332322E323620372E393420322E393520722070310A3233322E3536203332322E323620372E393420332E323920722070310A3234302E3530203332322E323620372E393420342E303720722070310A3234382E3435203332322E323620372E393420302E303020722070310A3235362E3339203332322E323620372E393420302E303020722070310A3236342E3333203332322E323620372E393420312E373020722070310A3237322E3238203332322E323620372E393420362E323620722070310A3238302E3232203332322E323620372E393420302E373820722070310A3238382E3137203332322E323620372E393420302E353920722070310A3239362E3131203332322E323620372E393420352E313320722070310A3330342E3035203332322E323620372E393420372E313020722070310A3331322E3030203332322E323620372E393420302E303220722070310A3331392E3934203332322E323620372E39342031342E333220722070310A3332372E3838203332322E323620372E393420322E393520722070310A3333352E3833203332322E323620372E393420302E303420722070310A3334332E3737203332322E323620372E39342033392E363020722070310A3335312E3731203332322E323620372E39342036312E373820722070310A3335392E3636203332322E323620372E39342033332E363520722070310A3336372E3630203332322E323620372E39342031302E353320722070310A3337352E3534203332322E323620372E393420342E393120722070310A3338332E3439203332322E323620372E393420302E353120722070310A3339312E3433203332322E323620372E393420322E393720722070310A3339392E3337203332322E323620372E393420302E313620722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  As you see, we do not get the same distribution! The first distribution was
  created by sampling from the real population. The second distribution was
  sampled from our sample.

  <subsection|Parametric bootstrap>

  Instead of using the sample as our model for the world, we can base a model
  on the sample, and then sample from it. For example, let us look at our
  sample.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      hist(measurements);rug(measurements);v()
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3135332E3634203237362E3934203434312E3634203536342E393420636C0A2F707320313420646566204220313420730A3020302030207267620A3330392E3634203533352E33322028486973746F6772616D206F66206D6561737572656D656E747329202E352030203020740A2F707320313220646566205220313220730A3330392E3634203239322E353420286D6561737572656D656E747329202E352030203020740A3136342E3434203432362E393420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231302E3735203333382E3134206D0A3139372E37382030206C0A6F0A6E700A3231302E3735203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3234332E3731203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3237362E3637203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3330392E3634203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3334322E3630203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3337352E3536203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3430382E3533203333382E3134206D0A30202D362E3030206C0A6F0A2F707320313220646566205220313220730A3231302E3735203331362E3534202831303029202E352030203020740A3234332E3731203331362E3534202831323029202E352030203020740A3237362E3637203331362E3534202831343029202E352030203020740A3330392E3634203331362E3534202831363029202E352030203020740A3334322E3630203331362E3534202831383029202E352030203020740A3337352E3536203331362E3534202832303029202E352030203020740A3430382E3533203331362E3534202832323029202E352030203020740A6E700A3230322E3834203334342E3732206D0A30203136342E3435206C0A6F0A6E700A3230322E3834203334342E3732206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203336382E3231206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203339312E3731206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203431352E3230206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203433382E3639206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203436322E3138206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203438352E3638206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203530392E3137206D0A2D362E30302030206C0A6F0A3138382E3434203334342E373220283029202E35203020393020740A3138382E3434203336382E323120283129202E35203020393020740A3138382E3434203339312E373120283229202E35203020393020740A3138382E3434203431352E323020283329202E35203020393020740A3138382E3434203433382E363920283429202E35203020393020740A3138382E3434203436322E313820283529202E35203020393020740A3138382E3434203438352E363820283629202E35203020393020740A3138382E3434203530392E313720283729202E35203020393020740A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3231302E3735203334342E37322033322E39362034362E393820722070310A3234332E3731203334342E37322033322E39362034362E393820722070310A3237362E3637203334342E37322033322E39362037302E343820722070310A3330392E3634203334342E37322033322E3936203136342E343420722070310A3334322E3630203334342E37322033322E3936203131372E343620722070310A3337352E3536203334342E37322033322E39362032332E343920722070310A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3338207365746C696E6577696474680A5B5D203020736574646173680A6E700A3233392E3638203333382E3134206D0A3134322E34352030206C0A6F0A6E700A3233392E3638203333382E3134206D0A3020352E3333206C0A6F0A6E700A3234322E3534203333382E3134206D0A3020352E3333206C0A6F0A6E700A3236352E3736203333382E3134206D0A3020352E3333206C0A6F0A6E700A3236392E3839203333382E3134206D0A3020352E3333206C0A6F0A6E700A3237392E3630203333382E3134206D0A3020352E3333206C0A6F0A6E700A3238312E3336203333382E3134206D0A3020352E3333206C0A6F0A6E700A3238392E3136203333382E3134206D0A3020352E3333206C0A6F0A6E700A3331332E3639203333382E3134206D0A3020352E3333206C0A6F0A6E700A3333312E3239203333382E3134206D0A3020352E3333206C0A6F0A6E700A3333312E3533203333382E3134206D0A3020352E3333206C0A6F0A6E700A3333352E3235203333382E3134206D0A3020352E3333206C0A6F0A6E700A3333362E3232203333382E3134206D0A3020352E3333206C0A6F0A6E700A3333362E3634203333382E3134206D0A3020352E3333206C0A6F0A6E700A3334322E3335203333382E3134206D0A3020352E3333206C0A6F0A6E700A3334392E3337203333382E3134206D0A3020352E3333206C0A6F0A6E700A3335302E3536203333382E3134206D0A3020352E3333206C0A6F0A6E700A3335322E3534203333382E3134206D0A3020352E3333206C0A6F0A6E700A3335352E3533203333382E3134206D0A3020352E3333206C0A6F0A6E700A3335372E3338203333382E3134206D0A3020352E3333206C0A6F0A6E700A3338322E3133203333382E3134206D0A3020352E3333206C0A6F0A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  It obviously does not look normal - it has too much of a tail on the left.

  We could still try to fit the best normal distrubution we can find, and
  then bootstrap.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=measurements-mean(measurements)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=a/sd(a)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      ks.test(a,pnorm)
    </input>

    <\output>
      \;

      \ \ \ \ \ \ \ \ One-sample Kolmogorov-Smirnov test

      \;

      data: \ a\ 

      D = 0.2335, p-value = 0.2254

      alternative hypothesis: two.sided\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  You can see that because of the small sample size, the KS test is actually
  not significant.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      mm=mean(measurements);mm
    </input>

    <\output>
      [1] 164.5417
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      msd=sd(measurements);msd
    </input>

    <\output>
      [1] 25.19489
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      parametric=matrix( rnorm(10000*20,mean=mm,sd=msd), 10000, 20)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      parametric.medians=apply(parametric,1,median)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      layout( matrix(1:3,3,1));par(cex=0.7);hist(pop.samples.medians,n=30,xlim=c(135,190)

      );hist(sample.samples.medians,n=30,xlim=c(135,190)

      );hist(parametric.medians,n=30,xlim=c(135,190));v(width=5,height=5);layout(1)
    </input>

    <\input|<with|color|red|+ <with|color|black|>>>
      \;
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203131382032343120343738203630310A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3135322E3038203532332E3738203436302E3030203536362E353020636C0A3131372E3634203438302E3934203437372E3634203630302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203538302E31332028486973746F6772616D206F6620706F702E73616D706C65732E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203439312E38362028706F702E73616D706C65732E6D656469616E7329202E352030203020740A3132352E3230203534352E313420284672657175656E637929202E35203020393020740A3131372E3634203234302E3934203437372E3634203630302E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3138392E3430203532332E3738206D0A3235392E31392030206C0A6F0A6E700A3138392E3430203532332E3738206D0A30202D342E3230206C0A6F0A6E700A3234312E3234203532332E3738206D0A30202D342E3230206C0A6F0A6E700A3239332E3038203532332E3738206D0A30202D342E3230206C0A6F0A6E700A3334342E3932203532332E3738206D0A30202D342E3230206C0A6F0A6E700A3339362E3735203532332E3738206D0A30202D342E3230206C0A6F0A6E700A3434382E3539203532332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3138392E3430203530382E3636202831343029202E352030203020740A3234312E3234203530382E3636202831353029202E352030203020740A3239332E3038203530382E3636202831363029202E352030203020740A3334342E3932203530382E3636202831373029202E352030203020740A3339362E3735203530382E3636202831383029202E352030203020740A3434382E3539203530382E3636202831393029202E352030203020740A6E700A3135322E3038203532352E3337206D0A302034302E3238206C0A6F0A6E700A3135322E3038203532352E3337206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203533352E3434206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203534352E3531206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203535352E3538206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203536352E3635206D0A2D342E32302030206C0A6F0A3134322E3030203532352E333720283029202E35203020393020740A3134322E3030203534352E353120283130303029202E35203020393020740A3135322E3038203532332E3738203436302E3030203536362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3138392E3430203532352E33372031302E333720302E303220722070310A3139392E3737203532352E33372031302E333720302E303420722070310A3231302E3134203532352E33372031302E333720302E303620722070310A3232302E3530203532352E33372031302E333720302E303820722070310A3233302E3837203532352E33372031302E333720302E303220722070310A3234312E3234203532352E33372031302E333720302E313620722070310A3235312E3631203532352E33372031302E333720302E323420722070310A3236312E3938203532352E33372031302E333720302E333420722070310A3237322E3334203532352E33372031302E333720302E343020722070310A3238322E3731203532352E33372031302E333720302E363820722070310A3239332E3038203532352E33372031302E333720302E373720722070310A3330332E3435203532352E33372031302E333720312E343320722070310A3331332E3831203532352E33372031302E333720322E373020722070310A3332342E3138203532352E33372031302E333720352E313220722070310A3333342E3535203532352E33372031302E333720392E363520722070310A3334342E3932203532352E33372031302E33372031372E333820722070310A3335352E3238203532352E33372031302E33372032342E393320722070310A3336352E3635203532352E33372031302E33372033372E333620722070310A3337362E3032203532352E33372031302E33372033392E353620722070310A3338362E3339203532352E33372031302E33372033322E393920722070310A3339362E3735203532352E33372031302E33372031382E373920722070310A3430372E3132203532352E33372031302E333720372E303520722070310A3431372E3439203532352E33372031302E333720312E343520722070310A3432372E3836203532352E33372031302E333720302E313220722070310A3433382E3233203532352E33372031302E333720302E303620722070310A3135322E3038203430332E3738203436302E3030203434362E353020636C0A3131372E3634203336302E3934203437372E3634203438302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203436302E31332028486973746F6772616D206F662073616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203337312E3836202873616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A3132352E3230203432352E313420284672657175656E637929202E35203020393020740A3131372E3634203234302E3934203437372E3634203630302E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3138392E3430203430332E3738206D0A3235392E31392030206C0A6F0A6E700A3138392E3430203430332E3738206D0A30202D342E3230206C0A6F0A6E700A3234312E3234203430332E3738206D0A30202D342E3230206C0A6F0A6E700A3239332E3038203430332E3738206D0A30202D342E3230206C0A6F0A6E700A3334342E3932203430332E3738206D0A30202D342E3230206C0A6F0A6E700A3339362E3735203430332E3738206D0A30202D342E3230206C0A6F0A6E700A3434382E3539203430332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3138392E3430203338382E3636202831343029202E352030203020740A3234312E3234203338382E3636202831353029202E352030203020740A3239332E3038203338382E3636202831363029202E352030203020740A3334342E3932203338382E3636202831373029202E352030203020740A3339362E3735203338382E3636202831383029202E352030203020740A3434382E3539203338382E3636202831393029202E352030203020740A6E700A3135322E3038203430352E3337206D0A302033392E3239206C0A6F0A6E700A3135322E3038203430352E3337206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203431312E3932206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203431382E3436206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203432352E3031206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203433312E3536206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203433382E3131206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203434342E3636206D0A2D342E32302030206C0A6F0A3134322E3030203430352E333720283029202E35203020393020740A3134322E3030203432352E303120283135303029202E35203020393020740A3135322E3038203430332E3738203436302E3030203434362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3135382E3330203430352E33372031302E333720302E303920722070310A3136382E3637203430352E33372031302E333720302E303120722070310A3137392E3033203430352E33372031302E333720302E323420722070310A3138392E3430203430352E33372031302E333720302E343620722070310A3139392E3737203430352E33372031302E333720312E383920722070310A3231302E3134203430352E33372031302E333720322E313120722070310A3232302E3530203430352E33372031302E333720322E363120722070310A3233302E3837203430352E33372031302E333720302E303020722070310A3234312E3234203430352E33372031302E333720302E303020722070310A3235312E3631203430352E33372031302E333720312E303920722070310A3236312E3938203430352E33372031302E333720342E303120722070310A3237322E3334203430352E33372031302E333720302E353020722070310A3238322E3731203430352E33372031302E333720302E333820722070310A3239332E3038203430352E33372031302E333720332E323920722070310A3330332E3435203430352E33372031302E333720342E353420722070310A3331332E3831203430352E33372031302E333720302E303120722070310A3332342E3138203430352E33372031302E333720392E313720722070310A3333342E3535203430352E33372031302E333720312E383920722070310A3334342E3932203430352E33372031302E333720302E303320722070310A3335352E3238203430352E33372031302E33372032352E333620722070310A3336352E3635203430352E33372031302E33372033392E353620722070310A3337362E3032203430352E33372031302E33372032312E353520722070310A3338362E3339203430352E33372031302E333720362E373520722070310A3339362E3735203430352E33372031302E333720332E313420722070310A3430372E3132203430352E33372031302E333720302E333320722070310A3431372E3439203430352E33372031302E333720312E393020722070310A3432372E3836203430352E33372031302E333720302E313020722070310A3135322E3038203238332E3738203436302E3030203332362E353020636C0A3131372E3634203234302E3934203437372E3634203336302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203334302E31332028486973746F6772616D206F6620706172616D65747269632E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203235312E38362028706172616D65747269632E6D656469616E7329202E352030203020740A3132352E3230203330352E313420284672657175656E637929202E35203020393020740A3131372E3634203234302E3934203437372E3634203630302E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3138392E3430203238332E3738206D0A3235392E31392030206C0A6F0A6E700A3138392E3430203238332E3738206D0A30202D342E3230206C0A6F0A6E700A3234312E3234203238332E3738206D0A30202D342E3230206C0A6F0A6E700A3239332E3038203238332E3738206D0A30202D342E3230206C0A6F0A6E700A3334342E3932203238332E3738206D0A30202D342E3230206C0A6F0A6E700A3339362E3735203238332E3738206D0A30202D342E3230206C0A6F0A6E700A3434382E3539203238332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3138392E3430203236382E3636202831343029202E352030203020740A3234312E3234203236382E3636202831353029202E352030203020740A3239332E3038203236382E3636202831363029202E352030203020740A3334342E3932203236382E3636202831373029202E352030203020740A3339362E3735203236382E3636202831383029202E352030203020740A3434382E3539203236382E3636202831393029202E352030203020740A6E700A3135322E3038203238352E3337206D0A302033342E3838206C0A6F0A6E700A3135322E3038203238352E3337206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203239322E3334206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203239392E3332206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203330362E3330206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203331332E3237206D0A2D342E32302030206C0A6F0A6E700A3135322E3038203332302E3235206D0A2D342E32302030206C0A6F0A3134322E3030203238352E333720283029202E35203020393020740A3134322E3030203330362E3330202836303029202E35203020393020740A3135322E3038203238332E3738203436302E3030203332362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3137392E3033203238352E33372031302E333720302E303320722070310A3138392E3430203238352E33372031302E333720302E313720722070310A3139392E3737203238352E33372031302E333720302E323120722070310A3231302E3134203238352E33372031302E333720302E363620722070310A3232302E3530203238352E33372031302E333720312E343020722070310A3233302E3837203238352E33372031302E333720332E323120722070310A3234312E3234203238352E33372031302E333720352E343420722070310A3235312E3631203238352E33372031302E333720392E333520722070310A3236312E3938203238352E33372031302E33372031342E323020722070310A3237322E3334203238352E33372031302E33372032322E333920722070310A3238322E3731203238352E33372031302E33372033302E343220722070310A3239332E3038203238352E33372031302E33372033362E323120722070310A3330332E3435203238352E33372031302E33372033392E323420722070310A3331332E3831203238352E33372031302E33372033392E353620722070310A3332342E3138203238352E33372031302E33372033372E303420722070310A3333342E3535203238352E33372031302E33372033332E353220722070310A3334342E3932203238352E33372031302E33372032352E313120722070310A3335352E3238203238352E33372031302E33372031392E383520722070310A3336352E3635203238352E33372031302E33372031332E323520722070310A3337362E3032203238352E33372031302E333720382E323720722070310A3338362E3339203238352E33372031302E333720342E393520722070310A3339362E3735203238352E33372031302E333720322E353520722070310A3430372E3132203238352E33372031302E333720312E303120722070310A3431372E3439203238352E33372031302E333720302E353220722070310A3432372E3836203238352E33372031302E333720302E313420722070310A3433382E3233203238352E33372031302E333720302E303320722070310A3434382E3539203238352E33372031302E333720302E303320722070310A3435382E3936203238352E33372031302E333720302E303020722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(sample.samples.medians)
    </input>

    <\output>
      [1] 8.75055
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(parametric.medians)
    </input>

    <\output>
      [1] 6.861419
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(pop.samples.medians)
    </input>

    <\output>
      [1] 4.687592
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  <subsection|Jackknife>

  The Jackkinfe method was invented before the bootstrap method, and is very
  similar.

  Instead of taking random samples from the distribution, we drop each of our
  sample points.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      jack= t( \ sapply(1:length(measurements),function(i) measurements[-i] )
      )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      jack[1:4,1:4]
    </input>

    <\output>
      \ \ \ \ \ \ \ \ \ [,1] \ \ \ \ [,2] \ \ \ \ [,3] \ \ \ \ [,4]

      [1,] 186.0301 162.4606 176.1285 133.3787

      [2,] 184.1049 162.4606 176.1285 133.3787

      [3,] 184.1049 186.0301 176.1285 133.3787

      [4,] 184.1049 186.0301 162.4606 133.3787
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      jack.medians=apply( jack, 1, median )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      layout( matrix(1:2,2,1));par(cex=0.7);hist(jack.medians,xlim=c(135,190)

      );hist(sample.samples.medians,n=30,xlim=c(135,190));v();layout(1)
    </input>

    <\input|<with|color|red|+ <with|color|black|>>>
      \;
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3135332E3634203432302E3934203434312E3634203536342E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203534342E31332028486973746F6772616D206F66206A61636B2E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203433312E383620286A61636B2E6D656469616E7329202E352030203020740A3136312E3230203439372E313420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231362E3637203436332E3738206D0A3139382E35392030206C0A6F0A6E700A3231362E3637203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3235362E3339203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3239362E3131203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3333352E3833203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3337352E3534203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203436332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3231362E3637203434382E3636202831343029202E352030203020740A3235362E3339203434382E3636202831353029202E352030203020740A3239362E3131203434382E3636202831363029202E352030203020740A3333352E3833203434382E3636202831373029202E352030203020740A3337352E3534203434382E3636202831383029202E352030203020740A3431352E3236203434382E3636202831393029202E352030203020740A6E700A3138382E3038203436362E3236206D0A302036312E3737206C0A6F0A6E700A3138382E3038203436362E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203437382E3631206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203439302E3937206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203530332E3332206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203531352E3638206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203532382E3033206D0A2D342E32302030206C0A6F0A3137382E3030203436362E323620283029202E35203020393020740A3137382E3030203437382E363120283229202E35203020393020740A3137382E3030203439302E393720283429202E35203020393020740A3137382E3030203530332E333220283629202E35203020393020740A3137382E3030203531352E363820283829202E35203020393020740A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3334372E3734203436362E323620312E39392036312E373820722070310A3334392E3733203436362E323620312E393920302E303020722070310A3335312E3731203436362E323620312E393920302E303020722070310A3335332E3730203436362E323620312E393920302E303020722070310A3335352E3638203436362E323620312E393920302E303020722070310A3335372E3637203436362E323620312E39392036312E373820722070310A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3135332E3634203237362E3934203434312E3634203432302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203430302E31332028486973746F6772616D206F662073616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A2F70732038206465662052203820730A3330362E3034203238372E3836202873616D706C652E73616D706C65732E6D656469616E7329202E352030203020740A3136312E3230203335332E313420284672657175656E637929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231362E3637203331392E3738206D0A3139382E35392030206C0A6F0A6E700A3231362E3637203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3235362E3339203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3239362E3131203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3333352E3833203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3337352E3534203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203331392E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3231362E3637203330342E3636202831343029202E352030203020740A3235362E3339203330342E3636202831353029202E352030203020740A3239362E3131203330342E3636202831363029202E352030203020740A3333352E3833203330342E3636202831373029202E352030203020740A3337352E3534203330342E3636202831383029202E352030203020740A3431352E3236203330342E3636202831393029202E352030203020740A6E700A3138382E3038203332322E3236206D0A302036312E3336206C0A6F0A6E700A3138382E3038203332322E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203333322E3438206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203334322E3731206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203335322E3934206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203336332E3137206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203337332E3430206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203338332E3632206D0A2D342E32302030206C0A6F0A3137382E3030203332322E323620283029202E35203020393020740A3137382E3030203334322E373120283130303029202E35203020393020740A3137382E3030203337332E343020283235303029202E35203020393020740A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3139322E3834203332322E323620372E393420302E313420722070310A3230302E3739203332322E323620372E393420302E303220722070310A3230382E3733203332322E323620372E393420302E333720722070310A3231362E3637203332322E323620372E393420302E373220722070310A3232342E3632203332322E323620372E393420322E393520722070310A3233322E3536203332322E323620372E393420332E323920722070310A3234302E3530203332322E323620372E393420342E303720722070310A3234382E3435203332322E323620372E393420302E303020722070310A3235362E3339203332322E323620372E393420302E303020722070310A3236342E3333203332322E323620372E393420312E373020722070310A3237322E3238203332322E323620372E393420362E323620722070310A3238302E3232203332322E323620372E393420302E373820722070310A3238382E3137203332322E323620372E393420302E353920722070310A3239362E3131203332322E323620372E393420352E313320722070310A3330342E3035203332322E323620372E393420372E313020722070310A3331322E3030203332322E323620372E393420302E303220722070310A3331392E3934203332322E323620372E39342031342E333220722070310A3332372E3838203332322E323620372E393420322E393520722070310A3333352E3833203332322E323620372E393420302E303420722070310A3334332E3737203332322E323620372E39342033392E363020722070310A3335312E3731203332322E323620372E39342036312E373820722070310A3335392E3636203332322E323620372E39342033332E363520722070310A3336372E3630203332322E323620372E39342031302E353320722070310A3337352E3534203332322E323620372E393420342E393120722070310A3338332E3439203332322E323620372E393420302E353120722070310A3339312E3433203332322E323620372E393420322E393720722070310A3339392E3337203332322E323620372E393420302E313620722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  We can see that the jackknife estimate of the error is too small. In fact
  it is too small by a factor of approxmimately <with|mode|math|<sqrt|20>>,
  or <with|mode|math|<sqrt|(n-1)<rsup|2>/n>>.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(jack.medians)
    </input>

    <\output>
      [1] 1.158305
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd( jack.medians)*sqrt(20)
    </input>

    <\output>
      [1] 5.180097
    </output>

    \;
  </session>>

  It is actually clear that the median will move between 1 2 or 3 points at
  most:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      median( 1:3)
    </input>

    <\output>
      [1] 2
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      median(1:2)
    </input>

    <\output>
      [1] 1.5
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      median(c(1,3))
    </input>

    <\output>
      [1] 2
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      median( 2:3)\ 
    </input>

    <\output>
      [1] 2.5
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  And as we see in the above example, we get just 2 points.\ 

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      table( jack.medians )
    </input>

    <\output>
      jack.medians

      173.280953077412 175.538905170459\ 

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ 10 \ \ \ \ \ \ \ \ \ \ \ \ \ \ 10\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Because the median has this property that it ``jumps'', the jackknife is a
  bad choice in this case.\ 

  Let us take another example:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a=read.table("/home/dirk/data/regression.txt",head=T)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      plot(growth~tannin,data=a);v()
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3230322E3834203333382E3134203431362E3434203531352E373420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3231302E3735203530392E313720322E323520632070310A3233352E3437203437362E323820322E323520632070310A3236302E3139203434332E333920322E323520632070310A3238342E3932203439322E373220322E323520632070310A3330392E3634203431302E353020322E323520632070310A3333342E3336203432362E393420322E323520632070310A3335392E3038203334342E373220322E323520632070310A3338332E3830203336312E313720322E323520632070310A3430382E3533203336312E313720322E323520632070310A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3231302E3735203333382E3134206D0A3139372E37382030206C0A6F0A6E700A3231302E3735203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3236302E3139203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3330392E3634203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3335392E3038203333382E3134206D0A30202D362E3030206C0A6F0A6E700A3430382E3533203333382E3134206D0A30202D362E3030206C0A6F0A2F707320313220646566205220313220730A3231302E3735203331362E353420283029202E352030203020740A3236302E3139203331362E353420283229202E352030203020740A3330392E3634203331362E353420283429202E352030203020740A3335392E3038203331362E353420283629202E352030203020740A3430382E3533203331362E353420283829202E352030203020740A6E700A3230322E3834203334342E3732206D0A30203136342E3435206C0A6F0A6E700A3230322E3834203334342E3732206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203337372E3631206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203431302E3530206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203434332E3339206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203437362E3238206D0A2D362E30302030206C0A6F0A6E700A3230322E3834203530392E3137206D0A2D362E30302030206C0A6F0A3138382E3434203334342E373220283229202E35203020393020740A3138382E3434203337372E363120283429202E35203020393020740A3138382E3434203431302E353020283629202E35203020393020740A3138382E3434203434332E333920283829202E35203020393020740A3138382E3434203437362E32382028313029202E35203020393020740A3138382E3434203530392E31372028313229202E35203020393020740A6E700A3230322E3834203333382E3134206D0A3231332E36302030206C0A30203137372E3630206C0A2D3231332E36302030206C0A30202D3137372E3630206C0A6F0A3135332E3634203237362E3934203434312E3634203536342E393420636C0A2F707320313220646566205220313220730A3020302030207267620A3330392E3634203239322E3534202874616E6E696E29202E352030203020740A3136342E3434203432362E3934202867726F77746829202E35203020393020740A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg=lm(growth~tannin,data=a)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg
    </input>

    <\output>
      \;

      Call:

      lm(formula = growth ~ tannin, data = a)

      \;

      Coefficients:

      (Intercept) \ \ \ \ \ \ tannin \ 

      \ \ \ \ \ 11.756 \ \ \ \ \ \ -1.217 \ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      names(reg)
    </input>

    <\output>
      \ [1] "coefficients" \ "residuals" \ \ \ \ "effects" \ \ \ \ \ \ "rank"
      \ \ \ \ \ \ \ \ 

      \ [5] "fitted.values" "assign" \ \ \ \ \ \ \ "qr"
      \ \ \ \ \ \ \ \ \ \ \ "df.residual" \ 

      \ [9] "xlevels" \ \ \ \ \ \ "call" \ \ \ \ \ \ \ \ \ "terms"
      \ \ \ \ \ \ \ \ "model" \ \ \ \ \ \ \ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg$coefficients[2]
    </input>

    <\output>
      \ \ \ tannin\ 

      -1.216667\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Let us say that we would like to know how exact this estimate of the slope
  is

  First, let us write a function that given growth and tannin tells us the
  slope:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      slope=function(gr,ta){reg=lm(gr~ta);reg$coeff[2]}
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      slope(a$gro,a$tan)
    </input>

    <\output>
      \ \ \ \ \ \ \ ta\ 

      -1.216667\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Now let us write a function that given idexes, calculates the slope for
  those points of data from a:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      index.slope=function(i) slope( a$gr[i], a$tan[i] )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </input>

    <\output>
      \ \ growth tannin

      1 \ \ \ \ 12 \ \ \ \ \ 0

      2 \ \ \ \ 10 \ \ \ \ \ 1

      3 \ \ \ \ \ 8 \ \ \ \ \ 2

      4 \ \ \ \ 11 \ \ \ \ \ 3

      5 \ \ \ \ \ 6 \ \ \ \ \ 4

      6 \ \ \ \ \ 7 \ \ \ \ \ 5

      7 \ \ \ \ \ 2 \ \ \ \ \ 6

      8 \ \ \ \ \ 3 \ \ \ \ \ 7

      9 \ \ \ \ \ 3 \ \ \ \ \ 8
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      index.slope(1:9)
    </input>

    <\output>
      \ \ \ \ \ \ \ ta\ 

      -1.216667\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      index.slope(1:3)
    </input>

    <\output>
      ta\ 

      -2\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      index.slope(-1)
    </input>

    <\output>
      \ \ \ \ \ \ \ ta\ 

      -1.190476\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Now the jackknife is very simple:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      jack.slopes=sapply(-(1:9), index.slope)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      jack.slopes
    </input>

    <\output>
      \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta
      \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta \ \ \ \ \ \ \ ta\ 

      -1.190476 -1.253133 -1.270270 -1.161359 -1.216667 -1.242038 -1.117117
      -1.200501\ 

      \ \ \ \ \ \ \ ta\ 

      -1.321429\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  Bootstrap is a bit more complicated:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      boot=t( sapply(1:200,function(i) sample(1:9,rep=T) ) )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      boot.slopes=apply(boot,1,index.slope)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      layout(matrix(1:2,2,1));par(cex=0.7);hist(boot.slopes,prob=T,xlim=c(-3,-0.5))
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      hist(jack.slopes,prob=T,xlim=c(-3,-0.5));v();layout(1)
    </input>

    <\output>
      <postscript|<tuple|<#252150532D41646F62652D332E3020455053462D332E300A2525446F63756D656E744E65656465645265736F75726365733A20666F6E742048656C7665746963610A25252B20666F6E742048656C7665746963612D426F6C640A25252B20666F6E742048656C7665746963612D4F626C697175650A25252B20666F6E742048656C7665746963612D426F6C644F626C697175650A25252B20666F6E742053796D626F6C0A25255469746C653A2052204772617068696373204F75747075740A252543726561746F723A205220536F6674776172650A252550616765733A20286174656E64290A2525426F756E64696E67426F783A203135342032373720343432203536350A2525456E64436F6D6D656E74730A2525426567696E50726F6C6F670A2F627020207B206773206773207D206465660A2520626567696E202E70732E70726F6C6F670A2F677320207B206773617665207D206465660A2F677220207B2067726573746F7265207D206465660A2F657020207B2073686F7770616765206772206772207D206465660A2F6D2020207B206D6F7665746F207D206465660A2F6C20207B20726C696E65746F207D206465660A2F6E7020207B206E657770617468207D206465660A2F637020207B20636C6F736570617468207D206465660A2F662020207B2066696C6C207D206465660A2F6F2020207B207374726F6B65207D206465660A2F632020207B206E65777061746820302033363020617263207D206465660A2F722020207B2034203220726F6C6C206D6F7665746F203120636F70792033202D3120726F6C6C20657863682030206578636820726C696E65746F203020726C696E65746F202D31206D756C2030206578636820726C696E65746F20636C6F736570617468207D206465660A2F703120207B207374726F6B65207D206465660A2F703220207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265206E657770617468207D206465660A2F703320207B20677361766520626720736574726762636F6C6F722066696C6C2067726573746F7265207374726F6B65207D206465660A2F742020207B2036202D3220726F6C6C206D6F7665746F20677361766520726F746174650A202020202020207073206D756C206E656720302032203120726F6C6C20726D6F7665746F0A202020202020203120696E64657820737472696E67776964746820706F700A202020202020206D756C206E6567203020726D6F7665746F2073686F772067726573746F7265207D206465660A2F636C20207B2067726573746F7265206773617665206E657770617468203320696E646578203320696E646578206D6F7665746F203120696E6465780A2020202020202034202D3120726F6C6C206C696E65746F202065786368203120696E646578206C696E65746F206C696E65746F0A20202020202020636C6F73657061746820636C6970206E657770617468207D206465660A2F726762207B20736574726762636F6C6F72207D206465660A2F732020207B207363616C65666F6E7420736574666F6E74207D206465660A2F522020207B202F466F6E74312066696E64666F6E74207D206465660A2F422020207B202F466F6E74322066696E64666F6E74207D206465660A2F492020207B202F466F6E74332066696E64666F6E74207D206465660A2F424920207B202F466F6E74342066696E64666F6E74207D206465660A2F532020207B202F466F6E74352066696E64666F6E74207D206465660A31207365746C696E656361702031207365746C696E656A6F696E0A2520656E642020202E70732E70726F6C6F670A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963610A2F48656C7665746963612066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7431206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C640A2F48656C7665746963612D426F6C642066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7432206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D4F626C697175650A2F48656C7665746963612D4F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7433206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742048656C7665746963612D426F6C644F626C697175650A2F48656C7665746963612D426F6C644F626C697175652066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A20202F456E636F64696E672049534F4C6174696E31456E636F64696E67206465660A202063757272656E74646963740A2020656E640A2F466F6E7434206578636820646566696E65666F6E7420706F700A2525496E636C7564655265736F757263653A20666F6E742053796D626F6C0A2F53796D626F6C2066696E64666F6E740A647570206C656E677468206469637420626567696E0A20207B3120696E646578202F464944206E65207B6465667D207B706F7020706F707D206966656C73657D20666F72616C6C0A202063757272656E74646963740A2020656E640A2F466F6E7435206578636820646566696E65666F6E7420706F700A2525456E6450726F6C6F670A2525506167653A203220320A62700A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3135332E3634203432302E3934203434312E3634203536342E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203534342E31332028486973746F6772616D206F6620626F6F742E736C6F70657329202E352030203020740A2F70732038206465662052203820730A3330362E3034203433312E38362028626F6F742E736C6F70657329202E352030203020740A3136312E3230203439372E3134202844656E7369747929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3139362E3832203436332E3738206D0A3231382E34342030206C0A6F0A6E700A3139362E3832203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3234302E3530203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3238342E3139203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3332372E3838203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3337312E3537203436332E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203436332E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3139362E3832203434382E363620282D332E3029202E352030203020740A3234302E3530203434382E363620282D322E3529202E352030203020740A3238342E3139203434382E363620282D322E3029202E352030203020740A3332372E3838203434382E363620282D312E3529202E352030203020740A3337312E3537203434382E363620282D312E3029202E352030203020740A3431352E3236203434382E363620282D302E3529202E352030203020740A6E700A3138382E3038203436362E3236206D0A302035392E3534206C0A6F0A6E700A3138382E3038203436362E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203438312E3134206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203439362E3033206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203531302E3931206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203532352E3830206D0A2D342E32302030206C0A6F0A3137382E3030203436362E32362028302E3029202E35203020393020740A3137382E3030203439362E30332028312E3029202E35203020393020740A3137382E3030203532352E38302028322E3029202E35203020393020740A3138382E3038203436332E3738203432342E3030203533302E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3234392E3234203436362E32362031372E343820302E373420722070310A3236362E3732203436362E32362031372E343820302E373420722070310A3238342E3139203436362E32362031372E343820302E373420722070310A3330312E3637203436362E32362031372E343820342E343720722070310A3331392E3134203436362E32362031372E34382031362E333720722070310A3333362E3632203436362E32362031372E34382036312E373820722070310A3335342E3130203436362E32362031372E34382035352E303820722070310A3337312E3537203436362E32362031372E343820382E313920722070310A3338392E3035203436362E32362031372E343820302E373420722070310A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3135332E3634203237362E3934203434312E3634203432302E393420636C0A2F707320313020646566204220313020730A3020302030207267620A3330362E3034203430302E31332028486973746F6772616D206F66206A61636B2E736C6F70657329202E352030203020740A2F70732038206465662052203820730A3330362E3034203238372E383620286A61636B2E736C6F70657329202E352030203020740A3136312E3230203335332E3134202844656E7369747929202E35203020393020740A3135332E3634203237362E3934203434312E3634203536342E393420636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A6E700A3139362E3832203331392E3738206D0A3231382E34342030206C0A6F0A6E700A3139362E3832203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3234302E3530203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3238342E3139203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3332372E3838203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3337312E3537203331392E3738206D0A30202D342E3230206C0A6F0A6E700A3431352E3236203331392E3738206D0A30202D342E3230206C0A6F0A2F70732038206465662052203820730A3139362E3832203330342E363620282D332E3029202E352030203020740A3234302E3530203330342E363620282D322E3529202E352030203020740A3238342E3139203330342E363620282D322E3029202E352030203020740A3332372E3838203330342E363620282D312E3529202E352030203020740A3337312E3537203330342E363620282D312E3029202E352030203020740A3431352E3236203330342E363620282D302E3529202E352030203020740A6E700A3138382E3038203332322E3236206D0A302035352E3630206C0A6F0A6E700A3138382E3038203332322E3236206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203333312E3532206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203334302E3739206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203335302E3036206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203335392E3332206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203336382E3539206D0A2D342E32302030206C0A6F0A6E700A3138382E3038203337372E3836206D0A2D342E32302030206C0A6F0A3137382E3030203332322E323620283029202E35203020393020740A3137382E3030203334302E373920283229202E35203020393020740A3137382E3030203335392E333220283429202E35203020393020740A3137382E3030203337372E383620283629202E35203020393020740A3138382E3038203331392E3738203432342E3030203338362E353020636C0A3020302030207267620A302E3735207365746C696E6577696474680A5B5D203020736574646173680A3334302E3939203332322E323620342E33372032302E353920722070310A3334352E3336203332322E323620342E33372034312E313920722070310A3334392E3733203332322E323620342E33372036312E373820722070310A3335342E3130203332322E323620342E33372034312E313920722070310A3335382E3436203332322E323620342E33372032302E353920722070310A65700A2525547261696C65720A252550616765733A20320A2525454F460A>|ps>||||||>
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(boot.slopes)
    </input>

    <\output>
      [1] 0.1943785
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(jack.slopes)
    </input>

    <\output>
      [1] 0.06090926
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sd(jack.slopes)*sqrt(9)
    </input>

    <\output>
      [1] 0.1827278
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  <subsection|Confidence intervals>

  A general rule of thumb says that to estimate the error, 200 bootstrap
  samples are enough. To estimate 95% confidence intervals, one needs around
  1000.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      boot=t( sapply(1:1000,function(i) sample(1:9,rep=T) ) )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      boot.slopes=apply(boot,1,index.slope)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      quantile(boot.slopes,0.025)
    </input>

    <\output>
      \ \ \ \ \ 2.5%\ 

      -1.609121\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      quantile(boot.slopes,0.975)
    </input>

    <\output>
      \ \ \ \ \ 97.5%\ 

      -0.9084386\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  There are actually more acurate methods for calculating confidence
  intervals using quantiles. It can be done with the function bcanon in the
  library bootstrap:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      library(bootstrap)
    </input>

    <\output>
      Error in library(bootstrap) : there is no package called 'bootstrap'
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      install.packages("bootstrap")
    </input>

    <\output>
      Warning in install.packages("bootstrap") : argument 'lib' is missing:
      using /home/michael/lib/R

      \;

      Warning message:

      unable to resolve 'cran.r-mirror.de'.\ 

      Warning: unable to access index for repository
      http://cran.r-mirror.de/src/contrib

      \;

      Warning message:

      no package 'bootstrap' at the repositories in: download.packages(pkgs,
      destdir = tmpd, available = available, \ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      bcanon(1:9,1000,index.slope)
    </input>

    <\output>
      $confpoints

      \ \ \ \ \ alpha \ bca point

      [1,] 0.025 -1.6774194

      [2,] 0.050 -1.5909091

      [3,] 0.100 -1.4782609

      [4,] 0.160 -1.4000000

      [5,] 0.840 -1.0920330

      [6,] 0.900 -1.0520833

      [7,] 0.950 -1.0061728

      [8,] 0.975 -0.9530201

      \;

      $z0

      [1] -0.06521854

      \;

      $acc

      [1] -0.001202818

      \;

      $u

      [1] -1.190476 -1.253133 -1.270270 -1.161359 -1.216667 -1.242038
      -1.117117

      [8] -1.200501 -1.321429

      \;

      $call

      bcanon(x = 1:9, nboot = 1000, theta = index.slope)

      \;

      Warning message:\ 

      multi-argument returns are deprecated in: return(confpoints, z0, acc,
      u, call = call)\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      \;
    </input>
  </session>>

  \;
</body>

<\initial>
  <\collection>
    <associate|language|english>
  </collection>
</initial>

<\references>
  <\collection>
    <associate|auto-1|<tuple|1|?>>
    <associate|auto-2|<tuple|1|?>>
    <associate|auto-3|<tuple|1.1|?>>
    <associate|auto-4|<tuple|1.2|?>>
    <associate|auto-5|<tuple|1.3|?>>
    <associate|auto-6|<tuple|1.4|?>>
    <associate|auto-7|<tuple|1.5|?>>
    <associate|auto-8|<tuple|1.6|?>>
    <associate|toc-1|<tuple|<uninit>|?>>
    <associate|toc-2|<tuple|<uninit>|?>>
    <associate|toc-3|<tuple|<uninit>|?>>
    <associate|toc-4|<tuple|<uninit>|?>>
    <associate|toc-5|<tuple|<uninit>|?>>
    <associate|toc-6|<tuple|<uninit>|?>>
  </collection>
</references>

<\auxiliary>
  <\collection>
    <\associate|toc>
      <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|Lecture
      7 - Bootstrap and Jackknife> <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-1><vspace|0.5fn>

      <with|par-left|<quote|1.5fn>|Example: Median
      <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-2>>

      <with|par-left|<quote|1.5fn>|Parametric bootstrap
      <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-3>>

      <with|par-left|<quote|1.5fn>|Jackknife
      <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-4>>

      <with|par-left|<quote|1.5fn>|Confidence intervals
      <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-5>>

      <with|par-left|<quote|1.5fn>|Permutation tests
      <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
      <no-break><pageref|auto-6>>
    </associate>
  </collection>
</auxiliary>
