<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR</title><revhistory><revision><revnumber>12</revnumber><date>2015-05-03 06:24:36</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>11</revnumber><date>2015-05-03 06:21:32</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>10</revnumber><date>2015-05-03 05:53:55</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>9</revnumber><date>2015-05-03 05:51:33</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>8</revnumber><date>2015-05-02 09:03:10</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>7</revnumber><date>2015-05-02 08:50:24</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>6</revnumber><date>2015-05-02 08:37:42</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>5</revnumber><date>2015-05-02 08:32:48</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>4</revnumber><date>2015-05-02 08:24:46</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>3</revnumber><date>2015-05-02 08:21:09</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>2</revnumber><date>2015-05-02 08:13:10</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision><revision><revnumber>1</revnumber><date>2015-05-02 08:03:17</date><authorinitials>mandy.vogel@googlemail.com</authorinitials></revision></revhistory></articleinfo><section><title>Classical Tests</title><section><title>Exercises</title><itemizedlist><listitem><para>load the data (file: session4data.rdata) </para></listitem><listitem><para>make a new summary data frame (per subject and time) containing: </para><itemizedlist><listitem><para>the number of trials </para></listitem><listitem><para>the number correct trials (absolute and relative) </para></listitem><listitem><para>the mean TTime and the standard deviation of TTime </para></listitem><listitem><para>the respective standard error of the mean </para></listitem></itemizedlist></listitem><listitem><para>keep the information about Sex and Age_PRETEST </para></listitem><listitem><para>make a plot with time on the x-axis and TTime on the y-axis showing the means and the 95\% confidence intervals (geom_pointrange()) </para></listitem><listitem><para>add the number of trials and the percentage of correct ones using geom_text() </para></listitem></itemizedlist></section><section><title>Exercises - Solutions</title><itemizedlist><listitem><para>load the data (file: session4data.rdata) </para></listitem><listitem><para>make a new summary data frame (per subject and time) containing: </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[sumdf]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[data]]></methodname><![CDATA[ %>%]]>
<![CDATA[+     ]]><methodname><![CDATA[group_by]]></methodname><![CDATA[(]]><methodname><![CDATA[Subject]]></methodname><![CDATA[,]]><methodname><![CDATA[Sex]]></methodname><![CDATA[,]]><methodname><![CDATA[Age_PRETEST]]></methodname><![CDATA[,]]><methodname><![CDATA[testid]]></methodname><![CDATA[) %>%]]>
<![CDATA[+     ]]><methodname><![CDATA[summarise]]></methodname><![CDATA[(]]><methodname><![CDATA[count]]></methodname><![CDATA[=]]><methodname><![CDATA[n]]></methodname><![CDATA[(),]]>
<![CDATA[+               ]]><methodname><![CDATA[n.corr]]></methodname><![CDATA[ = ]]><methodname><![CDATA[sum]]></methodname><![CDATA[(]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[hit"]]></phrase><![CDATA[),]]>
<![CDATA[+               ]]><methodname><![CDATA[perc.corr]]></methodname><![CDATA[ = ]]><methodname><![CDATA[n.corr]]></methodname><![CDATA[/]]><methodname><![CDATA[count]]></methodname><![CDATA[,]]>
<![CDATA[+               ]]><methodname><![CDATA[mean.ttime]]></methodname><![CDATA[ = ]]><methodname><![CDATA[mean]]></methodname><![CDATA[(]]><methodname><![CDATA[TTime]]></methodname><![CDATA[),]]>
<![CDATA[+               ]]><methodname><![CDATA[sd.ttime]]></methodname><![CDATA[ = ]]><methodname><![CDATA[sd]]></methodname><![CDATA[(]]><methodname><![CDATA[TTime]]></methodname><![CDATA[),]]>
<![CDATA[+               ]]><methodname><![CDATA[se.ttime]]></methodname><![CDATA[ = ]]><methodname><![CDATA[sd.ttime]]></methodname><![CDATA[/]]><methodname><![CDATA[sqrt]]></methodname><![CDATA[(]]><methodname><![CDATA[count]]></methodname><![CDATA[))]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[sumdf]]></methodname><![CDATA[)]]>
<methodname><![CDATA[Subject]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sex]]></methodname><![CDATA[ ]]><methodname><![CDATA[Age_PRETEST]]></methodname><![CDATA[ ]]><methodname><![CDATA[testid]]></methodname><![CDATA[ ]]><methodname><![CDATA[count]]></methodname><![CDATA[ ]]><methodname><![CDATA[n.corr]]></methodname><![CDATA[ ]]><methodname><![CDATA[perc.corr]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean.ttime]]></methodname><![CDATA[ ]]>
<![CDATA[1       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11  ]]><methodname><![CDATA[test1]]></methodname><![CDATA[    95     63 0.6631579   8621.674 ]]>
<![CDATA[2       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11      1    60     32 0.5333333   9256.367 ]]>
<![CDATA[3       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11      2    59     32 0.5423729   9704.712 ]]>
<![CDATA[4       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11      3    60     38 0.6333333  14189.550 ]]>
<![CDATA[5       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11      4    59     31 0.5254237  13049.831 ]]>
<![CDATA[6       1   ]]><methodname><![CDATA[f]]></methodname><![CDATA[        3.11      5    59     33 0.5593220  14673.525 ]]>
<methodname><![CDATA[Variables]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[shown]]></methodname><![CDATA[: ]]><methodname><![CDATA[sd.ttime]]></methodname><![CDATA[ ]]><methodname><![CDATA[se.ttime ]]></methodname><![CDATA[(]]><methodname><![CDATA[dbl]]></methodname><![CDATA[)  ]]>
</programlisting></section><section><title>four possible situations</title><informaltable><tgroup cols="4"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><colspec colname="col_3"/><tbody><row rowsep="1"><entry align="center" colsep="1" nameend="col_1" namest="col_0" rowsep="1"/><entry colsep="1" rowsep="1"><para>Situation </para></entry><entry colsep="1" rowsep="1"/></row><row rowsep="1"><entry align="center" colsep="1" nameend="col_1" namest="col_0" rowsep="1"/><entry colsep="1" rowsep="1"><para>H_0 is true </para></entry><entry colsep="1" rowsep="1"><para>H_0 is false </para></entry></row><row rowsep="1"><entry colsep="1" morerows="1" rowsep="1"><para>Conclusion</para></entry><entry colsep="1" rowsep="1"><para>H_0 is not rejected </para></entry><entry colsep="1" rowsep="1"><para> Correct decision </para></entry><entry colsep="1" rowsep="1"><para>Type II error </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>H_0 is rejected </para></entry><entry colsep="1" rowsep="1"><para>Type I error </para></entry><entry colsep="1" rowsep="1"><para> Correct decision </para></entry></row></tbody></tgroup></informaltable></section><section><title>Common symbols</title><informaltable><tgroup cols="2"><colspec colname="col_0"/><colspec colname="col_1"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para>n </para></entry><entry colsep="1" rowsep="1"><para>number of observations (sample size)</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>K </para></entry><entry colsep="1" rowsep="1"><para>number of samples (each having n elements)</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>alpha </para></entry><entry colsep="1" rowsep="1"><para>level of significance </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>nu </para></entry><entry colsep="1" rowsep="1"><para>degrees of freedom</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>mu </para></entry><entry colsep="1" rowsep="1"><para>population mean</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>xbar </para></entry><entry colsep="1" rowsep="1"><para>sample mean</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>sigma </para></entry><entry colsep="1" rowsep="1"><para>standard deviation (population)</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>s </para></entry><entry colsep="1" rowsep="1"><para>standard deviation (sample)</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>rho </para></entry><entry colsep="1" rowsep="1"><para>population correlation coefficient</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>r </para></entry><entry colsep="1" rowsep="1"><para>sample correlation coefficient</para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>Z </para></entry><entry colsep="1" rowsep="1"><para>standard normal deviate </para></entry></row></tbody></tgroup></informaltable></section><section><title>Alternatives</title><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=twosided.pdf"><!--transclusion is not implemented in DocBook formatter-->attachment:twosided.pdf<!--transclusion is not implemented in DocBook formatter--></ulink>  </para><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=greater.pdf"><!--transclusion is not implemented in DocBook formatter-->attachment:greater.pdf<!--transclusion is not implemented in DocBook formatter--></ulink> </para><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=less.pdf"><!--transclusion is not implemented in DocBook formatter-->attachment:less.pdf<!--transclusion is not implemented in DocBook formatter--></ulink> </para><para>The p-value is the probability of the sample estimate (of the respective estimator) under the null. The p-value is NOT the probability that the null is true. </para></section><section><title>Z-test for a population mean</title><para>The z-test is a something like a t-test (it is like you would know almost everything about the perfect conditions. It uses the normal distribution as distribution of the test statistic and is therefore a good example. </para><itemizedlist><listitem><para>To investigate the significance of the difference between an assumed population mean  </para></listitem></itemizedlist><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_c48699a82aa75bd42687a9b18ace5deca0dcc82c_p1.png"/></imageobject><textobject><phrase>$\mu_0$</phrase></textobject></inlinemediaobject></para><para> and a sample mean  </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_c4afc14526d2aa94109c035274a1fb703efaf13a_p1.png"/></imageobject><textobject><phrase>$\bar{x}$</phrase></textobject></inlinemediaobject></para><para>It is necessary that the population variance  </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_50c5bb18777fbdb3d09e3589581897ad4b809c01_p1.png"/></imageobject><textobject><phrase>$\sigma^2$ </phrase></textobject></inlinemediaobject></para><para> is known. </para><itemizedlist><listitem><para>The test is accurate if the population values are normally distributed. If the population values are not normal, the test will still give an approximate guide. </para></listitem></itemizedlist></section><section><title>Excercise</title><itemizedlist><listitem><para>Write a function which takes a vector, the population standard deviation and the population mean as arguments and which gives the Z score as result.  </para><itemizedlist><listitem><para>name the function ztest or my.z.test - not z.test because z.test is already used </para></listitem><listitem><para>set a default value for the population mean </para></listitem></itemizedlist></listitem><listitem><para>add a line to your function that allows you to process numeric vectors containing missing values! </para></listitem><listitem><para>the function pnorm(Z) gives the probability of  </para></listitem></itemizedlist><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_942b8e74a8c6f1644260daede97e6a7fd94908c9_p1.png"/></imageobject><textobject><phrase>$$x \leq Z$$ </phrase></textobject></inlinemediaobject></para><para> Change your function so that it includes the p-value (for a two sided test) as result. </para><itemizedlist><listitem><para>now let the result be a named vector containing the estimated difference, Z, p and the n. </para></listitem></itemizedlist><para>You can always test your function using simulated values: rnorm(100,mean=0) gives you a vector containing 100 normal distributed values with mean 0. </para><section><title>Solutions</title><para>Write a function which takes a vector, the population standard deviation and the population mean as arguments and which gives the Z score as result. </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=0){]]>
<![CDATA[+     ]]><methodname><![CDATA[sqrt]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)) * (]]><methodname><![CDATA[mean]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)-]]><methodname><![CDATA[mu]]></methodname><![CDATA[)/]]><methodname><![CDATA[x.sd]]></methodname>
<![CDATA[+ }]]>
<![CDATA[> ]]><methodname><![CDATA[set.seed]]></methodname><![CDATA[(1)]]>
<![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[ = 1)]]>
<methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[ 1.088874]]>
</programlisting><para>Add a line to your function that allows you to also process numeric vectors containing missing values! </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=0){]]>
<![CDATA[+     ]]><methodname><![CDATA[x]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[x]]></methodname><methodname><![CDATA[[]]></methodname><![CDATA[!]]><methodname><![CDATA[is.na]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)]]><methodname><![CDATA[]]]></methodname>
<![CDATA[+     ]]><methodname><![CDATA[if]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) < 3) ]]><methodname><![CDATA[stop]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[too few values in x"]]></phrase><![CDATA[)]]>
<![CDATA[+     ]]><methodname><![CDATA[sqrt]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)) * (]]><methodname><![CDATA[mean]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)-]]><methodname><![CDATA[mu]]></methodname><![CDATA[)/]]><methodname><![CDATA[x.sd]]></methodname>
<![CDATA[+ }]]>
</programlisting><para>The function pnorm(Z) gives the probability of  </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_942b8e74a8c6f1644260daede97e6a7fd94908c9_p1.png"/></imageobject><textobject><phrase>$$x \leq Z$$ </phrase></textobject></inlinemediaobject></para><para> . Change your function so that it has the p-value (for a two sided test) as result. </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=0){]]>
<![CDATA[+     ]]><methodname><![CDATA[x]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[x]]></methodname><methodname><![CDATA[[]]></methodname><![CDATA[!]]><methodname><![CDATA[is.na]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)]]><methodname><![CDATA[]]]></methodname>
<![CDATA[+     ]]><methodname><![CDATA[if]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) < 3) ]]><methodname><![CDATA[stop]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[too few values in x"]]></phrase><![CDATA[)]]>
<![CDATA[+     ]]><methodname><![CDATA[z]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[sqrt]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)) * (]]><methodname><![CDATA[mean]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)-]]><methodname><![CDATA[mu]]></methodname><![CDATA[)/]]><methodname><![CDATA[x.sd]]></methodname>
<![CDATA[+     2*]]><methodname><![CDATA[pnorm]]></methodname><![CDATA[(-]]><methodname><![CDATA[abs]]></methodname><![CDATA[(]]><methodname><![CDATA[z]]></methodname><![CDATA[))]]>
<![CDATA[+ }]]>
<![CDATA[> ]]><methodname><![CDATA[set.seed]]></methodname><![CDATA[(1)]]>
<![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[ = 1)]]>
<methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[ 0.2762096]]>
</programlisting><para>Now let the result be a named vector containing the estimated difference, Z, p and the n. </para><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=0){]]>
<![CDATA[+     ]]><methodname><![CDATA[x]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[x]]></methodname><methodname><![CDATA[[]]></methodname><![CDATA[!]]><methodname><![CDATA[is.na]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)]]><methodname><![CDATA[]]]></methodname>
<![CDATA[+     ]]><methodname><![CDATA[if]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) < 3) ]]><methodname><![CDATA[stop]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[too few values in x"]]></phrase><![CDATA[)]]>
<![CDATA[+     ]]><methodname><![CDATA[est.diff]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[mean]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)-]]><methodname><![CDATA[mu]]></methodname>
<![CDATA[+     ]]><methodname><![CDATA[z]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[sqrt]]></methodname><![CDATA[(]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)) * (]]><methodname><![CDATA[est.diff]]></methodname><![CDATA[)/]]><methodname><![CDATA[x.sd]]></methodname>
<![CDATA[+     ]]><methodname><![CDATA[round]]></methodname><![CDATA[(]]><methodname><![CDATA[c]]></methodname><![CDATA[(]]><methodname><![CDATA[diff]]></methodname><![CDATA[=]]><methodname><![CDATA[est.diff]]></methodname><![CDATA[,]]><methodname><![CDATA[Z]]></methodname><![CDATA[=]]><methodname><![CDATA[z]]></methodname><![CDATA[,]]><methodname><![CDATA[pval]]></methodname><![CDATA[=2*]]><methodname><![CDATA[pnorm]]></methodname><![CDATA[(-]]><methodname><![CDATA[abs]]></methodname><![CDATA[(]]><methodname><![CDATA[z]]></methodname><![CDATA[)),]]><methodname><![CDATA[n]]></methodname><![CDATA[=]]><methodname><![CDATA[length]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[)),4)]]>
<![CDATA[+ }]]>
<![CDATA[> ]]><methodname><![CDATA[set.seed]]></methodname><![CDATA[(1)]]>
<![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[ = 1)]]>
<![CDATA[    ]]><methodname><![CDATA[diff]]></methodname><![CDATA[        ]]><methodname><![CDATA[Z]]></methodname><![CDATA[     ]]><methodname><![CDATA[pval]]></methodname><![CDATA[        ]]><methodname><![CDATA[n]]></methodname><![CDATA[ ]]>
<![CDATA[  0.1089   1.0889   0.2762 100.0000 ]]>
</programlisting></section><section><title>Requirements</title><itemizedlist><listitem><para>Z-test for two population means (variances known and equal) </para></listitem><listitem><para>Z-test for two population means (variances known and unequal) </para></listitem></itemizedlist><para>To investigate the statistical significance of the difference between an assumed population mean  </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_c48699a82aa75bd42687a9b18ace5deca0dcc82c_p1.png"/></imageobject><textobject><phrase>$\mu_0$</phrase></textobject></inlinemediaobject></para><para> and a sample mean </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_c4afc14526d2aa94109c035274a1fb703efaf13a_p1.png"/></imageobject><textobject><phrase>$\bar{x}$</phrase></textobject></inlinemediaobject></para><para>. There is a function z.test() in the BSDA package</para><itemizedlist><listitem><para>It is necessary that the population variance  </para></listitem></itemizedlist><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_55aa096962a731c9239cb43a9dd1776b5a367294_p1.png"/></imageobject><textobject><phrase>$\sigma^2$</phrase></textobject></inlinemediaobject></para><para> is known. </para><itemizedlist><listitem><para>The test is accurate if the population is normally distributed. If the population is not normal, the test will still give an approximate guide. </para></listitem></itemizedlist></section></section><section><title>Simulation Exercises</title><itemizedlist><listitem><para>Now sample 100 values from a Normal distribution with mean 10 and standard deviation 2 and use a z-test to compare it against the population mean 10. What is the p-value? </para></listitem><listitem><para>Now do the sampling and the testing 1000 times, what would be the number of statistically significant results? Use replicate() (which is a wrapper of tapply()) or a for() loop! Record at least the p-values and the estimated differences! Use table() to count the p-vals below 0.05. What type of error do you associate with it? What is the smallest absolute difference with a p-value below 0.05? </para></listitem><listitem><para>Repeat the simulation above, change the sample size to 1000 in each of the 1000 samples! How many p-values below 0.05? What is now the smallest absolute difference with a p-value below 0.05? </para></listitem></itemizedlist><section><title>Simulation Exercises -- Solutions</title><itemizedlist><listitem><para>Now sample 100 values from a Normal distribution with mean 10 and standard deviation 2 and use a z-test to compare it against the population mean 10. What is the p-value? What the estimated difference? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10)]]><methodname><![CDATA[[]]></methodname><phrase><![CDATA["]]></phrase><phrase><![CDATA[pval"]]></phrase><methodname><![CDATA[]]]></methodname>
<![CDATA[  ]]><methodname><![CDATA[pval]]></methodname>
<![CDATA[0.0441    ]]>
<![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10)]]><methodname><![CDATA[[]]></methodname><phrase><![CDATA["]]></phrase><phrase><![CDATA[diff"]]></phrase><methodname><![CDATA[]]]></methodname>
<![CDATA[   ]]><methodname><![CDATA[diff]]></methodname><![CDATA[ ]]>
<![CDATA[-0.0655 ]]>
<![CDATA[> ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10)]]><methodname><![CDATA[[c]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[pval"]]></phrase><![CDATA[,]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[diff"]]></phrase><![CDATA[)]]><methodname><![CDATA[]]]></methodname>
<![CDATA[  ]]><methodname><![CDATA[pval]]></methodname><![CDATA[   ]]><methodname><![CDATA[diff]]></methodname><![CDATA[ ]]>
<![CDATA[0.4515 0.1506 ]]>
</programlisting><itemizedlist><listitem><para>Now do the sampling and the testing 1000 times, what would be the number of statistically significant results? Use replicate() (which is a wrapper of tapply()) or a for() loop. Record at least the p-values and the estimated differences! Transform the result into a data frame. </para></listitem></itemizedlist></section><section><title>Solution</title><itemizedlist><listitem><para>using replicate() </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[replicate]]></methodname><![CDATA[(1000, ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10))]]>
<![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[as.data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[t]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[))]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[)]]>
<methodname><![CDATA[diff]]></methodname><![CDATA[       ]]><methodname><![CDATA[Z]]></methodname><![CDATA[   ]]><methodname><![CDATA[pval]]></methodname><![CDATA[   ]]><methodname><![CDATA[n]]></methodname>
<![CDATA[1 -0.2834 -1.4170 0.1565 100]]>
<![CDATA[2  0.2540  1.2698 0.2042 100]]>
<![CDATA[3 -0.1915 -0.9576 0.3383 100]]>
<![CDATA[4  0.1462  0.7312 0.4646 100]]>
<![CDATA[5  0.1122  0.5612 0.5747 100]]>
<![CDATA[6 -0.0141 -0.0706 0.9437 100]]>
</programlisting><itemizedlist><listitem><para>using replicate() II </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[replicate]]></methodname><![CDATA[(1000, ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10),]]>
<![CDATA[+                        ]]><methodname><![CDATA[simplify]]></methodname><![CDATA[ = ]]><token><![CDATA[F]]></token><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[as.data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[Reduce]]></methodname><![CDATA[(]]><methodname><![CDATA[rbind]]></methodname><![CDATA[,]]><methodname><![CDATA[res]]></methodname><![CDATA[))]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[)]]>
<methodname><![CDATA[diff]]></methodname><![CDATA[       ]]><methodname><![CDATA[Z]]></methodname><![CDATA[   ]]><methodname><![CDATA[pval]]></methodname><![CDATA[   ]]><methodname><![CDATA[n]]></methodname>
<methodname><![CDATA[init]]></methodname><![CDATA[ -0.0175 -0.0874 0.9304 100]]>
</programlisting><itemizedlist><listitem><para>using for()  </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[matrix]]></methodname><![CDATA[(]]><methodname><![CDATA[numeric]]></methodname><![CDATA[(2000),]]><methodname><![CDATA[ncol]]></methodname><![CDATA[=2)]]>
<![CDATA[> ]]><methodname><![CDATA[for]]></methodname><![CDATA[(]]><methodname><![CDATA[i]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[seq.int]]></methodname><![CDATA[(1000)){]]>
<![CDATA[+     ]]><methodname><![CDATA[res]]></methodname><methodname><![CDATA[[i]]></methodname><![CDATA[,]]><methodname><![CDATA[]]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(100,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10)]]><methodname><![CDATA[[c]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[pval"]]></phrase><![CDATA[,]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[diff"]]></phrase><![CDATA[)]]><methodname><![CDATA[]]]></methodname><![CDATA[ }]]>
<![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[as.data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[names]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[) <- ]]><methodname><![CDATA[c]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[pval"]]></phrase><![CDATA[,]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[diff"]]></phrase><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[)]]>
<methodname><![CDATA[pval]]></methodname><![CDATA[    ]]><methodname><![CDATA[diff]]></methodname>
<![CDATA[1 0.0591 -0.3775]]>
<![CDATA[2 0.2466  0.2317]]>
<![CDATA[3 0.6368  0.0944]]>
<![CDATA[4 0.5538 -0.1184]]>
<![CDATA[5 0.9897 -0.0026]]>
<![CDATA[6 0.7748  0.0572]]>
</programlisting><itemizedlist><listitem><para>Use table() to count the p-vals below 0.05. What type of error do you associate with it? What is the smallest absolute difference with a p-value below 0.05? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05)]]>
<symbol><![CDATA[FALSE]]></symbol><![CDATA[  ]]><symbol><![CDATA[TRUE]]></symbol><![CDATA[ ]]>
<![CDATA[960    40 ]]>
<![CDATA[> ]]><methodname><![CDATA[tapply]]></methodname><![CDATA[(]]><methodname><![CDATA[abs]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[diff]]></methodname><![CDATA[),]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05,]]><methodname><![CDATA[summary]]></methodname><![CDATA[)]]>
<![CDATA[$]]><methodname><![CDATA[`FALSE`]]></methodname>
<![CDATA[   ]]><methodname><![CDATA[Min.]]></methodname><![CDATA[ 1]]><methodname><![CDATA[st]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[  ]]><methodname><![CDATA[Median]]></methodname><![CDATA[    ]]><methodname><![CDATA[Mean]]></methodname><![CDATA[ 3]]><methodname><![CDATA[rd]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[    ]]><methodname><![CDATA[Max.]]></methodname><![CDATA[ ]]>
<![CDATA[ 0.0002  0.0585  0.1280  0.1411  0.2068  0.3847 ]]>

