% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/loi.R
\name{loi_perm}
\alias{loi_perm}
\title{Permutation Test for LoI}
\usage{
loi_perm(O, O_hat, n_perm = 999, conf.level = 0.95, seed = NULL)
}
\arguments{
\item{O}{Proximity matrix from the ensemble model (n x n)}

\item{O_hat}{Proximity matrix estimated by E2Tree (n x n)}

\item{n_perm}{Number of permutations (default: 999)}

\item{conf.level}{Confidence level for intervals (default: 0.95)}

\item{seed}{Random seed for reproducibility. Default is NULL.}
}
\value{
An object of class \code{"loi_perm"} containing:
\item{observed}{Observed nLoI value and decomposition (loi object)}
\item{statistic}{Observed nLoI value (scalar)}
\item{p.value}{Test p-value (one-sided, less)}
\item{ci}{Permutation-based confidence interval for nLoI}
\item{null_dist}{Null distribution of nLoI values}
\item{null_mean}{Mean of the null distribution}
\item{null_sd}{Standard deviation of the null distribution}
\item{z_stat}{Standardized Z statistic}
\item{n_perm}{Number of permutations}
\item{conf.level}{Confidence level}
}
\description{
Performs a permutation test using row/column permutation to assess
whether the E2Tree reconstruction is significantly better than expected
by chance.
}
\details{
The test uses \strong{simultaneous row/column permutation} of
\eqn{\hat{O}}: for each replicate, a random permutation \eqn{\pi}
of \eqn{\{1, \ldots, n\}} is drawn and \eqn{\hat{O}^\pi =
\hat{O}[\pi, \pi]} is computed. This preserves the block-diagonal
structure of \eqn{\hat{O}} while breaking the correspondence with
\eqn{O}.

The null hypothesis is: the E2Tree labeling is unrelated to the
ensemble structure. Under H1 (good reconstruction), the observed
nLoI should be significantly \emph{lower} than the null distribution.

P-values include the +1 correction of Phipson & Smyth (2010).
}
\examples{
\donttest{
n <- 50
O <- matrix(runif(n^2, 0.3, 1), n, n)
O <- (O + t(O)) / 2; diag(O) <- 1
O_hat <- O + matrix(rnorm(n^2, 0, 0.05), n, n)
O_hat <- pmin(pmax((O_hat + t(O_hat)) / 2, 0), 1); diag(O_hat) <- 1

result <- loi_perm(O, O_hat, n_perm = 199, seed = 42)
print(result)
summary(result)
plot(result)
}

}
