normL2: L2 norm between data and model prediction

Description Usage Arguments Details Value Examples

View source: R/objClass.R

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

1
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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## 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)

dMod documentation built on Jan. 27, 2021, 1:07 a.m.