Computes the total loss across all pairwise combinations of rows in a matrix.
Arguments
- x
A numeric vector, matrix, or data frame. If not a matrix, it will be coerced to one after applying the transformation function.
- fun
A function to compute the loss for each pairwise difference. The package supports the alignment loss (
alf) and the approximate L0 penalty (l0a), but users can provide custom functions as well.- trans
A transformation function to apply to
xbefore computing pairwise differences. Default isidentity(no transformation).- rescale
Either
"df"(default) to rescale the total loss by(nrow - 1) / ncombn(nrow, 2), wherenrowis the number of rows, or a numeric value (likely between 0 and 1) to multiply the total loss by. Withrescale = "df"and a 0/1-valuedfunsuch asl0a, the returned value approximates the number of degrees of freedom of non-invariance in the block:0when all rows are equal (full invariance) andnrow - 1per column when all rows differ (fully free). It soft-counts how many of thenrow - 1pairwise-invariance constraints per column are violated.- ...
Additional arguments passed to the loss function
fun.
Details
The function works by:
Applying the transformation function
transto the inputxConverting the result to a matrix
Generating all possible pairwise combinations of row indices
Computing the difference between each pair of rows
Applying the loss function
funto each differenceSumming all the individual losses
effective_df() builds on this degrees-of-freedom interpretation
(rescale = "df" with a 0/1-valued fun such as l0a) to report the
effective number of parameters, and hence the effective model degrees of
freedom, of penalized fits returned by penalized_est().