Plot an array of model predictions for a list of parameters

Share:

Description

Plot an array of model predictions for a list of parameters

Usage

1
2
plotArray(parframe, x, times, data = NULL, ..., fixed = NULL,
  deriv = FALSE, scales = "free", facet = "wrap")

Arguments

parframe

Object of class parframe, e.g. returned by mstrust or profile

x

The model prediction function x(times, pars, fixed, ...)

times

Numeric vector of time points for the model prediction

data

Named list of data.frames as being used in res, i.e. with columns name, time, value and sigma.

...

Further arguments going to subset.

fixed

Named numeric vector with fixed parameters

deriv

Logical. If x supports the argument deriv, it is used.

scales

The scales argument of facet_wrap or facet_grid, i.e. "free", "fixed", "free_x" or "free_y"

facet

Either "wrap" or "grid"

Details

The data.frame being plotted has columns time, value, sigma, name and condition.

Value

A plot object of class ggplot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## Generate a prediction function
regfn <- c(y = "sin(a*time)")

g <- Y(regfn, parameters = "a")
x <- Xt(condition = "C1")

## Generate data
data <- datalist(
  C1 = data.frame(
    name = "y",
    time = 1:5,
    value = sin(1:5) + rnorm(5, 0, .1),
    sigma = .1
  )
)

## Initialize parameters and time 
pars <- c(a = 1)
times <- seq(0, 5, .1)

plot((g*x)(times, pars), data)

## Do many fits from random positions and store them into parlist
out <- as.parlist(lapply(1:50, function(i) {
  trust(normL2(data, g*x), pars + rnorm(length(pars), 0, 1), rinit = 1, rmax = 10)
}))

summary(out)

## Reduce parlist to parframe
parframe <- as.parframe(out)
plotValues(parframe)

## Reduce parframe to best fit
bestfit <- as.parvec(parframe)
plot((g*x)(times, bestfit), data)

## Plot array with all solutions
plotArray(parframe, g*x, times, data)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.