<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Aggregate mouse-tracking data per condition. — mt_aggregate • mousetrap</title><!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css"><script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet"><script src="../pkgdown.js"></script><meta property="og:title" content="Aggregate mouse-tracking data per condition. — mt_aggregate"><meta property="og:description" content="mt_aggregate is used for aggregating mouse-tracking measures (or
trajectories) per condition. One or several condition variables can be
specified using use2_variables. Aggregation will be performed
separately for each level of the condition variables. mt_aggregate is
a wrapper function for mt_reshape."><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--></head><body data-spy="scroll" data-target="#toc">
    

    <div class="container template-reference-topic">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">mousetrap</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">3.2.3</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav"><li>
  <a href="../reference/mousetrap-package.html">Overview</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../news/index.html">News</a>
</li>
      </ul><ul class="nav navbar-nav navbar-right"><li>
  <a href="https://github.com/pascalkieslich/mousetrap" class="external-link">
    <span class="fa fa-github fa-lg"></span>
     
  </a>
</li>
      </ul></div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

      

      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>Aggregate mouse-tracking data per condition.</h1>
    <small class="dont-index">Source: <a href="https://github.com/pascalkieslich/mousetrap/blob/HEAD/R/aggregate.R" class="external-link"><code>R/aggregate.R</code></a></small>
    <div class="hidden name"><code>mt_aggregate.Rd</code></div>
    </div>

    <div class="ref-description">
    <p><code>mt_aggregate</code> is used for aggregating mouse-tracking measures (or
trajectories) per condition. One or several condition variables can be
specified using <code>use2_variables</code>. Aggregation will be performed
separately for each level of the condition variables. <code>mt_aggregate</code> is
a wrapper function for <code><a href="mt_reshape.html">mt_reshape</a></code>.</p>
    </div>

    <div id="ref-usage">
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">mt_aggregate</span><span class="op">(</span></span>
<span>  <span class="va">data</span>,</span>
<span>  use <span class="op">=</span> <span class="st">"measures"</span>,</span>
<span>  use_variables <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  use2 <span class="op">=</span> <span class="st">"data"</span>,</span>
<span>  use2_variables <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  subject_id <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span>  trajectories_long <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div id="arguments">
    <h2>Arguments</h2>
    <dl><dt>data</dt>
<dd><p>a mousetrap data object created using one of the mt_import
functions (see <a href="mt_example.html">mt_example</a> for details). Alternatively, a trajectory
array can be provided directly (in this case <code>use</code> will be ignored).</p></dd>


<dt>use</dt>
<dd><p>a character string specifying which dataset should be aggregated.
The corresponding data are selected from <code>data</code> using
<code>data[[use]]</code>. Usually, this value corresponds to either
"tn_trajectories" or "measures", depending on whether the time-normalized
trajectories or derived measures should be aggregated.</p></dd>


<dt>use_variables</dt>
<dd><p>a character vector specifying the mouse-tracking
variables to aggregate. If a data.frame with mouse-tracking measures is
provided as <code>data</code>, this corresponds to the column names. If a
trajectory array is provided, this argument should specify the labels of
respective array dimensions. If unspecified, all variables will be
aggregated.</p></dd>


<dt>use2</dt>
<dd><p>a character string specifying where the data containing the
condition information can be found. Defaults to "data" as
<code>data[["data"]]</code> usually contains all non mouse-tracking trial data.
Alternatively, a data.frame can be provided directly.</p></dd>


<dt>use2_variables</dt>
<dd><p>a character string (or vector) specifying the variables
(in <code>data[[use2]]</code>) across which the trajectories / measures will be
aggregated. For each combination of levels of the grouping variable(s),
aggregation will be performed separately using <a href="https://dplyr.tidyverse.org/reference/summarise_all.html" class="external-link">summarize_at</a>.</p></dd>


<dt>subject_id</dt>
<dd><p>an optional character string specifying the column that
contains the subject identifier. If specified, aggregation will be
performed within subjects first (i.e., within subjects for all available
values of the grouping variables specified in <code>use2_variables</code>).</p></dd>