<![CDATA[$]]><methodname><![CDATA[`TRUE`]]></methodname>
<![CDATA[   ]]><methodname><![CDATA[Min.]]></methodname><![CDATA[ 1]]><methodname><![CDATA[st]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[  ]]><methodname><![CDATA[Median]]></methodname><![CDATA[    ]]><methodname><![CDATA[Mean]]></methodname><![CDATA[ 3]]><methodname><![CDATA[rd]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[    ]]><methodname><![CDATA[Max.]]></methodname><![CDATA[ ]]>
<![CDATA[ 0.3928  0.4247  0.4408  0.4694  0.5102  0.6859 ]]>

<![CDATA[> ]]><methodname><![CDATA[min]]></methodname><![CDATA[(]]><methodname><![CDATA[abs]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[diff]]></methodname><methodname><![CDATA[[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[<0.05]]><methodname><![CDATA[]]]></methodname><![CDATA[))]]>
<methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[ 0.3928]]>
</programlisting><itemizedlist><listitem><para>Repeat the simulation above, change the sample size to 1000 in each of the 1000 samples! How many p-values below 0.05? What is now the smallest absolute difference with a p-value below 0.05? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[res2]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[replicate]]></methodname><![CDATA[(1000, ]]><methodname><![CDATA[ztest]]></methodname><![CDATA[(]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(1000,]]><methodname><![CDATA[mean]]></methodname><![CDATA[=10,]]><methodname><![CDATA[sd]]></methodname><![CDATA[=2),]]>
<![CDATA[+                              ]]><methodname><![CDATA[x.sd]]></methodname><![CDATA[=2,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=10))]]>
<![CDATA[> ]]><methodname><![CDATA[res2]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[as.data.frame]]></methodname><![CDATA[(]]><methodname><![CDATA[t]]></methodname><![CDATA[(]]><methodname><![CDATA[res2]]></methodname><![CDATA[))]]>
<![CDATA[> ]]><methodname><![CDATA[head]]></methodname><![CDATA[(]]><methodname><![CDATA[res2]]></methodname><![CDATA[)]]>
<![CDATA[     ]]><methodname><![CDATA[diff]]></methodname><![CDATA[       ]]><methodname><![CDATA[Z]]></methodname><![CDATA[   ]]><methodname><![CDATA[pval]]></methodname><![CDATA[    ]]><methodname><![CDATA[n]]></methodname>
<![CDATA[1 -0.0731 -1.1559 0.2477 1000]]>
<![CDATA[2  0.0018  0.0292 0.9767 1000]]>
<![CDATA[3  0.0072  0.1144 0.9089 1000]]>
<![CDATA[4 -0.1145 -1.8100 0.0703 1000]]>
<![CDATA[5 -0.1719 -2.7183 0.0066 1000]]>
<![CDATA[6  0.0880  1.3916 0.1640 1000]]>
</programlisting><itemizedlist><listitem><para>Repeat the simulation above, change the sample size to 1000 in each of the 1000 samples! How many p-values below 0.05? What is now the smallest absolute difference with a p-value below 0.05? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[res2]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05)]]>
<symbol><![CDATA[FALSE]]></symbol><![CDATA[  ]]><symbol><![CDATA[TRUE]]></symbol><![CDATA[ ]]>
<![CDATA[946    54 ]]>
<![CDATA[> ]]><methodname><![CDATA[tapply]]></methodname><![CDATA[(]]><methodname><![CDATA[abs]]></methodname><![CDATA[(]]><methodname><![CDATA[res2]]></methodname><![CDATA[$]]><methodname><![CDATA[diff]]></methodname><![CDATA[),]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05,]]><methodname><![CDATA[summary]]></methodname><![CDATA[)]]>
<![CDATA[$]]><methodname><![CDATA[`FALSE`]]></methodname>
<![CDATA[   ]]><methodname><![CDATA[Min.]]></methodname><![CDATA[ 1]]><methodname><![CDATA[st]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[  ]]><methodname><![CDATA[Median]]></methodname><![CDATA[    ]]><methodname><![CDATA[Mean]]></methodname><![CDATA[ 3]]><methodname><![CDATA[rd]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[    ]]><methodname><![CDATA[Max.]]></methodname><![CDATA[ ]]>
<![CDATA[0.00010 0.02092 0.04285 0.05149 0.07400 0.22610 ]]>

