% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/association_rules.R
\name{association_rules}
\alias{association_rules}
\title{Discover Association Rules from Sequential or Transaction Data}
\usage{
association_rules(
  x,
  min_support = 0.1,
  min_confidence = 0.5,
  min_lift = 1,
  max_length = 5L
)
}
\arguments{
\item{x}{Input data. Accepts:
\describe{
\item{netobject}{Uses \code{$data} sequences — each sequence becomes
a transaction of its unique states.}
\item{list}{Each element is a character vector of items (one transaction).}
\item{data.frame}{Wide format: each row is a transaction, character
columns are item occurrences. Or a binary matrix (0/1).}
\item{matrix}{Binary transaction matrix (rows = transactions,
columns = items).}
}}

\item{min_support}{Numeric. Minimum support threshold. Default: 0.1.}

\item{min_confidence}{Numeric. Minimum confidence threshold. Default: 0.5.}

\item{min_lift}{Numeric. Minimum lift threshold. Default: 1.0.}

\item{max_length}{Integer. Maximum itemset size. Default: 5.}
}
\value{
An object of class \code{"net_association_rules"} containing:
\describe{
\item{rules}{Data frame with columns: antecedent (list), consequent (list),
support, confidence, lift, conviction, count, n_transactions.}
\item{frequent_itemsets}{List of frequent itemsets per level k.}
\item{items}{Character vector of all items.}
\item{n_transactions}{Integer.}
\item{n_rules}{Integer.}
\item{params}{List of min_support, min_confidence, min_lift, max_length.}
}
}
\description{
Discovers association rules using the Apriori algorithm with proper
candidate pruning. Accepts \code{netobject} (extracts sequences as
transactions), data frames, lists, or binary matrices.

Support counting is vectorized via \code{crossprod()} for 2-itemsets
and logical matrix indexing for k-itemsets.
}
\details{
\subsection{Algorithm}{

Uses level-wise Apriori (Agrawal & Srikant, 1994) with the full pruning
step: after the join step generates k-candidates, all (k-1)-subsets are
verified as frequent before support counting. This is critical for
efficiency at k >= 4.
}

\subsection{Metrics}{

\describe{
\item{support}{P(A and B). Fraction of transactions containing both
antecedent and consequent.}
\item{confidence}{P(B | A). Fraction of antecedent transactions that
also contain the consequent.}
\item{lift}{P(A and B) / (P(A) * P(B)). Values > 1 indicate positive
association; < 1 indicate negative association.}
\item{conviction}{(1 - P(B)) / (1 - confidence). Measures departure
from independence. Higher = stronger implication.}
}
}
}
\examples{
# From a list of transactions
trans <- list(
  c("plan", "discuss", "execute"),
  c("plan", "research", "analyze"),
  c("discuss", "execute", "reflect"),
  c("plan", "discuss", "execute", "reflect"),
  c("research", "analyze", "reflect")
)
rules <- association_rules(trans, min_support = 0.3, min_confidence = 0.5)
print(rules)

# From a netobject (sequences as transactions)
seqs <- data.frame(
  V1 = sample(LETTERS[1:5], 50, TRUE),
  V2 = sample(LETTERS[1:5], 50, TRUE),
  V3 = sample(LETTERS[1:5], 50, TRUE)
)
net <- build_network(seqs, method = "relative")
rules <- association_rules(net, min_support = 0.1)

}
\references{
Agrawal, R. & Srikant, R. (1994). Fast algorithms for mining association
rules. In \emph{Proc. 20th VLDB Conference}, 487--499.
}
\seealso{
\code{\link{build_network}}, \code{\link{predict_links}}
}