<dt>trajectories_long</dt>
<dd><p>logical indicating if the reshaped trajectories
should be returned in long or wide format. If <code>TRUE</code>, every recorded
position in a trajectory is placed in another row (whereby the order of the
positions is logged in the variable <code>mt_seq</code>). If <code>FALSE</code>, every
trajectory is saved in wide format and the respective positions are indexed
by adding an integer to the corresponding label (e.g., <code>xpos_1</code>,
<code>xpos_2</code>, ...). Only relevant if <code>data[[use]]</code> contains
trajectories.</p></dd>


<dt>...</dt>
<dd><p>additional arguments passed on to <a href="mt_reshape.html">mt_reshape</a> (such as
<code>subset</code>).</p></dd>

</dl></div>
    <div id="value">
    <h2>Value</h2>
    

<p>A <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a> containing the aggregated data.</p>
    </div>
    <div id="see-also">
    <h2>See also</h2>
    <div class="dont-index"><p><a href="mt_aggregate_per_subject.html">mt_aggregate_per_subject</a> for aggregating mouse-tracking
measures and trajectories per subject.</p>
<p><a href="https://dplyr.tidyverse.org/reference/summarise_all.html" class="external-link">summarize_at</a> for aggregating data using the <code>dplyr</code>
package.</p></div>
    </div>
    <div id="author">
    <h2>Author</h2>
    <p>Pascal J. Kieslich</p>
<p>Felix Henninger</p>
    </div>

    <div id="ref-examples">
    <h2>Examples</h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co"># Time-normalize trajectories</span></span></span>
<span class="r-in"><span><span class="va">mt_example</span> <span class="op">&lt;-</span> <span class="fu"><a href="mt_time_normalize.html">mt_time_normalize</a></span><span class="op">(</span><span class="va">mt_example</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Aggregate time-normalized trajectories per condition</span></span></span>
<span class="r-in"><span><span class="va">average_trajectories</span> <span class="op">&lt;-</span>  <span class="fu">mt_aggregate</span><span class="op">(</span><span class="va">mt_example</span>,</span></span>
<span class="r-in"><span>  use<span class="op">=</span><span class="st">"tn_trajectories"</span>,</span></span>
<span class="r-in"><span>  use2_variables<span class="op">=</span><span class="st">"Condition"</span></span></span>
<span class="r-in"><span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Calculate mouse-tracking measures</span></span></span>
<span class="r-in"><span><span class="va">mt_example</span> <span class="op">&lt;-</span> <span class="fu"><a href="mt_measures.html">mt_measures</a></span><span class="op">(</span><span class="va">mt_example</span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Aggregate measures per condition</span></span></span>
<span class="r-in"><span><span class="va">average_measures</span> <span class="op">&lt;-</span> <span class="fu">mt_aggregate</span><span class="op">(</span><span class="va">mt_example</span>,</span></span>
<span class="r-in"><span>  use<span class="op">=</span><span class="st">"measures"</span>, use_variables<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"MAD"</span>, <span class="st">"AD"</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>  use2_variables<span class="op">=</span><span class="st">"Condition"</span></span></span>
<span class="r-in"><span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
<span class="r-in"><span><span class="co"># Aggregate measures per condition</span></span></span>
<span class="r-in"><span><span class="co"># first within subjects and then across subjects</span></span></span>
<span class="r-in"><span><span class="va">average_measures</span> <span class="op">&lt;-</span> <span class="fu">mt_aggregate</span><span class="op">(</span><span class="va">mt_example</span>,</span></span>
<span class="r-in"><span>  use<span class="op">=</span><span class="st">"measures"</span>, use_variables<span class="op">=</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"MAD"</span>, <span class="st">"AD"</span><span class="op">)</span>,</span></span>
<span class="r-in"><span>  use2_variables<span class="op">=</span><span class="st">"Condition"</span>,</span></span>
<span class="r-in"><span>  subject_id<span class="op">=</span><span class="st">"subject_nr"</span></span></span>
<span class="r-in"><span><span class="op">)</span></span></span>
<span class="r-in"><span></span></span>
</code></pre></div>
    </div>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
    </nav></div>
</div>


      <footer><div class="copyright">
  <p></p><p>Developed by Pascal J. Kieslich, Dirk U. Wulff, Felix Henninger, Jonas M. B. Haslbeck.</p>
</div>

<div class="pkgdown">
  <p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

      </footer></div>

  


  

  </body></html>