<![CDATA[$]]><methodname><![CDATA[`TRUE`]]></methodname>
<![CDATA[   ]]><methodname><![CDATA[Min.]]></methodname><![CDATA[ 1]]><methodname><![CDATA[st]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[  ]]><methodname><![CDATA[Median]]></methodname><![CDATA[    ]]><methodname><![CDATA[Mean]]></methodname><![CDATA[ 3]]><methodname><![CDATA[rd]]></methodname><![CDATA[ ]]><methodname><![CDATA[Qu.]]></methodname><![CDATA[    ]]><methodname><![CDATA[Max.]]></methodname><![CDATA[ ]]>
<![CDATA[0.00240 0.02115 0.04535 0.05435 0.08433 0.14760 ]]>
</programlisting></section></section><section><title>Simulation Exercises Part II</title><itemizedlist><listitem><para>Concatenate the both resulting data frames from above using rbind() </para></listitem><listitem><para>Plot the distributions of the pvals and the difference per sample size. Use ggplot2 with an appropriate geom (density/histogram) </para></listitem><listitem><para>What is the message? </para></listitem></itemizedlist><section><title>Simulation Exercises -- Solutions</title><itemizedlist><listitem><para>Concatenate the both resulting data frames from above using rbind() </para></listitem><listitem><para>Plot the distributions of the pvals and the difference per sample size. Use ggplot2 with an appropriate geom (density/histogram) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[rbind]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[,]]><methodname><![CDATA[res2]]></methodname><![CDATA[)  ]]>
<![CDATA[> ]]><methodname><![CDATA[require]]></methodname><![CDATA[(]]><methodname><![CDATA[ggplot2]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[pval]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_histogram]]></methodname><![CDATA[(]]><methodname><![CDATA[bin]]></methodname><![CDATA[=0.1,]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[forestgreen"]]></phrase><![CDATA[) +]]>
<![CDATA[+     ]]><methodname><![CDATA[facet_grid]]></methodname><![CDATA[(~ ]]><methodname><![CDATA[n]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[hist.png"]]></phrase><![CDATA[)]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=hist.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=hist.png" width="800"/></imageobject><textobject><phrase>attachment:hist.png</phrase></textobject></inlinemediaobject></ulink> </para><itemizedlist><listitem><para>Plot the distributions of the pvals and the difference per sample size. Use ggplot2 with an appropriate geom (density/histogram) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[diff]]></methodname><![CDATA[,]]><methodname><![CDATA[colour]]></methodname><![CDATA[=]]><methodname><![CDATA[factor]]></methodname><![CDATA[(]]><methodname><![CDATA[n]]></methodname><![CDATA[))) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_density]]></methodname><![CDATA[(]]><methodname><![CDATA[size]]></methodname><![CDATA[=3)]]>
<![CDATA[> ]]><methodname><![CDATA[ggsave]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[dens.png"]]></phrase><![CDATA[)]]>
</programlisting></section></section><section><title>Simulation Exercises -- Solutions</title><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=dens.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=dens.png" width="800"/></imageobject><textobject><phrase>attachment:dens.png</phrase></textobject></inlinemediaobject></ulink> </para><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=point.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=point.png" width="800"/></imageobject><textobject><phrase>attachment:point.png</phrase></textobject></inlinemediaobject></ulink> </para><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=dens2d.png"><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=dens2d.png" width="800"/></imageobject><textobject><phrase>attachment:dens2d.png</phrase></textobject></inlinemediaobject></ulink> </para></section><section><title>t-tests</title><para>A t-test is any statistical hypothesis test in which the test statistic follows a Student's t distribution if the null hypothesis is supported. </para><itemizedlist><listitem><para>one sample t-test: test a sample mean against a population mean </para></listitem></itemizedlist><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_f1bda318df3523763ae70ac8f742515a3c339955_p1.png"/></imageobject><textobject><phrase>$$t = \frac{\bar{x}-\mu_0}{s/\sqrt{n}}$$</phrase></textobject></inlinemediaobject></para><para> where </para><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_59aa7e4c85f727b785ce4e6d0fd0c3f078e3df3c_p1.png"/></imageobject><textobject><phrase>$\bar{x}$ </phrase></textobject></inlinemediaobject></para><para>is the sample mean, s is the sample standard deviation and n is the sample size. The degrees of freedom used in this test is n-1 </para><section><title>one sample t-test</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[set.seed]]></methodname><![CDATA[(1)]]>
<![CDATA[> ]]><methodname><![CDATA[x]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(12)]]>
<![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=0) ]]><lineannotation><![CDATA[## population mean 0]]></lineannotation>

<![CDATA[        ]]><methodname><![CDATA[One]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[x]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = 1.1478, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 11, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.2754]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -0.2464740  0.7837494]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[x]]></methodname><![CDATA[ ]]>
<![CDATA[0.2686377 ]]>

<![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[mu]]></methodname><![CDATA[=1) ]]><lineannotation><![CDATA[## population mean 1]]></lineannotation>

<![CDATA[        ]]><methodname><![CDATA[One]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[x]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = -3.125, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 11, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.009664]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 1]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -0.2464740  0.7837494]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[x]]></methodname><![CDATA[ ]]>
<![CDATA[0.2686377 ]]>
</programlisting></section></section><section><title>Two Sample t-tests</title><para>There are two ways to perform a two sample t-test in R: </para><itemizedlist><listitem><para>given two vectors x and y containing the measurement values from the respective groups t.test(x,y) </para></listitem><listitem><para>given one vector x containing all the measurement values and one vector g containing the group membership  </para></listitem></itemizedlist><para><inlinemediaobject><imageobject><imagedata fileref="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=latex_86e03fafcc061a3c5664ac2839fd89cabd77eea9_p1.png"/></imageobject><textobject><phrase>t.test(x $\sim$ g)</phrase></textobject></inlinemediaobject></para><para> (read: x dependend on g)</para><section><title>Two Sample t-tests: two vector syntax</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[set.seed]]></methodname><![CDATA[(1)]]>
<![CDATA[> ]]><methodname><![CDATA[x]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(12)]]>
<![CDATA[> ]]><methodname><![CDATA[y]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[rnorm]]></methodname><![CDATA[(12)]]>
<![CDATA[> ]]><methodname><![CDATA[g]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[sample]]></methodname><![CDATA[(]]><methodname><![CDATA[c]]></methodname><![CDATA[(]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[A"]]></phrase><![CDATA[,]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[B"]]></phrase><![CDATA[),12,]]><methodname><![CDATA[replace]]></methodname><![CDATA[ = ]]><token><![CDATA[T]]></token><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[)]]>

