\name{C2ST}
\alias{C2ST}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
Diagnostics of the fit
}
\description{
\code{C2ST} implements a classifier two-sample test, testing whether a classifier is able to distinguish samples produced in two ways: samples produced by the data-generating simulator function, and samples produced by \code{simulate(\var{SLik_j object}, ...)}. Ideally (i.e., if the likelihood surface inference is exact), the two types of samples should be indistinguishable, and thus the probability of correct classificication should be 0.5. 

Note that at least in some cases, RMSE computations for the likelihood ratios appear to be a better diagnostic of the reliability of the inferences.

In this current implementation of this procedure, parameter values are taken from the latest rows of the reference table (see \code{nsim} argument); a random-forest classifier is used; and the proportion of correctly classified samples (according to the out-of-bag classification) is tested by a one-tailed binomial test. The test is conservative because the out-of-bag classification does not exactly represent classification performance on an independent test set. 
}
\usage{
C2ST(object, nsim, resimulate = FALSE,
     Simulate = get_from(object, "Simulate"), ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{object}{
An object of class \code{SLik_j} as produced by the up-to-date workflow. 
}
  \item{nsim}{
Numeric: Number of simulations in each distribution: samples will be drawn for the parameter values in the \code{nsim} latest rows of the reference table.
}
  \item{resimulate}{
Boolean: whether to actually resimulate the data-generating process. If FALSE (the default), the sample simulations in the reference table are instead used, which both (i) may save simulation time and, if projections were used in the inference workflow, (ii) obviates the need to apply such projections. 
}
  \item{Simulate}{
The process simulation function (not necessarily used: see \code{resimulate} argument), in one of the formats handled for the \code{Simulate} argument of \code{\link{add_reftable}}.
}
  \item{\dots}{
Other arguments for development purposes, not documented.
}
}
\value{
A list containing the object \code{test}, itself the result of \code{\link[stats]{binom.test}}.

As a side effect, this result is also stored in the input \code{object} if the latter was created  (or regenerated by re-running \code{MSL} on it) by a recent version (>2.3.8) of \pkg{Infusion}. This stored result can be properly extracted by using \code{get_from(\var{SLik_j object}, which="C2ST")}.
}
\references{
  David Lopez-Paz and Maxime Oquab (2017) Revisiting classifier two-sample tests.
  International Conference on Learning Representations.
  \url{https://openreview.net/forum?id=SJkXfE5xx}
}
\seealso{\code{\link{get_from}}}
\examples{
# Run example from help("example_reftable") and then
\dontrun{
C2ST(slik_j)
}
}