mean_kinship: Calculate the weighted mean kinship

View source: R/mean_kinship.R

mean_kinshipR Documentation

Calculate the weighted mean kinship

Description

This function computes a particular weighted mean kinship that arises in the context of kinship and FST estimators and in the definition of the effective sample size. This function allows for weights to be zero or even negative, but they are internally normalized to sum to one.

Usage

mean_kinship(kinship, weights = NULL)

Arguments

kinship

The kinship matrix

weights

Weights for individuals (optional). If NULL (default), uniform weights are used.

Value

The weighted mean kinship matrix, equivalent to drop( weights %*% kinship %*% weights ) after normalizing weights to sum to one.

Examples

# construct a dummy kinship matrix
kinship <- matrix(c(0.5, 0, 0, 0.6), nrow=2)

# this is the ordinary mean
mean_kinship(kinship)

# weighted mean with twice as much weight on the second individual
# (weights are internally normalized to sum to one)
weights <- c(1, 2)
mean_kinship(kinship, weights)


popkin documentation built on Jan. 7, 2023, 1:26 a.m.