#' Relative fitness
#'
#' Calculate relative fitness in the population under directional selection.
#'
#' `relative_fitness` takes lof fitness values from a population generated by
#' `initialise_population` and exponentiates them to calculate relative fitness.
#' Relative fitness is absolute fitness divided by mean absolute fitness.
#'
#' If individuals have NA phenotype the fitness is returned as zero.
#'
#' @param pop A list describing genotypes and positions in a population.
#' Output of `initialise_population`,
#'
#' @returns A vector of relative fitness values.
relative_fitness <- function(pop){
w <- exp(pop$phenotype)
w <- w / mean(w, na.rm = TRUE)
w[is.na(w)] <- 0
w
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.