<![CDATA[        ]]><methodname><![CDATA[Welch]]></methodname><![CDATA[ ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[x]]></methodname><![CDATA[ ]]><methodname><![CDATA[and]]></methodname><![CDATA[ ]]><methodname><![CDATA[y]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = 0.5939, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 20.012, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.5592]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -0.5966988  1.0717822]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[x]]></methodname><![CDATA[  ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[y]]></methodname><![CDATA[ ]]>
<![CDATA[0.26863768 0.03109602   ]]>
</programlisting></section><section><title>Two Sample t-tests: formula syntax</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[ ~ ]]><methodname><![CDATA[g]]></methodname><![CDATA[)]]>

<![CDATA[        ]]><methodname><![CDATA[Welch]]></methodname><![CDATA[ ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[x]]></methodname><![CDATA[ ]]><methodname><![CDATA[by]]></methodname><![CDATA[ ]]><methodname><![CDATA[g]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = -0.6644, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 6.352, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.5298]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -1.6136329  0.9171702]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[A]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[B]]></methodname><![CDATA[ ]]>
<![CDATA[      0.1235413       0.4717726 ]]>
</programlisting></section><section><title>Welch/Satterthwaite vs. Student</title><itemizedlist><listitem><para>if not stated otherwise t.test() will not assume that the variances in the both groups are equal </para></listitem><listitem><para>if one knows that both populations have the same variance set the var.equal argument to TRUE to perform a student's t-test </para></listitem></itemizedlist></section></section><section><title>Student's t-test</title><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[, ]]><methodname><![CDATA[y]]></methodname><![CDATA[, ]]><methodname><![CDATA[var.equal]]></methodname><![CDATA[ = ]]><token><![CDATA[T]]></token><![CDATA[)]]>

