normL2: L2 norm between data and model prediction

View source: R/objClass.R

normL2R Documentation

L2 norm between data and model prediction

Description

For parameter estimation and optimization, an objective function is needed. normL2 returns an objective function for the L2 norm of data and model prediction. The resulting objective function can be used for optimization with the trust optimizer, see mstrust.

Usage

normL2(data, x, errmodel = NULL, times = NULL, attr.name = "data")

Arguments

data

object of class datalist

x

object of class prdfn

errmodel

object of class obsfn. errmodel does not need to be defined for all conditions.

times

numeric vector, additional time points where the prediction function is evaluated. If NULL, time points are extacted from the datalist solely. If the prediction function makes use of events, hand over event times here.

attr.name

character. The constraint value is additionally returned in an attributed with this name

forcings

TO BE FILLED BY DANIEL K

iiv

Example: c("ka", "ETA_EMAX").
Vector with names which are individualized per condition

conditional

Example: data.frame(parname = "GR", covname = "SEX", covvalue = "1", stringsAsFactors = FALSE).
* covname can relate to any parameter in the condition.grid of the data.
* covvalue is the value of this variable to use for individualization

fixed.grid

data.frame(parname, partask, ids...) Lookup table for fixed parameters

nauxtimes

additional simulation times

cores

to parallelize over conditions not over fits

Details

Objective functions can be combined by the "+" operator, see sumobjfn.

Value

Object of class obsfn, i.e. a function obj(..., fixed, deriv, conditions, env) that returns an objective list, objlist.

Examples

## Generate a prediction function

times <- 0:5
grid <- data.frame(name = "A", time = times, row.names = paste0("p", times))
x <- Xd(grid, condition = "C1")

pars <- structure(rep(0, nrow(grid)), names = row.names(grid))

## Simulate data
data.list <- lapply(1:3, function(i) {
  prediction <- x(times, pars + rnorm(length(pars), 0, 1))
  cbind(wide2long(prediction), sigma = 1)
})

data <- as.datalist(do.call(rbind, data.list))

## Generate objective function based on data and model
## Then fit the data and plot the result
obj <- normL2(data, x)
myfit <- trust(obj, pars, rinit = 1, rmax = 10)
plot(x(times, myfit$argument), data)

dkaschek/dMod documentation built on May 9, 2024, 2:07 a.m.