emulator: Calculate and plot fit.

View source: R/emulator.R

emulatorR Documentation

Calculate and plot fit.

Description

This function fits a function of the form y = a + b * x ^ d for the given data.

Usage

emulator(
  data,
  name_x,
  name_y,
  name_modelstat = NULL,
  treat_as_feasible = c(2, 7),
  userfun = function(param, x) return(param[[1]] + param[[2]] * x^param[[3]]),
  initial_values = c(0, 0, 1),
  outlier_range = 1.5,
  n_suff = 1,
  fill = FALSE,
  output_path = "emulator",
  fitname = "linear",
  create_pdf = TRUE,
  ...
)

Arguments

data

MAgPIE object containing at least two variables and the modelstatus

name_x

Name of the variable in data that will be treated as x in the fit

name_y

Name of the variable in data that will be treated as y in the fit

name_modelstat

Name of the variable that contains the modelstatus

treat_as_feasible

GAMS model status codes that will be regarded feasible. See https://www.gams.com/24.8/docs/userguides/mccarl/modelstat_tmodstat.htm

userfun

Function to fit. User can provide a functional form using the following syntax: function(param,x)return(param[[1]] + param[[2]] * x ^param[[3]]). This function is the default.

initial_values

Vector with initial values of the fit coefficients.

outlier_range

Before the actual fit a linear pre-fit is performed. Based on their distance to this pre-fit the data points are allocated to quartiles. A data point is considered an outlier if it is more than outlier_range times of the interquartile range away from the the upper or lower end of the interquartile range http://colingorrie.github.io/outlier-detection.html.

n_suff

Minial number (default=1) of data points in a specific year and region that will be regarded as sufficient to perform a fit. If the number of available data points is less no fit will be generated for this year and region.

fill

Logical (default=FALSE) indicating whether data will be copied from subsequent year if in the current year not enough data points are avaialbe.

output_path

Path to save the output to

fitname

Name that describes the fit (default: linear) and will be used for naming the output folders.

create_pdf

Logical indicating whether a pdf should be produced that compiles all figures.

...

Arguments passed on to the optim function in calcualte_fit. Useful to define bounds on fit coefficients.

Value

MAgPIE object containning fit coefficients

Author(s)

David Klein


pik-piam/remulator documentation built on Oct. 19, 2023, 4:07 p.m.