R/gen_pop_tpd.R

Defines functions gen_pop_tpd

Documented in gen_pop_tpd

##* GENERATE POPULATION THERMAL-PERFORMANCE DATA

#' Generate a population's thermal-performance data
#'
#' Generate a thermal-performance data set for a population multiple individiuals
#'
#' @param N Number of individiuals forming the population
#'
#' @param Topt The thermal optimum.
#'
#' @param CTmax The critical thermal maximum. Needs to be > Topt
#'
#' @param CTmin The critical thermal minimum. Needs to be < Topt
#'
#' @param Pmax The maximal performance capacity.
#'
#' @param Pmin The mimimal performance capacity. Needs to be < Pmax
#'
#' @param Error The amount of error/noise to be introduced to generate unique data. In units of standard deviation.
#'
#' @param Samples Number of samples to be extracted for each individual
#'
#' @param Degree Degree of the polynomial regression that will be created to extract the data.
#'
#' @return A dataset of three columns: "ID" for individual identifier,  "T" for temperature and "P" for performance.
#'


gen_pop_tpd <- function(N, Topt, CTmax, CTmin, Pmax, Pmin, Error, Samples, Degree){

  # Generate first individual
  pop_tpd <- data.frame(ID = rep(gen_id(), Samples), gen_tpd(Topt, CTmax, CTmin, Pmax, Pmin, Error, Samples, Degree))

  # Loop for the rest
  for(i in 2:N){

    # Generate a new individual
    x <- data.frame(ID = rep(gen_id(), Samples), gen_tpd(Topt, CTmax, CTmin, Pmax, Pmin, Error, Samples, Degree))

    # Attach new individual to the population dataset
    pop_tpd <- rbind(pop_tpd, x)

  }

  return(pop_tpd)

}
ggcostoya/tpcurves2 documentation built on Jan. 1, 2021, 2:19 a.m.