<![CDATA[        ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[x]]></methodname><![CDATA[ ]]><methodname><![CDATA[and]]></methodname><![CDATA[ ]]><methodname><![CDATA[y]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = 0.5939, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 22, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.5586]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -0.5918964  1.0669797]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[x]]></methodname><![CDATA[  ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[of]]></methodname><![CDATA[ ]]><methodname><![CDATA[y]]></methodname><![CDATA[ ]]>
<![CDATA[0.26863768 0.03109602   ]]>
</programlisting><section><title>Requirements</title><itemizedlist><listitem><para>the t-test, especially the Welch test is appropriate whenever the values are normally distributed </para></listitem><listitem><para>it is also recommended for group sizes &gt; 30 (robust against deviation from normality) </para></listitem></itemizedlist></section></section><section><title>Exercises</title><itemizedlist><listitem><para>use a t-test to compare TTime according to Stim.Type, visualize it. What is the problem? </para></listitem><listitem><para>now do the same for Subject 1 on pre and post test (use filter() or indexing to get the resp. subsets) </para></listitem><listitem><para>use the following code to do the test on every subset Subject and testid, try to figure what is happening in each step:\tiny </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><methodname><![CDATA[data.l]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[split]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[list]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[,]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[),]]><methodname><![CDATA[drop]]></methodname><![CDATA[=]]><token><![CDATA[T]]></token><![CDATA[)]]>
<methodname><![CDATA[tmp.l]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[lapply]]></methodname><![CDATA[(]]><methodname><![CDATA[data.l]]></methodname><![CDATA[,]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) {]]>
<![CDATA[    ]]><methodname><![CDATA[if]]></methodname><![CDATA[(]]><methodname><![CDATA[min]]></methodname><![CDATA[(]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) < 5) ]]><methodname><![CDATA[return]]></methodname><![CDATA[(]]><symbol><![CDATA[NULL]]></symbol><![CDATA[)]]>
<![CDATA[    ]]><methodname><![CDATA[tob]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><![CDATA[ ~ ]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)]]>
<![CDATA[    ]]><methodname><![CDATA[tmp]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[data.frame]]></methodname><![CDATA[(]]>
<![CDATA[        ]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ = ]]><methodname><![CDATA[unique]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[),]]>
<![CDATA[        ]]><methodname><![CDATA[testid]]></methodname><![CDATA[ = ]]><methodname><![CDATA[unique]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[),]]>
<![CDATA[        ]]><methodname><![CDATA[mean.group.1]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[estimate]]></methodname><methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[mean.group.2]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[estimate]]></methodname><methodname><![CDATA[[2]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[name.test.stat]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[statistic]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[conf.lower]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[conf.int]]></methodname><methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[conf.upper]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[conf.int]]></methodname><methodname><![CDATA[[2]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[pval]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[p.value]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[alternative]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[alternative]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[method]]></methodname><![CDATA[)})]]>
<methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[Reduce]]></methodname><![CDATA[(]]><methodname><![CDATA[rbind]]></methodname><![CDATA[,]]><methodname><![CDATA[tmp.l]]></methodname><![CDATA[)]]>
</programlisting><itemizedlist><listitem><para>make plots to visualize the results.  </para></listitem><listitem><para>how many tests have a statistically significant result? How many did you expect? Is there a tendency? What could be the next step? </para></listitem></itemizedlist><section><title>Solutions</title><itemizedlist><listitem><para>use a t-test to compare TTime according to Stim.Type, visualize it. What is the problem? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><![CDATA[ ~ ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)]]>

