<div>
<div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/prepdat-preparing-experimental-data-for-statistical-analysis/"></div></div><div></div></div><div></div></div>
<h4><em>Guest post by<a target="_blank" rel="nofollow" href="https://github.com/ayalaallon/"> Ayala S. Allon</a>, School of Psychological Sciences, Tel-Aviv University</em></h4>
</div>
<p><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a> is an R package that helps researchers to optimize and speedup their analysis, providing various cross sections of the data in order to better understand the results.</p>
<p><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a> was created by <a target="_blank" rel="nofollow" href="https://github.com/ayalaallon/">Ayala S. Allon</a> and <a target="_blank" rel="nofollow" href="http://people.socsci.tau.ac.il/mu/royluria/">Roy Luria</a>. The full papaer about <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a> was published in <a target="_blank" rel="nofollow" href="http://openresearchsoftware.metajnl.com/articles/10.5334/jors.134/">Journal of Open Research Software</a> on Nov 25, 2016, and <a target="_blank" rel="nofollow" href="http://openresearchsoftware.metajnl.com/articles/10.5334/jors.134/galley/205/download/">can be downloaded here</a>.</p>
<p>To better understand the abilities of the package let’s look at an example. Look at the two distributions in the figure below. The difference between the means of these two distributions is significant (<em>t</em>(20) = 8.65, <em>p</em> &lt; 0.001). As can be seen, the “mdvc1” distribution is right skewed, and the “mdvc5” distribution is not skewed.</p>
<p>It could be that the “mdvc1” distribution, because of it’s skeweness, is not best characterized by the mean, but rather by another dependent measure such as the 25th percentile. As such, one should consider looking and testing different cross sections and dependent measures of the data because it can provide information about the source of the effect in question.</p>
<p>Yet, in many studies the comparision between experimental conditions in the statistical inference stage is done directly on the means without examining other cross sections of the data.</p>
<p><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a>, using the <code>prep()</code> function, outputs various dependent measures of the dependent variable (e.g., means after rejecting observations according to a flexible standard deviation criteria and percentiles), enabling the user to better understand the results. In addition, <code>prep()</code> enables to aggregate raw data tables in a long format according to any number of grouping variables (i.e., independent variables).</p>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/www.r-bloggers.com/wp-content/uploads/2017/01/mdvc_for_histogram.png?ssl=1"><img alt="mdvc_for_histogram" class="wp-image-145263" src="https://i1.wp.com/www.r-bloggers.com/wp-content/uploads/2017/01/mdvc_for_histogram.png?resize=390%2C338&ssl=1" data-recalc-dims="1"></a></div>
<div>
<h1>prep()</h1>
<p>Aggregating a raw data table includes reducing the amounts of data to the desired level of information, resulting in a finalized table, usually in a wide format, in which each row in the table refers to a specific subject (which is the variable that identifies the unit upon which the measurement took place; i.e., the id variable), and each cell in the table usually reflects the averaged performance of that subject according to the desired grouping variables (i.e., the independent and dependent variables). This finalized table often contains only selected variables relative to the raw data table:</p>
<p>For each aggregated cell in the finalized table <code>prep()</code> will output:</p>
<ul>
<li>Means before and after rejecting observations according to a flexible standard deviation criteria.</li>
<li>Number of rejected observations according to the flexible standard deviation criteria.</li>
<li>Proportions of rejected observations according to the flexible standard deviation criteria.</li>
<li>Number of observations before rejection.</li>
<li>Standard deviations.</li>
<li>Medians.</li>
<li>Additional percentiles (e.g., the 0.05th, 0.25th, 0.75th, 0.95th percentiles).</li>
<li>Means after rejecting observations according to procedures described in Van Selst &amp; Jolicoeur (1994; suitable when measuring reaction-times).</li>
<li>Harmonic means.</li>
</ul>
<p><code>prep()</code> is suitable for aggregating various types of experimental designs such as between-subjects designs, within-subjects (i.e., repeated measures) designs, and mixed designs (i.e., designs that combine between-subjects and within-subjects independent variables). <code>prep()</code> is very easy to use, and only involves filling various arguments and when needed, making changes to default procedures for removing outliers.</p>
<p><code>prep()</code> accepts the following arguments:</p>
<pre><code><span>prep</span><span>(</span>
   <span>dataset</span> <span>=</span> <span>NULL</span>
   , <span>file_name</span> <span>=</span> <span>NULL</span>
   , <span>file_path</span> <span>=</span> <span>NULL</span>
   , <span>id</span> <span>=</span> <span>NULL</span>
   , <span>within_vars</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
   , <span>between_vars</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
   , <span>dvc</span> <span>=</span> <span>NULL</span>
   , <span>dvd</span> <span>=</span> <span>NULL</span>
   , <span>keep_trials</span> <span>=</span> <span>NULL</span>
   , <span>drop_vars</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
   , <span>keep_trials_dvc</span> <span>=</span> <span>NULL</span>
   , <span>keep_trials_dvd</span> <span>=</span> <span>NULL</span>
   , <span>id_properties</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
   , <span>sd_criterion</span> <span>=</span> <span>c</span><span>(</span><span>1</span>, <span>1.5</span>, <span>2</span><span>)</span>
   , <span>percentiles</span> <span>=</span> <span>c</span><span>(</span><span>0.05</span>, <span>0.25</span>, <span>0.75</span>, <span>0.95</span><span>)</span>
   , <span>outlier_removal</span> <span>=</span> <span>NULL</span>
   , <span>keep_trials_outlier</span> <span>=</span> <span>NULL</span>
   , <span>decimal_places</span> <span>=</span> <span>4</span>
   , <span>notification</span> <span>=</span> <span>TRUE</span>
   , <span>dm</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
   , <span>save_results</span> <span>=</span> <span>TRUE</span>
   , <span>results_name</span> <span>=</span> <span>&quot;results.txt&quot;</span>
   , <span>results_path</span> <span>=</span> <span>NULL</span>
   , <span>save_summary</span> <span>=</span> <span>TRUE</span>
<span>)</span></code></pre>
</div>
<div>
<h1>file_merge()</h1>
<p>In many research fields the outcome of running an experiment is a raw data file (e.g., a text file) for each subject, containing a table in which each row describes one trial conducted during the experiment. For example in Experimental Psychology, this file will contain numerical description of the subject’s performance in the various experimental conditions. The columns in this raw data table will describe the independent variables, dependent variables, and various characteristics of the subject and the experiment (e.g., age, gender, and a numerical description of the stimulus in the experiment). The rows in this raw data table will describe the observations (i.e., trials) conducted during the experiment, such that each row in the table corresponds to one observation. Usually, this raw data table has over a hundred lines, and the number of raw data files corresponds to the number of subjects in a given experiment.</p>
<p>The next step (before aggregating the data into one finalized table), is to merge all files into one big raw data table. <code>file_merge()</code> enables to merge the individuals raw data files into one big raw data table containing a ‘chain’ of raw data from all subjects, one after the other.</p>
<p><code>file_merge()</code> accepts the following arguments:</p>
<pre><code><span>file_merge</span><span>(</span>
  <span>folder_path</span> <span>=</span> <span>NULL</span>
  , <span>has_header</span> <span>=</span> <span>TRUE</span>
  , <span>new_header</span> <span>=</span> <span>c</span><span>(</span><span>)</span>
  , <span>raw_file_name</span> <span>=</span> <span>NULL</span>
  , <span>raw_file_extension</span> <span>=</span> <span>NULL</span>
  , <span>file_name</span> <span>=</span> <span>&quot;dataset.txt&quot;</span>
  , <span>save_table</span> <span>=</span> <span>TRUE</span>
  , <span>dir_save_table</span> <span>=</span> <span>folder_path</span>
  , <span>notification</span> <span>=</span> <span>TRUE</span>
<span>)</span></code></pre>
<div>
<h3>Installation</h3>
<pre><code><span>install.packages</span><span>(</span><span>&quot;prepdat&quot;</span><span>)</span></code></pre>
<p>To install the most current version of <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a>, sometimes even before its official release on <a target="_blank" rel="nofollow" href="https://cran.r-project.org/">CRAN</a>:</p>
<pre><code><span>devtools</span><span>:</span><span>:</span><span>install_github</span><span>(</span><span>&quot;ayalaallon/prepdat&quot;</span><span>)</span></code></pre>
<p>To load <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a> in a current R session:</p>
<pre><code><span>library</span><span>(</span><span>prepdat</span><span>)</span></code></pre>
</div>
<div>
<h3>Summary</h3>
<p>To summarize, <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/prepdat/index.html"><code>prepdat</code></a> enables the user to easily and quickly merge (using <code>file_merge()</code> ) and aggregate raw data tables (using <code>prep()</code>) while keeping track and summarizing every step of the preparation.</p>
</div>
<div>
<h3>Contact</h3>
<p>For questions, comments, and suggestions please email me at <a target="_blank" rel="nofollow" href="mailto:ayalaallon@gmail.com">ayalaallon@gmail.com</a> or open an issue in <a target="_blank" rel="nofollow" href="https://github.com/ayalaallon/prepdat/issues">GitHub</a>.</p>
</div>
<div>
<h3>References</h3>
<p>Allon, A. S., &amp; Luria, R. (2016). prepdat- An R Package for Preparing Experimental Data for Statistical Analysis. <em>Journal of Open Research Software</em>, 4(1), e43. DOI: <a target="_blank" rel="nofollow" href="http://doi.org/10.5334/jors.134">http://doi.org/10.5334/jors.134</a></p>
<p>Allon, A. S. &amp; Luria, R. (2016). prepdat: Preparing Experimental Data for Statistical Analysis. R package version 1.0.8. <a target="_blank" rel="nofollow" href="http://CRAN.R-project.org/package=prepdat">http://CRAN.R-project.org/package=prepdat</a></p>
<p>Van Selst, M. &amp; Jolicoeur, P. (1994). A solution to the effect of sample size on outlier elimination. <em>The Quarterly Journal of Experimental Psychology</em>, Section A, 47:3, 631-650, DOI: <a target="_blank" rel="nofollow" href="http://dx.doi.org/10.1080/14640749408401131">http://dx.doi.org/10.1080/14640749408401131</a></p>
</div>
</div>
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/5F4zZ4irvZU">