Retrieves relationship coefficients between individuals from a pedmatrix object. For compact matrices, automatically handles lookup of merged full-siblings.
Arguments
- x
A pedmatrix object created by
pedmatrix.- id1
Character, first individual ID.
- id2
Character, second individual ID. If
NULL, returns the entire row of relationships forid1.
Value
If
id2is provided: numeric value (relationship coefficient)If
id2isNULL: named numeric vector (id1's row)Returns
NAif individual not found
Details
For compact matrices (compact = TRUE), this function automatically
maps individuals to their family representatives. For methods A, D, and AA,
it can compute the correct relationship even between merged full-siblings
using the formula:
A: \(a_{ij} = 0.5 * (a_{is} + a_{id})\) where s, d are parents
D: \(d_{ij} = a_{ij}^2\) (for full-sibs in same family)
AA: \(aa_{ij} = a_{ij}^2\)
Note
Inverse matrices (Ainv, Dinv, AAinv) are not supported because inverse matrix elements do not represent meaningful relationship coefficients.
Examples
tped <- tidyped(small_ped)
A <- pedmatrix(tped, method = "A", compact = TRUE)
# Query specific pair
query_relationship(A, "A", "B")
#> [1] 0
# Query merged full-siblings (works with compact)
query_relationship(A, "Z1", "Z2")
#> [1] 0.5507812
# Get all relationships for one individual
query_relationship(A, "A")
#> A B F I J1 J2 N O R C
#> 1.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.50000
#> E Q G H K M T U V W
#> 0.50000 0.00000 0.25000 0.25000 0.25000 0.25000 0.00000 0.12500 0.25000 0.12500
#> X Y Z1
#> 0.18750 0.06250 0.09375