Learn R Programming

popkin (version 1.3.23)

mean_kinship: 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)

Value

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

Arguments

kinship

The kinship matrix

weights

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab