R/param_grid.R

Defines functions param_grid

Documented in param_grid

#' Make all combinations of parameters for parameter matrix
#'
#' This takes a df of parameter ranges generated by param_ranges()
#' and applied param_seqs() to turn any that vary into a sequence spanning
#' the range.
#' These sequences (if any) are then turned into a matrix of all possible values
#' if none vary, then a single row of data is returned
#'
#'
#' @param param.seqs sequence of parameters to use (in form of vector)
#'
#' @return param.grid Dataframe of parameter combinations
#'
#' @examples
#'
#' # "Grid" with no variation = single row of data
#' param_grid()
#'
#' # Grid with variation
#'
#' ##Generate parameters for Figure 28.2
#' param.ranges <- param_ranges(figure = 28.3)
#'
#' ##generate parameter sequences
#' param.seqs <- param_seqs(param.ranges = param.ranges)
#' param.seqs[1:3]
#'
#' ##generate grid
#' param.grid <- param_grid(param.seqs)
#'
#' ## look at snippet of raw data
#' param.grid[1:10,1:5]
#'
#' ## look at summary of columns that vary
#' summary(param.grid[,c("K.bc","K.bk","K.wg" )])
#'
#' ## conver colums that vary to factors then look at them
#' param.grid$K.bc <- factor(param.grid$K.bc)
#' param.grid$K.bk <- factor(param.grid$K.bk)
#' param.grid$K.wg <- factor(param.grid$K.wg)
#'
#' summary(param.grid[,c("K.bc","K.bk","K.wg" )],10)
#' @export

param_grid <- function(param.seqs = param_seqs(param_ranges(figure = 28.3))){


  if(is.list(param.seqs) == FALSE){
    message("Input is not a list.")
    stop()
  }

  param.grid <- do.call(what = expand.grid,param.seqs)



  #Diagnostic
  message("The dimension of the fully expanded dataframe is: \n", dim(param.grid)[1], " by ",dim(param.grid)[2])

  return(param.grid)
}
brouwern/FACavian documentation built on March 23, 2022, 10:07 a.m.