<![CDATA[        ]]><methodname><![CDATA[Welch]]></methodname><![CDATA[ ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><![CDATA[ ]]><methodname><![CDATA[by]]></methodname><![CDATA[ ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = -6.3567, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 9541.891, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 2.156e-10]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -2773.574 -1466.161]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<![CDATA[      ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[hit]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[incorrect]]></methodname><![CDATA[ ]]>
<![CDATA[               17579.77                19699.64   ]]>

<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+     ]]><methodname><![CDATA[geom_boxplot]]></methodname><![CDATA[()]]>
</programlisting><itemizedlist><listitem><para>now do the same for Subject 1 on pre and post test (use filter() or indexing to get the resp. subsets) </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[==1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test1"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[ ~]]>
<![CDATA[+        ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[==1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test1"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[)]]>

<![CDATA[        ]]><methodname><![CDATA[Welch]]></methodname><![CDATA[ ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ == 1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[ == ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test1"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><methodname><![CDATA[by]]></methodname><![CDATA[ ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ == 1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[ == ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test1"]]></phrase><methodname><![CDATA[]]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = -0.5846, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 44.183, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.5618]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -4930.842  2713.191]]>

<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<![CDATA[      ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[hit]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[incorrect]]></methodname><![CDATA[ ]]>
<![CDATA[               8248.175                9357.000 ]]>

<![CDATA[> ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[==1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test2"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[ ~]]>
<![CDATA[+        ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[==1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test2"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[)]]>
<![CDATA[        ]]><methodname><![CDATA[Welch]]></methodname><![CDATA[ ]]><methodname><![CDATA[Two]]></methodname><![CDATA[ ]]><methodname><![CDATA[Sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[t]]></methodname><![CDATA[-]]><methodname><![CDATA[test]]></methodname>

<methodname><![CDATA[data]]></methodname><![CDATA[:  ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ == 1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[ == ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test2"]]></phrase><methodname><![CDATA[]]]></methodname><![CDATA[ ]]><methodname><![CDATA[by]]></methodname><![CDATA[ ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><methodname><![CDATA[[data]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ == 1 & ]]><methodname><![CDATA[data]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[ == ]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[test2"]]></phrase><methodname><![CDATA[]]]></methodname>
<methodname><![CDATA[t]]></methodname><![CDATA[ = -1.7694, ]]><methodname><![CDATA[df]]></methodname><![CDATA[ = 47.022, ]]><methodname><![CDATA[p]]></methodname><![CDATA[-]]><methodname><![CDATA[value]]></methodname><![CDATA[ = 0.08332]]>
<methodname><![CDATA[alternative]]></methodname><![CDATA[ ]]><methodname><![CDATA[hypothesis]]></methodname><![CDATA[: ]]><methodname><![CDATA[true]]></methodname><![CDATA[ ]]><methodname><![CDATA[difference]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[means]]></methodname><![CDATA[ ]]><methodname><![CDATA[is]]></methodname><![CDATA[ ]]><methodname><![CDATA[not]]></methodname><![CDATA[ ]]><methodname><![CDATA[equal]]></methodname><![CDATA[ ]]><methodname><![CDATA[to]]></methodname><![CDATA[ 0]]>
<![CDATA[95 ]]><methodname><![CDATA[percent]]></methodname><![CDATA[ ]]><methodname><![CDATA[confidence]]></methodname><![CDATA[ ]]><methodname><![CDATA[interval]]></methodname><![CDATA[:]]>
<![CDATA[ -7004.4904   448.9388]]>
<methodname><![CDATA[sample]]></methodname><![CDATA[ ]]><methodname><![CDATA[estimates]]></methodname><![CDATA[:]]>
<![CDATA[      ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[hit]]></methodname><![CDATA[ ]]><methodname><![CDATA[mean]]></methodname><![CDATA[ ]]><methodname><![CDATA[in]]></methodname><![CDATA[ ]]><methodname><![CDATA[group]]></methodname><![CDATA[ ]]><methodname><![CDATA[incorrect]]></methodname><![CDATA[ ]]>
<![CDATA[               4012.480                7290.256 ]]>
</programlisting><itemizedlist><listitem><para>make plots to visualize the results </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[testid]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+    ]]><methodname><![CDATA[geom_boxplot]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+    ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[Subject]]></methodname><![CDATA[)]]>
<![CDATA[> ]]><methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[data]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[factor]]></methodname><![CDATA[(]]><methodname><![CDATA[Subject]]></methodname><![CDATA[),]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[TTime]]></methodname><![CDATA[)) +]]>
<![CDATA[+    ]]><methodname><![CDATA[geom_boxplot]]></methodname><![CDATA[(]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[fill]]></methodname><![CDATA[=]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) +]]>
<![CDATA[+    ]]><methodname><![CDATA[facet_wrap]]></methodname><![CDATA[(~]]><methodname><![CDATA[testid]]></methodname><![CDATA[)]]>
</programlisting><itemizedlist><listitem><para>how many tests have an statistically significant result? How many did you expect?  </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><![CDATA[> ]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05)]]>
<symbol><![CDATA[FALSE]]></symbol><![CDATA[  ]]><symbol><![CDATA[TRUE]]></symbol><![CDATA[ ]]>
<![CDATA[165    22 ]]>
<![CDATA[> ]]><methodname><![CDATA[prop.table]]></methodname><![CDATA[(]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[$]]><methodname><![CDATA[pval]]></methodname><![CDATA[ < 0.05))]]>

<![CDATA[    ]]><symbol><![CDATA[FALSE]]></symbol><![CDATA[      ]]><symbol><![CDATA[TRUE]]></symbol><![CDATA[ ]]>
<![CDATA[0.8823529 0.1176471  ]]>
<![CDATA[> ]]>
</programlisting></section></section><section><title>Exercises - Solutions</title><itemizedlist><listitem><para>What could be the next step? </para></listitem></itemizedlist><programlisting format="linespecific" language="highlight" linenumbering="numbered" startinglinenumber="1"><methodname><![CDATA[tmp.l]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[lapply]]></methodname><![CDATA[(]]><methodname><![CDATA[data.l]]></methodname><![CDATA[,]]><methodname><![CDATA[function]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[) {]]>
<![CDATA[    ]]><methodname><![CDATA[if]]></methodname><![CDATA[(]]><methodname><![CDATA[min]]></methodname><![CDATA[(]]><methodname><![CDATA[table]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)) < 5) ]]><methodname><![CDATA[return]]></methodname><![CDATA[(]]><symbol><![CDATA[NULL]]></symbol><![CDATA[)]]>
<![CDATA[    ]]><methodname><![CDATA[tob]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[t.test]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[TTime]]></methodname><![CDATA[ ~ ]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)]]>
<![CDATA[    ]]><methodname><![CDATA[tmp]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[data.frame]]></methodname><![CDATA[(]]>
<![CDATA[        ]]><methodname><![CDATA[Subject]]></methodname><![CDATA[ = ]]><methodname><![CDATA[unique]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Subject]]></methodname><![CDATA[),]]>
<![CDATA[        ]]><methodname><![CDATA[testid]]></methodname><![CDATA[ = ]]><methodname><![CDATA[unique]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[testid]]></methodname><![CDATA[),]]>
<![CDATA[        ]]><methodname><![CDATA[perc.corr]]></methodname><![CDATA[ = ]]><methodname><![CDATA[sum]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[==]]><phrase><![CDATA["]]></phrase><phrase><![CDATA[hit"]]></phrase><![CDATA[)/]]><methodname><![CDATA[sum]]></methodname><![CDATA[(!]]><methodname><![CDATA[is.na]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[$]]><methodname><![CDATA[Stim.Type]]></methodname><![CDATA[)),]]>
<![CDATA[        ]]><methodname><![CDATA[mean.group.1]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[estimate]]></methodname><methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[mean.group.2]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[estimate]]></methodname><methodname><![CDATA[[2]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[name.test.stat]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[statistic]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[conf.lower]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[conf.int]]></methodname><methodname><![CDATA[[1]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[conf.upper]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[conf.int]]></methodname><methodname><![CDATA[[2]]></methodname><methodname><![CDATA[]]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[pval]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[p.value]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[alternative]]></methodname><![CDATA[ = ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[alternative]]></methodname><![CDATA[,]]>
<![CDATA[        ]]><methodname><![CDATA[tob]]></methodname><![CDATA[$]]><methodname><![CDATA[method]]></methodname><![CDATA[)})]]>

