% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/permTest.R, R/permTest.default.R,
%   R/permTest.formula.R
\name{permTest}
\alias{permTest}
\alias{permTest.default}
\alias{permTest.formula}
\title{Permutation test}
\usage{
permTest(x, ...)

\method{permTest}{default}(
  x,
  group,
  statistic = mean,
  success = NULL,
  B = 9999,
  alternative = "two.sided",
  plot.hist = TRUE,
  plot.qq = FALSE,
  xlab = NULL,
  ylab = NULL,
  title = NULL,
  seed = NULL,
  ...
)

\method{permTest}{formula}(formula, data = parent.frame(), subset, ...)
}
\arguments{
\item{x}{a numeric, logical, factor, or character vector. Logical, factor,
and character vectors with exactly two unique values are converted to 0/1,
and \code{mean} is used to compute the proportion.}

\item{\dots}{further arguments to be passed to or from methods.}

\item{group}{a factor variable with two levels. If \code{group} is a binary
numeric vector, it will be coerced into a factor variable.}

\item{statistic}{the statistic of interest.}

\item{success}{a character string naming the level of \code{x} to code as
1 when \code{x} is a logical, factor, or character variable. Defaults to
\code{NULL}, which uses the second factor level (alphabetically) or
\code{TRUE} for logical vectors.}

\item{B}{the number of resamples (positive integer greater than 2).}

\item{alternative}{the alternative hypothesis. Options are
\code{"two.sided"}, \code{"less"} or \code{"greater"}.}

\item{plot.hist}{a logical value. If \code{TRUE}, the permutation
distribution of the statistic is plotted.}

\item{plot.qq}{a logical value. If \code{TRUE}, then a normal
quantile-quantile plot of the resampled test statistic is created.}

\item{xlab}{an optional character string for the x-axis label}

\item{ylab}{an optional character string for the y-axis label}

\item{title}{an optional character string giving the plot title}

\item{seed}{optional argument to \code{\link{set.seed}}}

\item{formula}{a formula of the form \code{y ~ group} where \code{y} is
numeric and \code{group} is a factor variable.}

\item{data}{a data frame with the variables in the formula.}

\item{subset}{an optional expression specifying which observations to keep.}
}
\value{
Returns invisibly a vector of the replicates of the test statistic.
}
\description{
Permutation test to test a hypothesis involving two samples.
}
\details{
Permutation test to see if a population parameter is the same for two
populations. For instance, test \eqn{latex}{H_0: \mu_M = \mu_F} where
\eqn{latex}{\mu} denotes the population mean. The values of the numeric
variable are randomly assigned to the two groups and the difference of the
statistic for each group is calculated. The command will print the mean and
standard error of the distribution of the test statistic as well as a
P-value.

Observations with missing values are removed.
}
\section{Methods (by class)}{
\itemize{
\item \code{permTest(default)}: Permutation test

\item \code{permTest(formula)}: Permutation test

}}
\examples{

# Testing the difference in means
permTest(states03$ViolentCrime, states03$DeathPenalty)

#using formula syntax
permTest(ViolentCrime ~ DeathPenalty, data = states03, alt = "less")

# Testing the difference in proportions
permTest(penguin_survival$Status, penguin_survival$TagType, B = 999)

#using formula syntax
permTest(Status ~ TagType, data = penguin_survival, B = 999)

}
\references{
Tim Hesteberg's website:
\url{https://www.timhesterberg.net/bootstrap-and-resampling}
}
\author{
Laura Chihara
}
\keyword{permutation}
\keyword{randomization}
\keyword{resampling}
\keyword{test}
