<TeXmacs|1.0.3.2>

<style|generic>

<\body>
  \ 1a. Use the data in the file factorial.txt. Compare the mean of growth
  when the coat is light to the mean when the coat is dark. Is the variance
  in the two cases significantly different? Are the distributions normal?

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

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      a
    </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|>>>
      i=a$coat=="dark"
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      var.test(a$growth[i],a$growth[!i])
    </input>

    <\output>
      \;

      \ \ \ \ \ \ \ \ F test to compare two variances

      \;

      data: \ a$growth[i] and a$growth[!i]\ 

      F = 0.1618, num df = 5, denom df = 5, p-value = 0.06724

      alternative hypothesis: true ratio of variances is not equal to 1\ 

      95 percent confidence interval:

      \ 0.02264239 1.15636435\ 

      sample estimates:

      ratio of variances\ 

      \ \ \ \ \ \ \ \ \ 0.1618112\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      t.test(a$growth[i],a$growth[!i],var.eq=T)
    </input>

    <\output>
      \;

      \ \ \ \ \ \ \ \ Two Sample t-test

      \;

      data: \ a$growth[i] and a$growth[!i]\ 

      t = 2.1765, df = 10, p-value = 0.05457

      alternative hypothesis: true difference in means is not equal to 0\ 

      95 percent confidence interval:

      \ -0.02214314 \ 1.88880980\ 

      sample estimates:

      mean of x mean of y\ 

      \ 8.616667 \ 7.683333\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b=a$growth[i]
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b=b-mean(b)
    </input>

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

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

    <\output>
      \;

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

      \;

      data: \ b\ 

      D = 0.1693, p-value = 0.9954

      alternative hypothesis: two.sided\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      b=a$growth[!i];b=b-mean(b);b=b/sd(b)
    </input>

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

    <\output>
      \;

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

      \;

      data: \ b\ 

      D = 0.19, p-value = 0.9819

      alternative hypothesis: two.sided\ 
    </output>

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

  1b. Do a linear model of growth, that takes into account coat color. Is it
  significantly better than not taking coat color into account? Compare to
  the p-value you got in 1a.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg=lm(growth~coat,data=a)
    </input>

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

    <\output>
      \;

      Call:

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

      \;

      Coefficients:

      (Intercept) \ \ \ coatlight \ 

      \ \ \ \ \ 8.6167 \ \ \ \ \ -0.9333 \ 
    </output>

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

    <\output>
      Analysis of Variance Table

      \;

      Response: growth

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

      coat \ \ \ \ \ \ 1 2.6133 \ 2.6133 \ 4.7372 0.05457 .

      Residuals 10 5.5167 \ 0.5517 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 

      ---

      Signif. codes: \ 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1\ 
    </output>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      anova(reg,reg1)
    </input>

    <\output>
      Analysis of Variance Table

      \;

      Model 1: growth ~ coat

      Model 2: growth ~ 1

      \ \ Res.Df \ \ \ \ RSS Df Sum of Sq \ \ \ \ \ F \ Pr(\<gtr\>F) \ 

      1 \ \ \ \ 10 \ 5.5167 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 

      2 \ \ \ \ 11 \ 8.1300 -1 \ \ -2.6133 4.7372 0.05457 .

      ---

      Signif. codes: \ 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1\ 
    </output>

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

  Using coat is borderline insignificant at a 5% level, and we get exactly
  the same p-value as above.

  \;

  2a. Draw 20 random points from a normal, and another 2 from a normal with
  mean 0.5. Does a t-test see them as significantly different? Does a
  Wilcoxon test see them as significantly different?

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      x=rnorm(20);y=rnorm(20,mean=0.5)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      t.test(x,y,var.eq=T)
    </input>

    <\output>
      \;

      \ \ \ \ \ \ \ \ Two Sample t-test

      \;

      data: \ x and y\ 

      t = -1.1355, df = 38, p-value = 0.2633

      alternative hypothesis: true difference in means is not equal to 0\ 

      95 percent confidence interval:

      \ -1.0247315 \ 0.2882662\ 

      sample estimates:

      mean of x mean of y\ 

      0.1317953 0.5000279\ 
    </output>

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

    <\output>
      \;

      \ \ \ \ \ \ \ \ Wilcoxon rank sum test

      \;

      data: \ x and y\ 

      W = 153, p-value = 0.2110

      alternative hypothesis: true mu is not equal to 0\ 
    </output>

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

  2b. Do the same as you did in 2a 1000 times with the t-test, and 1000 times
  with the Wilcoxon test. Are the success rates of the two tests
  significantly different from each other? try to find at what distance (i.e.
  mean of the second 20 samples) they become different.

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      compare=function(mean){\ 

      \ x=matrix(rnorm(1000*20),1000,20)

      \ y=matrix(rnorm(1000*20,mean=mean),1000,20)

      tp=apply(cbind(x,y),1,function(xy) \ \ \ 

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ t.test(xy[1:20],xy[21:40],var.eq=T)$p.value)

      \ wp=apply(cbind(x,y),1,function(xy)
      wilcox.test(xy[1:20],xy[21:40])$p.value)

      c(sum(tp\<less\>0.05),sum(wp\<less\>0.05))

      }
    </input>

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      prop.test(compare(0.1),n=c(1000,1000))
    </input>

    <\output>
      \;

      \ \ \ \ \ \ \ \ 2-sample test for equality of proportions without
      continuity

      \ \ \ \ \ \ \ \ correction

      \;

      data: \ compare(0.1) out of c(1000, 1000)\ 

      X-squared = 0, df = 1, p-value = 1

      alternative hypothesis: two.sided\ 

      95 percent confidence interval:

      \ -0.02191499 \ 0.02191499\ 

      sample estimates:

      prop 1 prop 2\ 

      \ 0.067 \ 0.067\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      x=sapply(seq(0.01,3,length=20),compare)
    </input>

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

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

      [1,] \ \ 50 \ \ 89 \ 177 \ 296 \ 495 \ 688 \ 853 \ 918 \ 975 \ \ 995
      \ \ 997 \ 1000 \ 1000 \ 1000

      [2,] \ \ 52 \ \ 87 \ 163 \ 284 \ 472 \ 661 \ 825 \ 912 \ 964 \ \ 989
      \ \ 997 \ 1000 \ 1000 \ 1000

      \ \ \ \ \ [,15] [,16] [,17] [,18] [,19] [,20]

      [1,] \ 1000 \ 1000 \ 1000 \ 1000 \ 1000 \ 1000

      [2,] \ 1000 \ 1000 \ 1000 \ 1000 \ 1000 \ 1000
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      plot(x[1,]);points(x[2,],col=2);v()
    </input>

    <\output>
      <postscript|<tuple|<raw-data|%!PS-Adobe-3.0
      EPSF-3.0\n%%DocumentNeededResources: font Helvetica\n%%+ font
      Helvetica-Bold\n%%+ font Helvetica-Oblique\n%%+ font
      Helvetica-BoldOblique\n%%+ font Symbol\n%%Title: R Graphics
      Output\n%%Creator: R Software\n%%Pages: (atend)\n%%BoundingBox: 154 277
      442 565\n%%EndComments\n%%BeginProlog\n/bp \ { gs gs } def\n% begin
      .ps.prolog\n/gs \ { gsave } def\n/gr \ { grestore } def\n/ep \ {
      showpage gr gr } def\n/m \ \ { moveto } def\n/l \ { rlineto } def\n/np
      \ { newpath } def\n/cp \ { closepath } def\n/f \ \ { fill } def\n/o
      \ \ { stroke } def\n/c \ \ { newpath 0 360 arc } def\n/r \ \ { 4 2 roll
      moveto 1 copy 3 -1 roll exch 0 exch rlineto 0 rlineto -1 mul 0 exch
      rlineto closepath } def\n/p1 \ { stroke } def\n/p2 \ { gsave bg
      setrgbcolor fill grestore newpath } def\n/p3 \ { gsave bg setrgbcolor
      fill grestore stroke } def\n/t \ \ { 6 -2 roll moveto gsave rotate\n
      \ \ \ \ \ \ ps mul neg 0 2 1 roll rmoveto\n \ \ \ \ \ \ 1 index
      stringwidth pop\n \ \ \ \ \ \ mul neg 0 rmoveto show grestore }
      def\n/cl \ { grestore gsave newpath 3 index 3 index moveto 1 index\n
      \ \ \ \ \ \ 4 -1 roll lineto \ exch 1 index lineto lineto\n
      \ \ \ \ \ \ closepath clip newpath } def\n/rgb { setrgbcolor } def\n/s
      \ \ { scalefont setfont } def\n/R \ \ { /Font1 findfont } def\n/B \ \ {
      /Font2 findfont } def\n/I \ \ { /Font3 findfont } def\n/BI \ { /Font4
      findfont } def\n/S \ \ { /Font5 findfont } def\n1 setlinecap 1
      setlinejoin\n% end \ \ .ps.prolog\n%%IncludeResource: font
      Helvetica\n/Helvetica findfont\ndup length dict begin\n \ {1 index /FID
      ne {def} {pop pop} ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n
      \ currentdict\n \ end\n/Font1 exch definefont pop\n%%IncludeResource:
      font Helvetica-Bold\n/Helvetica-Bold findfont\ndup length dict begin\n
      \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font2 exch definefont
      pop\n%%IncludeResource: font Helvetica-Oblique\n/Helvetica-Oblique
      findfont\ndup length dict begin\n \ {1 index /FID ne {def} {pop pop}
      ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n \ currentdict\n
      \ end\n/Font3 exch definefont pop\n%%IncludeResource: font
      Helvetica-BoldOblique\n/Helvetica-BoldOblique findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font4 exch definefont
      pop\n%%IncludeResource: font Symbol\n/Symbol findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n
      \ currentdict\n \ end\n/Font5 exch definefont pop\n%%EndProlog\n%%Page:
      2 2\nbp\n202.84 338.14 416.44 515.74 cl\n202.84 338.14 416.44 515.74
      cl\n0 0 0 rgb\n0.75 setlinewidth\n[] 0 setdash\n210.75 344.72 2.25 c
      p1\n221.16 351.47 2.25 c p1\n231.57 366.71 2.25 c p1\n241.98 387.31
      2.25 c p1\n252.39 421.75 2.25 c p1\n262.80 455.16 2.25 c p1\n273.21
      483.72 2.25 c p1\n283.61 494.97 2.25 c p1\n294.02 504.84 2.25 c
      p1\n304.43 508.30 2.25 c p1\n314.84 508.65 2.25 c p1\n325.25 509.17
      2.25 c p1\n335.66 509.17 2.25 c p1\n346.07 509.17 2.25 c p1\n356.48
      509.17 2.25 c p1\n366.89 509.17 2.25 c p1\n377.30 509.17 2.25 c
      p1\n387.71 509.17 2.25 c p1\n398.12 509.17 2.25 c p1\n408.53 509.17
      2.25 c p1\n153.64 276.94 441.64 564.94 cl\n0 0 0 rgb\n0.75
      setlinewidth\n[] 0 setdash\nnp\n252.39 338.14 m\n156.14 -0.00
      l\no\nnp\n252.39 338.14 m\n-0.00 -6.00 l\no\nnp\n304.43 338.14 m\n0.00
      -6.00 l\no\nnp\n356.48 338.14 m\n0.00 -6.00 l\no\nnp\n408.53 338.14
      m\n-0.00 -6.00 l\no\n/ps 12 def R 12 s\n252.39 316.54 (5) .5 0 0
      t\n304.43 316.54 (10) .5 0 0 t\n356.48 316.54 (15) .5 0 0 t\n408.53
      316.54 (20) .5 0 0 t\nnp\n202.84 370.69 m\n0.00 138.48 l\no\nnp\n202.84
      370.69 m\n-6.00 -0.00 l\no\nnp\n202.84 405.31 m\n-6.00 0.00
      l\no\nnp\n202.84 439.93 m\n-6.00 0.00 l\no\nnp\n202.84 474.55 m\n-6.00
      0.00 l\no\nnp\n202.84 509.17 m\n-6.00 0.00 l\no\n188.44 370.69 (200) .5
      0 90 t\n188.44 405.31 (400) .5 0 90 t\n188.44 439.93 (600) .5 0 90
      t\n188.44 474.55 (800) .5 0 90 t\n188.44 509.17 (1000) .5 0 90
      t\nnp\n202.84 338.14 m\n213.60 -0.00 l\n-0.00 177.60 l\n-213.60 0.00
      l\n0.00 -177.60 l\no\n153.64 276.94 441.64 564.94 cl\n/ps 12 def R 12
      s\n0 0 0 rgb\n309.64 292.54 (Index) .5 0 0 t\n164.44 426.94 (x[1, ]) .5
      0 90 t\n202.84 338.14 416.44 515.74 cl\n1 0 0 rgb\n0.75
      setlinewidth\n[] 0 setdash\n210.75 345.07 2.25 c p1\n221.16 351.13 2.25
      c p1\n231.57 364.28 2.25 c p1\n241.98 385.23 2.25 c p1\n252.39 417.77
      2.25 c p1\n262.80 450.49 2.25 c p1\n273.21 478.87 2.25 c p1\n283.61
      493.93 2.25 c p1\n294.02 502.94 2.25 c p1\n304.43 507.26 2.25 c
      p1\n314.84 508.65 2.25 c p1\n325.25 509.17 2.25 c p1\n335.66 509.17
      2.25 c p1\n346.07 509.17 2.25 c p1\n356.48 509.17 2.25 c p1\n366.89
      509.17 2.25 c p1\n377.30 509.17 2.25 c p1\n387.71 509.17 2.25 c
      p1\n398.12 509.17 2.25 c p1\n408.53 509.17 2.25 c
      p1\nep\n%%Trailer\n%%Pages: 2\n%%EOF\n>|ps>||||||>
    </output>

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

  3. Read the file strange.txt. Plot z vs. x. Do a linear regression of z vs.
  x. Does z increase or dercrease with x? Now do an analysis of variance of
  linear models for z. In the best model, does z increase or decrease with x?

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

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg1=lm(z~x,data=a)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      plot(z~x,data=a)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      abline(reg1);v()
    </input>

    <\output>
      <postscript|<tuple|<raw-data|%!PS-Adobe-3.0
      EPSF-3.0\n%%DocumentNeededResources: font Helvetica\n%%+ font
      Helvetica-Bold\n%%+ font Helvetica-Oblique\n%%+ font
      Helvetica-BoldOblique\n%%+ font Symbol\n%%Title: R Graphics
      Output\n%%Creator: R Software\n%%Pages: (atend)\n%%BoundingBox: 154 277
      442 565\n%%EndComments\n%%BeginProlog\n/bp \ { gs gs } def\n% begin
      .ps.prolog\n/gs \ { gsave } def\n/gr \ { grestore } def\n/ep \ {
      showpage gr gr } def\n/m \ \ { moveto } def\n/l \ { rlineto } def\n/np
      \ { newpath } def\n/cp \ { closepath } def\n/f \ \ { fill } def\n/o
      \ \ { stroke } def\n/c \ \ { newpath 0 360 arc } def\n/r \ \ { 4 2 roll
      moveto 1 copy 3 -1 roll exch 0 exch rlineto 0 rlineto -1 mul 0 exch
      rlineto closepath } def\n/p1 \ { stroke } def\n/p2 \ { gsave bg
      setrgbcolor fill grestore newpath } def\n/p3 \ { gsave bg setrgbcolor
      fill grestore stroke } def\n/t \ \ { 6 -2 roll moveto gsave rotate\n
      \ \ \ \ \ \ ps mul neg 0 2 1 roll rmoveto\n \ \ \ \ \ \ 1 index
      stringwidth pop\n \ \ \ \ \ \ mul neg 0 rmoveto show grestore }
      def\n/cl \ { grestore gsave newpath 3 index 3 index moveto 1 index\n
      \ \ \ \ \ \ 4 -1 roll lineto \ exch 1 index lineto lineto\n
      \ \ \ \ \ \ closepath clip newpath } def\n/rgb { setrgbcolor } def\n/s
      \ \ { scalefont setfont } def\n/R \ \ { /Font1 findfont } def\n/B \ \ {
      /Font2 findfont } def\n/I \ \ { /Font3 findfont } def\n/BI \ { /Font4
      findfont } def\n/S \ \ { /Font5 findfont } def\n1 setlinecap 1
      setlinejoin\n% end \ \ .ps.prolog\n%%IncludeResource: font
      Helvetica\n/Helvetica findfont\ndup length dict begin\n \ {1 index /FID
      ne {def} {pop pop} ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n
      \ currentdict\n \ end\n/Font1 exch definefont pop\n%%IncludeResource:
      font Helvetica-Bold\n/Helvetica-Bold findfont\ndup length dict begin\n
      \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font2 exch definefont
      pop\n%%IncludeResource: font Helvetica-Oblique\n/Helvetica-Oblique
      findfont\ndup length dict begin\n \ {1 index /FID ne {def} {pop pop}
      ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n \ currentdict\n
      \ end\n/Font3 exch definefont pop\n%%IncludeResource: font
      Helvetica-BoldOblique\n/Helvetica-BoldOblique findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font4 exch definefont
      pop\n%%IncludeResource: font Symbol\n/Symbol findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n
      \ currentdict\n \ end\n/Font5 exch definefont pop\n%%EndProlog\n%%Page:
      2 2\nbp\n202.84 338.14 416.44 515.74 cl\n202.84 338.14 416.44 515.74
      cl\n0 0 0 rgb\n0.75 setlinewidth\n[] 0 setdash\n210.75 384.48 2.25 c
      p1\n227.23 376.13 2.25 c p1\n243.71 368.22 2.25 c p1\n260.19 344.72
      2.25 c p1\n276.67 355.27 2.25 c p1\n243.71 403.00 2.25 c p1\n260.19
      408.06 2.25 c p1\n276.67 413.71 2.25 c p1\n293.16 379.70 2.25 c
      p1\n309.64 379.34 2.25 c p1\n276.67 432.44 2.25 c p1\n293.16 435.79
      2.25 c p1\n309.64 429.72 2.25 c p1\n326.12 409.88 2.25 c p1\n342.60
      405.75 2.25 c p1\n309.64 469.89 2.25 c p1\n326.12 469.10 2.25 c
      p1\n342.60 458.10 2.25 c p1\n359.08 434.50 2.25 c p1\n375.56 439.04
      2.25 c p1\n342.60 508.04 2.25 c p1\n359.08 509.17 2.25 c p1\n375.56
      490.65 2.25 c p1\n392.05 465.02 2.25 c p1\n408.53 458.67 2.25 c
      p1\n153.64 276.94 441.64 564.94 cl\n0 0 0 rgb\n0.75 setlinewidth\n[] 0
      setdash\nnp\n227.23 338.14 m\n164.82 -0.00 l\no\nnp\n227.23 338.14
      m\n-0.00 -6.00 l\no\nnp\n260.19 338.14 m\n-0.00 -6.00 l\no\nnp\n293.16
      338.14 m\n0.00 -6.00 l\no\nnp\n326.12 338.14 m\n0.00 -6.00
      l\no\nnp\n359.08 338.14 m\n-0.00 -6.00 l\no\nnp\n392.05 338.14 m\n0.00
      -6.00 l\no\n/ps 12 def R 12 s\n227.23 316.54 (2) .5 0 0 t\n260.19
      316.54 (4) .5 0 0 t\n293.16 316.54 (6) .5 0 0 t\n326.12 316.54 (8) .5 0
      0 t\n359.08 316.54 (10) .5 0 0 t\n392.05 316.54 (12) .5 0 0
      t\nnp\n202.84 346.46 m\n0.00 148.33 l\no\nnp\n202.84 346.46 m\n-6.00
      -0.00 l\no\nnp\n202.84 395.91 m\n-6.00 0.00 l\no\nnp\n202.84 445.35
      m\n-6.00 0.00 l\no\nnp\n202.84 494.79 m\n-6.00 0.00 l\no\n188.44 346.46
      (0) .5 0 90 t\n188.44 395.91 (5) .5 0 90 t\n188.44 445.35 (10) .5 0 90
      t\n188.44 494.79 (15) .5 0 90 t\nnp\n202.84 338.14 m\n213.60 -0.00
      l\n-0.00 177.60 l\n-213.60 0.00 l\n0.00 -177.60 l\no\n153.64 276.94
      441.64 564.94 cl\n/ps 12 def R 12 s\n0 0 0 rgb\n309.64 292.54 (x) .5 0
      0 t\n164.44 426.94 (z) .5 0 90 t\n202.84 338.14 416.44 515.74 cl\n0 0 0
      rgb\n0.75 setlinewidth\n[] 0 setdash\nnp\n202.84 360.32 m\n213.60
      129.63 l\no\nep\n%%Trailer\n%%Pages: 2\n%%EOF\n>|ps>||||||>
    </output>

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

  There seems to be a positive slope

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

    <\output>
      \;

      Call:

      lm(formula = z ~ x, data = a)

      \;

      Coefficients:

      (Intercept) \ \ \ \ \ \ \ \ \ \ \ x \ 

      \ \ \ \ \ 0.8757 \ \ \ \ \ \ 1.0115 \ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg2=aov(z~x*y,data=a)
    </input>

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

    <\output>
      Analysis of Variance Table

      \;

      Response: z

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

      x \ \ \ \ \ \ \ \ \ 1 255.761 255.761 343.5759 1.706e-14 ***

      y \ \ \ \ \ \ \ \ \ 1 247.596 247.596 332.6085 2.353e-14 ***

      x:y \ \ \ \ \ \ \ 1 \ \ 0.063 \ \ 0.063 \ \ 0.0849 \ \ \ 0.7736 \ \ \ 

      Residuals 21 \ 15.633 \ \ 0.744 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 

      ---

      Signif. codes: \ 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg3=update(reg2,~.-x:y)
    </input>

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

    <\output>
      Analysis of Variance Table

      \;

      Response: z

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

      x \ \ \ \ \ \ \ \ \ 1 255.761 255.761 \ 358.49 4.174e-15 ***

      y \ \ \ \ \ \ \ \ \ 1 247.596 247.596 \ 347.04 5.845e-15 ***

      Residuals 22 \ 15.696 \ \ 0.713 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 

      ---

      Signif. codes: \ 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1\ 
    </output>

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

  both seem significant, so we are left with x and y.

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

    <\output>
      Call:

      \ \ \ aov(formula = z ~ x + y, data = a)

      \;

      Terms:

      \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ x \ \ \ \ \ \ \ \ y
      Residuals

      Sum of Squares \ 255.76053 247.59632 \ 15.69579

      Deg. of Freedom \ \ \ \ \ \ \ \ 1 \ \ \ \ \ \ \ \ 1 \ \ \ \ \ \ \ 22

      \;

      Residual standard error: 0.8446567\ 

      Estimated effects may be unbalanced
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      reg3=lm(z~x+y,data=a)
    </input>

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

    <\output>
      \;

      Call:

      lm(formula = z ~ x + y, data = a)

      \;

      Coefficients:

      (Intercept) \ \ \ \ \ \ \ \ \ \ \ x \ \ \ \ \ \ \ \ \ \ \ y \ 

      \ \ \ \ -0.1195 \ \ \ \ \ -0.9789 \ \ \ \ \ \ 4.9759 \ 
    </output>

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

  Now the slope as a function of x is negative!

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

    <\output>
      \ \ \ \ \ \ \ \ \ \ 1 \ \ \ \ \ \ \ \ \ \ 2 \ \ \ \ \ \ \ \ \ \ 3
      \ \ \ \ \ \ \ \ \ \ 4 \ \ \ \ \ \ \ \ \ \ 5 \ \ \ \ \ \ \ \ \ \ 6\ 

      \ 3.87747765 \ 2.89857105 \ 1.91966445 \ 0.94075786 -0.03814874
      \ 6.89556959\ 

      \ \ \ \ \ \ \ \ \ \ 7 \ \ \ \ \ \ \ \ \ \ 8 \ \ \ \ \ \ \ \ \ \ 9
      \ \ \ \ \ \ \ \ \ 10 \ \ \ \ \ \ \ \ \ 11 \ \ \ \ \ \ \ \ \ 12\ 

      \ 5.91666299 \ 4.93775639 \ 3.95884979 \ 2.97994319 \ 9.91366152
      \ 8.93475492\ 

      \ \ \ \ \ \ \ \ \ 13 \ \ \ \ \ \ \ \ \ 14 \ \ \ \ \ \ \ \ \ 15
      \ \ \ \ \ \ \ \ \ 16 \ \ \ \ \ \ \ \ \ 17 \ \ \ \ \ \ \ \ \ 18\ 

      \ 7.95584832 \ 6.97694172 \ 5.99803512 12.93175346 11.95284686
      10.97394026\ 

      \ \ \ \ \ \ \ \ \ 19 \ \ \ \ \ \ \ \ \ 20 \ \ \ \ \ \ \ \ \ 21
      \ \ \ \ \ \ \ \ \ 22 \ \ \ \ \ \ \ \ \ 23 \ \ \ \ \ \ \ \ \ 24\ 

      \ 9.99503366 \ 9.01612706 15.94984539 14.97093879 13.99203219
      13.01312559\ 

      \ \ \ \ \ \ \ \ \ 25\ 

      12.03421899\ 
    </output>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      plot(z~x,data=a)
    </input>

    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      points(predict(reg3)~x,data=a,col=2);v()
    </input>

    <\output>
      <postscript|<tuple|<raw-data|%!PS-Adobe-3.0
      EPSF-3.0\n%%DocumentNeededResources: font Helvetica\n%%+ font
      Helvetica-Bold\n%%+ font Helvetica-Oblique\n%%+ font
      Helvetica-BoldOblique\n%%+ font Symbol\n%%Title: R Graphics
      Output\n%%Creator: R Software\n%%Pages: (atend)\n%%BoundingBox: 154 277
      442 565\n%%EndComments\n%%BeginProlog\n/bp \ { gs gs } def\n% begin
      .ps.prolog\n/gs \ { gsave } def\n/gr \ { grestore } def\n/ep \ {
      showpage gr gr } def\n/m \ \ { moveto } def\n/l \ { rlineto } def\n/np
      \ { newpath } def\n/cp \ { closepath } def\n/f \ \ { fill } def\n/o
      \ \ { stroke } def\n/c \ \ { newpath 0 360 arc } def\n/r \ \ { 4 2 roll
      moveto 1 copy 3 -1 roll exch 0 exch rlineto 0 rlineto -1 mul 0 exch
      rlineto closepath } def\n/p1 \ { stroke } def\n/p2 \ { gsave bg
      setrgbcolor fill grestore newpath } def\n/p3 \ { gsave bg setrgbcolor
      fill grestore stroke } def\n/t \ \ { 6 -2 roll moveto gsave rotate\n
      \ \ \ \ \ \ ps mul neg 0 2 1 roll rmoveto\n \ \ \ \ \ \ 1 index
      stringwidth pop\n \ \ \ \ \ \ mul neg 0 rmoveto show grestore }
      def\n/cl \ { grestore gsave newpath 3 index 3 index moveto 1 index\n
      \ \ \ \ \ \ 4 -1 roll lineto \ exch 1 index lineto lineto\n
      \ \ \ \ \ \ closepath clip newpath } def\n/rgb { setrgbcolor } def\n/s
      \ \ { scalefont setfont } def\n/R \ \ { /Font1 findfont } def\n/B \ \ {
      /Font2 findfont } def\n/I \ \ { /Font3 findfont } def\n/BI \ { /Font4
      findfont } def\n/S \ \ { /Font5 findfont } def\n1 setlinecap 1
      setlinejoin\n% end \ \ .ps.prolog\n%%IncludeResource: font
      Helvetica\n/Helvetica findfont\ndup length dict begin\n \ {1 index /FID
      ne {def} {pop pop} ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n
      \ currentdict\n \ end\n/Font1 exch definefont pop\n%%IncludeResource:
      font Helvetica-Bold\n/Helvetica-Bold findfont\ndup length dict begin\n
      \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font2 exch definefont
      pop\n%%IncludeResource: font Helvetica-Oblique\n/Helvetica-Oblique
      findfont\ndup length dict begin\n \ {1 index /FID ne {def} {pop pop}
      ifelse} forall\n \ /Encoding ISOLatin1Encoding def\n \ currentdict\n
      \ end\n/Font3 exch definefont pop\n%%IncludeResource: font
      Helvetica-BoldOblique\n/Helvetica-BoldOblique findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n \ /Encoding
      ISOLatin1Encoding def\n \ currentdict\n \ end\n/Font4 exch definefont
      pop\n%%IncludeResource: font Symbol\n/Symbol findfont\ndup length dict
      begin\n \ {1 index /FID ne {def} {pop pop} ifelse} forall\n
      \ currentdict\n \ end\n/Font5 exch definefont pop\n%%EndProlog\n%%Page:
      2 2\nbp\n202.84 338.14 416.44 515.74 cl\n202.84 338.14 416.44 515.74
      cl\n0 0 0 rgb\n0.75 setlinewidth\n[] 0 setdash\n210.75 384.48 2.25 c
      p1\n227.23 376.13 2.25 c p1\n243.71 368.22 2.25 c p1\n260.19 344.72
      2.25 c p1\n276.67 355.27 2.25 c p1\n243.71 403.00 2.25 c p1\n260.19
      408.06 2.25 c p1\n276.67 413.71 2.25 c p1\n293.16 379.70 2.25 c
      p1\n309.64 379.34 2.25 c p1\n276.67 432.44 2.25 c p1\n293.16 435.79
      2.25 c p1\n309.64 429.72 2.25 c p1\n326.12 409.88 2.25 c p1\n342.60
      405.75 2.25 c p1\n309.64 469.89 2.25 c p1\n326.12 469.10 2.25 c
      p1\n342.60 458.10 2.25 c p1\n359.08 434.50 2.25 c p1\n375.56 439.04
      2.25 c p1\n342.60 508.04 2.25 c p1\n359.08 509.17 2.25 c p1\n375.56
      490.65 2.25 c p1\n392.05 465.02 2.25 c p1\n408.53 458.67 2.25 c
      p1\n153.64 276.94 441.64 564.94 cl\n0 0 0 rgb\n0.75 setlinewidth\n[] 0
      setdash\nnp\n227.23 338.14 m\n164.82 -0.00 l\no\nnp\n227.23 338.14
      m\n-0.00 -6.00 l\no\nnp\n260.19 338.14 m\n-0.00 -6.00 l\no\nnp\n293.16
      338.14 m\n0.00 -6.00 l\no\nnp\n326.12 338.14 m\n0.00 -6.00
      l\no\nnp\n359.08 338.14 m\n-0.00 -6.00 l\no\nnp\n392.05 338.14 m\n0.00
      -6.00 l\no\n/ps 12 def R 12 s\n227.23 316.54 (2) .5 0 0 t\n260.19
      316.54 (4) .5 0 0 t\n293.16 316.54 (6) .5 0 0 t\n326.12 316.54 (8) .5 0
      0 t\n359.08 316.54 (10) .5 0 0 t\n392.05 316.54 (12) .5 0 0
      t\nnp\n202.84 346.46 m\n0.00 148.33 l\no\nnp\n202.84 346.46 m\n-6.00
      -0.00 l\no\nnp\n202.84 395.91 m\n-6.00 0.00 l\no\nnp\n202.84 445.35
      m\n-6.00 0.00 l\no\nnp\n202.84 494.79 m\n-6.00 0.00 l\no\n188.44 346.46
      (0) .5 0 90 t\n188.44 395.91 (5) .5 0 90 t\n188.44 445.35 (10) .5 0 90
      t\n188.44 494.79 (15) .5 0 90 t\nnp\n202.84 338.14 m\n213.60 -0.00
      l\n-0.00 177.60 l\n-213.60 0.00 l\n0.00 -177.60 l\no\n153.64 276.94
      441.64 564.94 cl\n/ps 12 def R 12 s\n0 0 0 rgb\n309.64 292.54 (x) .5 0
      0 t\n164.44 426.94 (z) .5 0 90 t\n202.84 338.14 416.44 515.74 cl\n1 0 0
      rgb\n0.75 setlinewidth\n[] 0 setdash\n210.75 384.81 2.25 c p1\n227.23
      375.13 2.25 c p1\n243.71 365.45 2.25 c p1\n260.19 355.77 2.25 c
      p1\n276.67 346.09 2.25 c p1\n243.71 414.65 2.25 c p1\n260.19 404.97
      2.25 c p1\n276.67 395.29 2.25 c p1\n293.16 385.61 2.25 c p1\n309.64
      375.93 2.25 c p1\n276.67 444.50 2.25 c p1\n293.16 434.82 2.25 c
      p1\n309.64 425.14 2.25 c p1\n326.12 415.46 2.25 c p1\n342.60 405.78
      2.25 c p1\n309.64 474.34 2.25 c p1\n326.12 464.66 2.25 c p1\n342.60
      454.98 2.25 c p1\n359.08 445.30 2.25 c p1\n375.56 435.62 2.25 c
      p1\n342.60 504.18 2.25 c p1\n359.08 494.50 2.25 c p1\n375.56 484.82
      2.25 c p1\n392.05 475.14 2.25 c p1\n408.53 465.46 2.25 c
      p1\nep\n%%Trailer\n%%Pages: 2\n%%EOF\n>|ps>||||||>
    </output>

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

  \;
</body>

<\initial>
  <\collection>
    <associate|page-even|30mm>
    <associate|page-reduce-bot|15mm>
    <associate|page-reduce-right|25mm>
    <associate|page-reduce-left|25mm>
    <associate|page-type|a4>
    <associate|page-top|30mm>
    <associate|page-right|30mm>
    <associate|par-width|150mm>
    <associate|page-odd|30mm>
    <associate|page-bot|30mm>
    <associate|language|english>
    <associate|page-reduce-top|15mm>
  </collection>
</initial>
