computeDiffs: Compute differences between model cases

View source: R/computeDiffs.R

computeDiffsR Documentation

Compute differences between model cases

Description

Function to compute differences between model cases

Usage

computeDiffs(
  x,
  base = 1,
  cast = "process+fleet+category+type+pc+x+m+s+z+y",
  fun = wtsUtilities::Sum,
  sense = 1,
  type = c("percent", "absolute")
)

Arguments

x
  • dataframe in canonical format to cast for differences

base
  • name (or number) of case to use as base

cast
  • cast'ing factors (left side of reshape2::dcast() cast'ing equation, with "case" on the righthand side)

fun
  • aggregation function (default is wtsUtilities::Sum())

sense
  • multiplier on difference

type
  • type of difference ("absolute" or "percent")

Details

The differences are calculated as sense*(case-base). If differences in negative log-likelihoods are desired, it may be useful to set sense to -1 so that improvements in fits from base to case are reflected as positive values.

Uses reshape2::dcast() to aggregate values within factor levels defined by the cast'ing formula prior to differencing. The default cast string is "process+fleet+category+type+pc+x+m+s+z+y", yielding the cast formula "process+fleet+category+type+pc+x+m+s+z+y~cast" (i.e., no aggregation, but possibly transformation if fun transforms values prior to aggregating them).

The columns of the returned dataframe will include the factors included in the input cast'ing string cast, as well as columns of the form "absdiff-case" or "pctdiff-case", where "case" are the names of the non-base cases. Note that the latter column names can be returned to "case" by colnames(xd) = gsub("^.*-","",colnames(xd)), where x is the result of computeDiffs.

Value

a dataframe (see details) with attributes "base", "type", and "sense" (reflecting the input values).


wStockhausen/rCompTCMs documentation built on Aug. 27, 2024, 7:15 p.m.