% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/PFCR.R
\name{PFCR}
\alias{PFCR}
\title{Power Fuzzy Cluster-wise Regression}
\usage{
PFCR(
  X,
  Y,
  K,
  m = 2,
  q = 2,
  distance = "Minkowski",
  p = 2,
  alpha = 0.5,
  beta = 10^15,
  threshold = 0.01,
  max.iter = 100
)
}
\arguments{
\item{X}{An \verb{n x dx} data frame or matrix of covariates.}

\item{Y}{An \verb{n x dy} data frame or matrix of dependent variables.}

\item{K}{Number of clusters (positive integer).}

\item{m}{Fuzzifier, must be strictly greater than 1. Default \code{2}.}

\item{q}{Distance exponent, must be strictly greater than 0. Default \code{2}.}

\item{distance}{Either \code{"Minkowski"} or \code{"Mahalanobis"}.}

\item{p}{Minkowski exponent (\verb{>= 1}). Ignored when
\code{distance = "Mahalanobis"}. Default \code{2}.}

\item{alpha}{Regularisation weight for the Mahalanobis covariance.
Default \code{0.5}.}

\item{beta}{Eigenvalue ratio bound for the Mahalanobis covariance.
Default \code{1e15}.}

\item{threshold}{Convergence tolerance on successive coefficient updates.
Default \code{0.01}.}

\item{max.iter}{Maximum number of iterations. Default \code{100}.}
}
\value{
A list with elements:
\describe{
\item{B}{Array of regression coefficients.}
\item{d}{Data frame of distances (\verb{n x K}).}
\item{p}{Data frame of membership degrees (\verb{n x K}).}
\item{JDF}{Vector of objective-function values per iteration.}
\item{l}{Hard cluster labels (length \code{n}).}
\item{rho, cov}{(Mahalanobis only) cluster proportions and covariance
matrices.}
}
}
\description{
Fits \code{K} cluster-specific linear models \eqn{Y = X B_k + \varepsilon},
selecting an internal solver based on the chosen distance and exponent.
}
\references{ P.T. Nguyen, C. Tortora, and A. Punzo. (2026)
"Power fuzzy clustering: flexible distance metrics and inclusion of covariates". 
IEEE Transactions on Fuzzy Systems 10.1109/TFUZZ.2026.3683998
}
\examples{
\donttest{
library(flexCWM)
data("students")
Y <- students[, 2:3]
X <- students[, 4]
l <- students[, 1]


# --- 1a. Mahalanobis distance (default m=2, q=2) ---
resMah <- PFCR(X, Y, K = 2, distance = "Mahalanobis")
table(resMah$l, l)

# --- 1b. Minkowski distance (default m=2, q=2, p=2) ---
resMin <- PFCR(X, Y, K = 2)
table(resMin$l, l)

# --- 1c. Mahalanobis with m=3, q=3 ---
resMah33 <- PFCR(X, Y, K = 2, m = 3, q = 3, distance = "Mahalanobis")
table(resMah33$l, l)

# --- Plots for the (m=3, q=3) Mahalanobis result ---
pp    <- apply(resMah33$p, 1, max)
color <- ifelse(resMah33$l == unique(resMah33$l)[1], "blue", "red")

plot(Y, col = color, pch = 16, cex = pp,
     main = "PFCR Mahalanobis (3,3)")

plot(X, Y[, 1], ylab = "HEIGHT", xlab = "HEIGHT.F",
     pch = 16, cex = pp, col = color,
     main = "PFCR Mahalanobis (3,3)")
abline(resMah33$B[1, 1, 1], resMah33$B[2, 1, 1], col = "blue", lwd = 2)
abline(resMah33$B[1, 1, 2], resMah33$B[2, 1, 2], col = "red",  lwd = 2)

plot(X, Y[, 2], ylab = "WEIGHT", xlab = "HEIGHT.F",
     pch = 16, cex = pp, col = color,
     main = "PFCR Mahalanobis (3,3)")
abline(resMah33$B[1, 2, 1], resMah33$B[2, 2, 1], col = "blue", lwd = 2)
abline(resMah33$B[1, 2, 2], resMah33$B[2, 2, 2], col = "red",  lwd = 2)
}

}
