% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/permutation_test.R
\name{permutation_test}
\alias{permutation_test}
\title{Permutation Test for Stepwise Regression}
\usage{
permutation_test(
  formula,
  data,
  n = 1000,
  alpha = 0.1,
  include = NULL,
  strategy = "bidirection",
  metric = "SBC",
  type = "linear",
  verbose = FALSE
)
}
\arguments{
\item{formula}{A model formula defining the response and candidate predictors for
permutation testing.}

\item{data}{A data frame containing all variables referenced in \code{formula},
including response trait(s) and predictor variables.}

\item{n}{Integer number of permutations to run. Larger values provide more stable
empirical thresholds but increase computation time. Default is \code{1000}.}

\item{alpha}{Numeric significance level used to extract empirical cutoff values
from the permutation distributions. Must be between 0 and 1. Default is \code{0.1}.}

\item{include}{Optional character vector of variable names that should always be
included during stepwise model selection. If \code{NULL}, inclusion terms can be
inferred from interaction terms in \code{formula}. Default is \code{NULL}.}

\item{strategy}{Stepwise selection strategy passed to \code{StepReg::stepwise()}.
Typical values include \code{"forward"}, \code{"backward"}, and \code{"bidirection"}.
Default is \code{"bidirection"}.}

\item{metric}{Model selection metric used inside stepwise regression.
Typical values include \code{"AIC"}, \code{"BIC"}, or \code{"SBC"}.
Default is \code{"SBC"}.}

\item{type}{Type of regression model.
Typical values include \code{"linear"}, \code{"logistic"}, and \code{"poisson"}.
Default is \code{"linear"}.}

\item{verbose}{Logical; if \code{TRUE}, emit progress \code{message()}s during
permutations. Default is \code{FALSE}.}
}
\value{
A list containing the empirical significance thresholds for p-value and LOD score with:
  \itemize{
    \item \strong{cut_off}: A vector containing the empirical significance thresholds for p-value and LOD score
    \item \strong{pvalue}: A vector containing the p-values for each permutation
    \item \strong{lod}: A vector containing the LOD scores for each permutation
  }
}
\description{
Performs permutation tests for stepwise regression to determine empirical significance thresholds
for QTL detection using stepwise regression. This function implements a comprehensive permutation
testing framework for stepwise regression.
}
\details{
This function implements a comprehensive permutation testing framework.

\strong{Output Interpretation:}
\itemize{
  \item \strong{P-values}: Empirical significance thresholds for p-value
  \item \strong{LOD scores}: Empirical significance thresholds for LOD score
}
}
\examples{
\donttest{
# Example phenotype data
set.seed(1)
pheno_data <- data.frame(
  Trait1 = rnorm(100, mean = 100, sd = 15),
  Trait2 = rnorm(100, mean = 50, sd = 8),
  Popu = rep(c("Pop1", "Pop2"), each = 50)
)

# Example genotype data
geno_data <- matrix(sample(c(0,1,2), 100*50, replace = TRUE), 
                    nrow = 100, ncol = 50)
colnames(geno_data) <- paste0("M", 1:50)

data1 <- cbind(pheno_data,geno_data)

data1$Popu <- as.factor(data1$Popu)

terms <- c("Popu", paste0(colnames(geno_data), ":Popu"))
formula1 <- reformulate(terms, response = "Trait1")

cut_off_list <- permutation_test(formula1, data1, n = 10, alpha = 0.1)

formula2 <- reformulate(terms, response = "cbind(Trait1,Trait2)")

cut_off_list <- permutation_test(formula2, data1, n = 10, alpha = 0.1)
}

}
