objectiveFunction: Objective function to be minimised in a search. Returns the...

View source: R/functions.R

objectiveFunctionR Documentation

Objective function to be minimised in a search. Returns the negative log likelihood

Description

Calculates the negative log likelihood of a model given a calibrated date matrix

Usage

objectiveFunction(pars, PDarray, type, timeseries=NULL)

Arguments

pars

A numeric vector of parameters.

PDarray

A data frame typically generated by phaseCalibrator, such that each column represents the PD of each calibrated date (or phase), and row names are the corresponding years.

type

Choose from the following currently available models. Composite models can be achieved using a vector of more than one type. For example, c('norm','power') will be a composite model, where the first two parameters are the mean and SD, the 3rd and 4th parameters determine the power distribution component, for example if modelling taphonomy.

timeseries

Only if 'type' = 'timeseries', a data frame should be provided containing columns x and y that define the timeseries as year and value respectively.

Details

If type is 'CPL', pars must be an odd length each between 0 and 1 since parameters correspond to: (y,x,...y). If type is 'exp', pars must be a single positive or negative numeric (the exponential rate can be growth or decay). Typically this parameter should be close to zero (-0.1 to 0.1) to avoid numbers beyond floating point limits) If type is 'norm', pars must have length 2 (mean and sd) If type is 'uniform', then pars must be NA.

Value

Returns a single value, the negative log likelihood.

Examples

	# generate a PD array from a handful of dates
	data <- subset(SAAD, site %in% c('Carrizal','Pacopampa'))
	CalArray <- makeCalArray(shcal13, calrange = c(2000,6000))
	PD <- phaseCalibrator(data, CalArray)

	# the negative log likelihood given some random parameters for a 3-CPL model
	pars <- runif(5)
	objectiveFunction(pars, PD, type='CPL')	

	# the negative log likelihood given a random exponential model
	pars <- runif(1, -0.01, 0.01)
	objectiveFunction(pars, PD, type='exp')	

	# the negative log likelihood given a random Gaussian model
	pars <- c(runif(1, 2000, 6000), runif(1, 100, 1000))
	objectiveFunction(pars, PD, type='norm')	

	# the negative log likelihood given a uniform model
	objectiveFunction(pars=NA, PD, type='uniform')	

	# the negative log likelihood given a uniform model with taphonomy
	pars <- c(NA, runif(1, 0, 20000), runif(1, -3, 0))
	objectiveFunction(pars=pars, PD, type=c('uniform','power'))	

AdrianTimpson/ADMUR documentation built on July 2, 2024, 8:39 p.m.