<TeXmacs|1.0.6>

<style|generic>

<\body>
  <subsection|Permutation tests>

  Permutation tests are very similar to bootstraps. They test if two
  distributions are the same:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      x=rnorm(10)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      y=rnorm(20)+1
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      mean(x)-mean(y)
    </input>

    <\output>
      [1] -0.7245577
    </output>

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

  In a permutation test, we permute the data, and ask how often it has such a
  difference between the samples:

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      perm=t( sapply( 1:1000, function(i) sample( c(x,y) ) ) )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      perm.diff = apply(perm, 1, function(xy){ mean(xy[1:10])-mean(xy[11:30])
      } )
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sum( abs(perm.diff) \<gtr\> abs((mean(x)-mean(y))) )
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      36/1000
    </input>

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

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

  So this permutation test sees the data as significantly different

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      t.test(x,y)$p.value
    </input>

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

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

  The permutation test tests the hypothesis that the two distributions are
  the same.

  With a bootstrap test, we could do a very similar test, except that we
  sample <strong|with replacement>.

  \;

  <with|prog-language|r|prog-session|default|<\session>
    <\input|r] >
      \;
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      x=runif(30)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      y=x+rnorm(30)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      plot(x,y);v()
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      l=lm(y~x)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      anova(l)
    </input>

    <\output>
      Analysis of Variance Table

      \;

      Response: y

      \;

      \ \ \ \ \ \ \ \ \ \ Df Sum Sq Mean Sq F value Pr(\<gtr\>F)

      x \ \ \ \ \ \ \ \ \ 1 \ 3.970 \ \ 3.970 \ 2.2348 0.1461

      Residuals 28 49.742 \ \ 1.776 \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
    </output>

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

    <\output>
      [1] "Df" \ \ \ \ \ "Sum Sq" \ "Mean Sq" "F value" "Pr(\<gtr\>F)"\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      anova(l)["Sum Sq"]
    </input>

    <\output>
      \ \ \ \ \ \ \ \ \ \ Sum Sq

      x \ \ \ \ \ \ \ \ \ 3.970

      Residuals 49.742
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      anova(l)["x","Sum Sq"]
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      our.test=function(y) {l=lm(y~x);anova(l)["x","Sum Sq"]}
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      our.test(y)
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      perm.y=sapply(1:1000,function(i) sample(y))
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      dim(perm.y)
    </input>

    <\output>
      [1] \ \ 30 1000
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      res=apply(perm.y,2,our.test)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      range(res)
    </input>

    <\output>
      [1] 1.235280e-05 1.821772e+01
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sum(res \<less\>= 3.970052)
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      sum(res \<gtr\> 3.970052)/1000
    </input>

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

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

  <subsection|Plugging some holes>

  <subsubsection|Files>

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      str=read.table("strange.txt",head=T,sep=",")
    </input>

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

    <\output>
      \ \ \ \ x y \ \ \ \ \ \ \ \ \ z

      1 \ \ 1 1 \ 3.8449461

      2 \ \ 2 1 \ 2.9999548

      3 \ \ 3 1 \ 2.2000090

      4 \ \ 4 1 -0.1760195

      5 \ \ 5 1 \ 0.8905869

      6 \ \ 3 2 \ 5.7175075

      7 \ \ 4 2 \ 6.2294734

      8 \ \ 5 2 \ 6.8006919

      9 \ \ 6 2 \ 3.3612630

      10 \ 7 2 \ 3.3244980

      11 \ 5 3 \ 8.6946998

      12 \ 6 3 \ 9.0335607

      13 \ 7 3 \ 8.4194550

      14 \ 8 3 \ 6.4132143

      15 \ 9 3 \ 5.9953834

      16 \ 7 4 12.4814162

      17 \ 8 4 12.4018421

      18 \ 9 4 11.2890104

      19 10 4 \ 8.9024239

      20 11 4 \ 9.3622899

      21 \ 9 5 16.3395314

      22 10 5 16.4536945

      23 11 5 14.5808492

      24 12 5 11.9888531

      25 13 5 11.3470732
    </output>

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

  How to write it back?

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      write.table(str,file="strange2.txt",col.names=T,row.names=F,sep="\\t")
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      ?write.table
    </input>

    <\output>
      write.table \ \ \ \ \ \ \ \ \ \ \ \ \ \ package:base
      \ \ \ \ \ \ \ \ \ \ \ \ \ \ R Documentation

      \;

      Data Output

      \;

      Description:

      \;

      \ \ \ \ \ 'write.table' prints its required argument 'x' (after
      converting

      \ \ \ \ \ it to a data frame if it is not one nor a matrix) to a file
      or

      \ \ \ \ \ connection.

      \;

      Usage:

      \;

      \ \ \ \ \ write.table(x, file = "", append = FALSE, quote = TRUE, sep =
      " ",

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ eol = "\\n", na = "NA", dec = ".",
      row.names = TRUE,

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ col.names = TRUE, qmethod =
      c("escape", "double"))

      \;

      \ \ \ \ \ write.csv(..., col.names = NA, sep = ",", qmethod = "double")

      \ \ \ \ \ write.csv2(..., col.names = NA, dec = ",", sep = ";", qmethod
      = "double")

      \;

      Arguments:

      \;

      \ \ \ \ \ \ \ x: the object to be written, preferably a matrix or data
      frame.

      \ \ \ \ \ \ \ \ \ \ If not, it is attempted to coerce 'x' to a data
      frame.

      \;

      \ \ \ \ file: either a character string naming a file or a connection.
      '""'

      \ \ \ \ \ \ \ \ \ \ indicates output to the console.

      \;

      \ \ append: logical. \ If 'TRUE', the output is appended to the file.
      \ If

      \ \ \ \ \ \ \ \ \ \ 'FALSE', any existing file of the name is
      destroyed.

      \;

      \ \ \ quote: a logical value or a numeric vector. \ If 'TRUE', any

      \ \ \ \ \ \ \ \ \ \ character or factor columns will be surrounded by
      double

      \ \ \ \ \ \ \ \ \ \ quotes. \ If a numeric vector, its elements are
      taken as the

      \ \ \ \ \ \ \ \ \ \ indices of the columns to quote. \ In both cases,
      row and

      \ \ \ \ \ \ \ \ \ \ column names are quoted if they are written. \ If
      'FALSE',

      \ \ \ \ \ \ \ \ \ \ nothing is quoted.

      \;

      \ \ \ \ \ sep: the field separator string. \ Values within each row of
      'x'

      \ \ \ \ \ \ \ \ \ \ are separated by this string.

      \;

      \ \ \ \ \ eol: the character(s) to print at the end of each line (row).

      \;

      \ \ \ \ \ \ na: the string to use for missing values in the data.

      \;

      \ \ \ \ \ dec: the string to use for decimal points in numeric or
      complex

      \ \ \ \ \ \ \ \ \ \ columns: must be a single character.

      \;

      row.names: either a logical value indicating whether the row names of

      \ \ \ \ \ \ \ \ \ \ 'x' are to be written along with 'x', or a
      character vector

      \ \ \ \ \ \ \ \ \ \ of row names to be written.

      \;

      col.names: either a logical value indicating whether the column names

      \ \ \ \ \ \ \ \ \ \ of 'x' are to be written along with 'x', or a
      character

      \ \ \ \ \ \ \ \ \ \ vector of column names to be written.

      \;

      \ qmethod: a character string specifying how to deal with embedded

      \ \ \ \ \ \ \ \ \ \ double quote characters when quoting strings.
      \ Must be one of

      \ \ \ \ \ \ \ \ \ \ '"escape"' (default), in which case the quote
      character is

      \ \ \ \ \ \ \ \ \ \ escaped in C style by a backslash, or '"double"',
      in which

      \ \ \ \ \ \ \ \ \ \ case it is doubled. \ You can specify just the
      initial letter.

      \;

      \ \ \ \ \ ...: further arguments to 'write.table'.

      \;

      Details:

      \;

      \ \ \ \ \ By default there is no column name for a column of row names.
      \ If

      \ \ \ \ \ 'col.names = NA' a blank column name is added. \ This can be
      used

      \ \ \ \ \ to write CSV files for input to spreadsheets. \ 'write.csv'
      and

      \ \ \ \ \ 'write.csv2' provide convenience wrappers for doing so.

      \;

      \ \ \ \ \ If the table has no columns the rownames will be written only
      if

      \ \ \ \ \ 'row.names=TRUE', and _vice versa_.

      \;

      \ \ \ \ \ Real and complex numbers are written to the maximal possible

      \ \ \ \ \ precision.

      \;

      \ \ \ \ \ If a data frame has matrix-like columns these will be
      converted to

      \ \ \ \ \ multiple columns in the result (_via_ 'as.matrix') and so a

      \ \ \ \ \ character 'col.names' or a numeric 'quote' should refer to
      the

      \ \ \ \ \ columns in the result, not the input. \ Such matrix-like
      columns

      \ \ \ \ \ are unquoted by default.

      \;

      \ \ \ \ \ Any columns in a data frame which are lists or have a class
      (e.g.

      \ \ \ \ \ dates) will be converted by the appropriate 'as.character'
      method:

      \ \ \ \ \ such columns are unquoted by default. \ On the other hand,
      any

      \ \ \ \ \ class information for a matrix is discarded.

      \;

      \ \ \ \ \ The 'dec' argument only applies to columns that are not
      subject to

      \ \ \ \ \ conversion to character because they have a class or are part
      of a

      \ \ \ \ \ matrix-like column, in particular to columns protected by
      'I()'.

      \;

      Note:

      \;

      \ \ \ \ \ 'write.table' can be slow for data frames with large numbers

      \ \ \ \ \ (hundreds or more) of columns: this is inevitable as each
      column

      \ \ \ \ \ could be of a different class and so must be handled
      separately.\ 

      \ \ \ \ \ If they are all of the same class, consider using a matrix

      \ \ \ \ \ instead.

      \;

      See Also:

      \;

      \ \ \ \ \ The 'R Data Import/Export' manual.

      \;

      \ \ \ \ \ 'read.table', 'write'.

      \;

      \ \ \ \ \ 'write.matrix' in package 'MASS'.

      \;

      Examples:

      \;

      \ \ \ \ \ ## Not run:\ 

      \ \ \ \ \ ## To write a CSV file for input to Excel one might use

      \ \ \ \ \ x \<less\>- data.frame(a = I("a \\" quote"), b = pi)

      \ \ \ \ \ write.table(x, file = "foo.csv", sep = ",", col.names = NA,

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ qmethod = "double")

      \ \ \ \ \ ## and to read this file back into R one needs

      \ \ \ \ \ read.table("foo.csv", header = TRUE, sep = ",", row.names =
      1)

      \ \ \ \ \ ## NB: you do need to specify a separator if qmethod =
      "double".

      \;

      \ \ \ \ \ ### Alternatively

      \ \ \ \ \ write.csv(x, file = "foo.csv")

      \ \ \ \ \ read.csv("foo.csv", row.names = 1)

      \ \ \ \ \ ## End(Not run)
    </output>

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

  But, we can also save variables in R (this we did see before)

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      save(str,file="strange.Rdata")
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      save(str,file="strange.Rdata",ascii=T)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      save(str,x,y,file="strange.Rdata",ascii=T)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      rm(list=ls())
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      load("strange.Rdata")
    </input>

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

    <\output>
      \ \ \ \ x y \ \ \ \ \ \ \ \ \ z

      1 \ \ 1 1 \ 3.8449461

      2 \ \ 2 1 \ 2.9999548

      3 \ \ 3 1 \ 2.2000090

      4 \ \ 4 1 -0.1760195

      5 \ \ 5 1 \ 0.8905869

      6 \ \ 3 2 \ 5.7175075

      7 \ \ 4 2 \ 6.2294734

      8 \ \ 5 2 \ 6.8006919

      9 \ \ 6 2 \ 3.3612630

      10 \ 7 2 \ 3.3244980

      11 \ 5 3 \ 8.6946998

      12 \ 6 3 \ 9.0335607

      13 \ 7 3 \ 8.4194550

      14 \ 8 3 \ 6.4132143

      15 \ 9 3 \ 5.9953834

      16 \ 7 4 12.4814162

      17 \ 8 4 12.4018421

      18 \ 9 4 11.2890104

      19 10 4 \ 8.9024239

      20 11 4 \ 9.3622899

      21 \ 9 5 16.3395314

      22 10 5 16.4536945

      23 11 5 14.5808492

      24 12 5 11.9888531

      25 13 5 11.3470732
    </output>

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

  Finally, we can also read command from a file

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      source("program.R")
    </input>

    <\output>
      This program will simply print the numbers from 1 to 10

      [1] 1

      [1] 2

      [1] 3

      [1] 4

      [1] 5

      [1] 6

      [1] 7

      [1] 8

      [1] 9

      [1] 10

      Then it will do the same, again

      [1] 1

      [1] 2

      [1] 3

      [1] 4

      [1] 5

      [1] 6

      [1] 7

      [1] 8

      [1] 9

      [1] 10
    </output>

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

<\initial>
  <\collection>
    <associate|language|english>
    <associate|page-bot|1in>
    <associate|page-even|1in>
    <associate|page-odd|1in>
    <associate|page-right|1in>
    <associate|page-top|1in>
    <associate|page-type|letter>
    <associate|par-width|6.5in>
    <associate|sfactor|5>
  </collection>
</initial>

<\references>
  <\collection>
    <associate|auto-1|<tuple|1|1>>
    <associate|auto-2|<tuple|2|3>>
    <associate|auto-3|<tuple|2.1|3>>
    <associate|auto-4|<tuple|1.1.1|?>>
    <associate|auto-5|<tuple|1.2|?>>
    <associate|auto-6|<tuple|1.2.1|?>>
    <associate|auto-7|<tuple|1.3|?>>
    <associate|auto-8|<tuple|1.4|?>>
    <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>|?>>
    <associate|toc-7|<tuple|<uninit>|?>>
    <associate|toc-8|<tuple|<uninit>|?>>
  </collection>
</references>

<\auxiliary>
  <\collection>
    <\associate|toc>
      <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-1>>

      <with|par-left|<quote|1.5fn>|Plugging some holes
      <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|3fn>|Files <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>>
    </associate>
  </collection>
</auxiliary>
