% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pedprod.R
\name{pedprod}
\alias{pedprod}
\title{Matrix-Free Pedigree Relationship Products}
\usage{
pedprod(ped, x, method = c("A", "Ainv"))
}
\arguments{
\item{ped}{A complete pedigree accepted by \code{\link{tidyped}}, preferably
an existing \code{tidyped} object.}

\item{x}{A numeric or logical vector, or a numeric or logical matrix.
An unnamed vector must have one value per pedigree individual in
\code{IndNum} order. A named vector may contain a subset of individuals;
omitted individuals receive value zero. For a matrix, the same rules apply
to its rows and \code{rownames}.}

\item{method}{Character scalar. \code{"A"} (default) computes products with
the additive relationship matrix. \code{"Ainv"} computes products with its
inverse.}
}
\value{
For vector input, a named numeric vector in pedigree order. For
  matrix input, a numeric matrix whose rows are in pedigree order; input
  column names are preserved.
}
\description{
Computes products of the form \eqn{A x}, \eqn{A X}, \eqn{A^{-1} x}, or
\eqn{A^{-1} X} directly from an ordered pedigree, without constructing the
full additive relationship matrix \eqn{A}. This is useful for large
pedigrees where explicitly storing the dense \eqn{n \times n} matrix is
infeasible.
}
\details{
For an ordered pedigree, the additive relationship matrix can be written as
\deqn{A = T D T^\prime,}
where \eqn{T} is the transmission matrix and \eqn{D} contains Mendelian
sampling variances. \code{pedprod()} applies these factors through backward
and forward pedigree traversals. For an \eqn{n \times p} right-hand side,
computation requires \eqn{O(np)} time and working memory rather than
materializing the \eqn{O(n^2)} relationship matrix.

Named inputs are aligned by individual ID. Every supplied name must occur in
\code{ped$Ind}, and duplicate, missing, or empty names are rejected. Missing
values and non-finite input values are also rejected to avoid propagating an
invalid value through all descendants or relatives.
}
\examples{
tped <- tidyped(small_ped)

# Equal contributions from two candidates; unspecified individuals are zero.
contributions <- c(Z1 = 0.5, Z2 = 0.5)
relationship_to_group <- pedprod(tped, contributions)

# Average additive relationship among the weighted candidates: c' A c.
sum(contributions * relationship_to_group[names(contributions)])

# Multiple contribution schemes can be evaluated in one call.
schemes <- cbind(
  Equal = c(A = 0.5, B = 0.5),
  SireA = c(A = 1.0, B = 0.0)
)
pedprod(tped, schemes)

}
\references{
Colleau, J. J. (2002). An indirect approach to the extensive calculation of
relationship coefficients. \emph{Genetics Selection Evolution}, 34,
409--421. \doi{10.1051/gse:2002015}

Colleau, J. J., Palhiere, I., Rodriguez-Ramilo, S. T., & Legarra, A.
(2017). A fast indirect method to compute functions of genomic relationships
concerning genotyped and ungenotyped individuals, for diversity management.
\emph{Genetics Selection Evolution}, 49, 87.
\doi{10.1186/s12711-017-0363-9}
}
\seealso{
\code{\link{pedmat}} for explicitly constructing relationship
  matrices and \code{\link{pedrel}} for group relationship summaries.
}
