% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hmetad.R
\name{aggregate_metad}
\alias{aggregate_metad}
\title{Aggregate \code{data} by \code{response}, \code{confidence}, and other columns}
\usage{
aggregate_metad(
  data,
  ...,
  .stimulus = "stimulus",
  .response = "response",
  .confidence = "confidence",
  .joint_response = "joint_response",
  .name = "N",
  K = NULL
)
}
\arguments{
\item{data}{The data frame to aggregate}

\item{...}{Grouping columns in \code{data}. These columns will be converted to
factors.}

\item{.stimulus}{The name of "stimulus" column}

\item{.response}{The name of "response" column}

\item{.confidence}{The name of "confidence" column}

\item{.joint_response}{The name of "joint_response" column}

\item{.name}{The name of the resulting column containing trial counts}

\item{K}{The number of confidence levels in \code{data}. If \code{NULL}, this is
estimated from \code{data} using the maximum value of either the confidence
column or joint response column.}
}
\value{
A tibble with one row per combination of the variables in \code{...}, and
another column named by the value of \code{.response} containing trial counts.
For \eqn{K} confidence levels, this will be an \eqn{N \times K*4} matrix,
such that the columns represent (for stimulus \eqn{S}, type 1 response
\eqn{R}, and type 2 response \eqn{C}):
\deqn{
 [N_{S=0, R=0, C=K}, \ldots, N_{S=0, R=0, C=1}, \\
 N_{S=0, R=1, C=1}, \ldots, N_{S=0, R=1, C=K}, \\
 N_{S=1, R=0, C=K}, \ldots, N_{S=1, R=0, C=1}, \\
 N_{S=1, R=1, C=1}, \ldots, N_{S=1, R=1, C=K}] \\
}{
[N(R=0, C=K, S=0), ..., N(R=0, C=1, S=0),
 N(R=1, C=1, S=0), ..., N(R=1, C=K, S=0),
 N(R=0, C=K, S=1), ..., N(R=0, C=1, S=1),
 N(R=1, C=1, S=1), ..., N(R=1, C=K, S=1)]
}
}
\description{
Counts number of rows in \code{data} with unique combinations values in the
columns \code{response}, \code{confidence}, and any other columns in \code{...}.
}
\details{
The data frame \code{data} must have one column with the name given by
\code{.stimulus}. Additionally, it must have either:
\itemize{
\item Two columns with names given by \code{.response} and \code{.confidence}
\item One column with the name given by \code{.joint_response}
}

Finally, it must also have columns for any additional variables in \code{...}.
}
\examples{
# aggregate a dataset without grouping factors
d <- sim_metad()
aggregate_metad(d)

# aggregate a dataset with grouping factors
d2 <- sim_metad_condition()
aggregate_metad(d2, condition)

# can also aggregate ignoring grouping factors
aggregate_metad(d2)

# aggregate data with only `joint_response` column
library(dplyr)
d |>
  ungroup() |>
  mutate(joint_response = joint_response(
    response, confidence,
    max(as.integer(confidence))
  )) |>
  select(-response, -confidence) |>
  aggregate_metad()

}