<methodname><![CDATA[res]]></methodname><![CDATA[ <- ]]><methodname><![CDATA[Reduce]]></methodname><![CDATA[(]]><methodname><![CDATA[rbind]]></methodname><![CDATA[,]]><methodname><![CDATA[tmp.l]]></methodname><![CDATA[)]]>

<methodname><![CDATA[ggplot]]></methodname><![CDATA[(]]><methodname><![CDATA[res]]></methodname><![CDATA[,]]><methodname><![CDATA[aes]]></methodname><![CDATA[(]]><methodname><![CDATA[x]]></methodname><![CDATA[=]]><methodname><![CDATA[perc.corr]]></methodname><![CDATA[,]]><methodname><![CDATA[y]]></methodname><![CDATA[=]]><methodname><![CDATA[mean.group.1]]></methodname><![CDATA[ - ]]><methodname><![CDATA[mean.group.2]]></methodname><![CDATA[)) +]]>
<![CDATA[    ]]><methodname><![CDATA[geom_point]]></methodname><![CDATA[() +]]>
<![CDATA[    ]]><methodname><![CDATA[geom_smooth]]></methodname><![CDATA[()]]>
</programlisting><para><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=excerchypo.pdf"><ulink url="https://wiki.init.mpg.de/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR/IT4Science/RstatisTik/RstatisTikPortal/RcourSe/CourseOutline/TestsInR?action=AttachFile&amp;do=get&amp;target=exerchypo.pdf">attachment:excerchypo.pdf</ulink></ulink>  </para></section></section></article>