Transforming the time of predicted values by means of a monotonic mapping.
timeTransME(o, p,
o.t = seq(0, 1, length.out = length(o)),
p.t = seq(0, 1, length.out = length(p)),
ignore = "scaled",
geometry = "real",
measure = "mad",
type = c("dissimilarity", "normalized",
"similarity", "reference"),
interval = range(c(o.t, p.t)),
time = c("transformed", "fixed"),
trans = transBeta,
p0 = eval(formals(trans)$p0),
pmin = eval(formals(trans)$pmin, list(p = p0)),
pmax = eval(formals(trans)$pmax, list(p = p0)),
timeMEFactor = 0,
timeME = MAE,
timeMEtype = "normalized",
timeScale = 1,
ME = generalME(o, p, ignore, geometry, measure,
type = "function"),
MEtype = c("dissimilarity", "normalized"),
trials = 100,
debug = FALSE)
# S3 method for timeTransME
print(x, ..., digits = 3)
# S3 method for timeTransME
summary(object, ...)
# S3 method for timeTransME
plot(x, y = NULL, ..., col.obs = "black", col.pred = "green",
col.map = "red", sub = x$call, xlab = "t",
xlim = range(x$x), ylim = range(c(0, x$yo, x$yp)))
The result is an object of type timeTransME
with the following entries:
the requested measure with specified type,
the "dissimilarity" measure, which was calculated as a minimum of
ME(o(x), p(trans(x, timep)), MEtype) + timeMEFactor *
timeME(x * timeScale, trans(x, timep) * timeScale,
timeMEtype)
.
the reference value of this criterium achieved without time deformation and full dissimilarity.
the call used to generate this deviance.
the times at which the series were compared from the perspective of the observations.
the transformed times at which the series were compared from the perspective of the prediction.
the interpolated values of the observations at times x
.
the interpolated values of the time transformed predictions
at times x
.
the deviance of the time transformation:
timeME(x, trans(x, ME), timeMEtype))
.
the reference value of timeME
the factor to be used for timeME in the weighting
with respect to ME
.
the scaling to time to account for an other unit.
the parameter of trans minimizing the criterium.
the interval of time under consideration
the transformation function used for the time.
contains informations about the convergence of the optimization procedure and a list of secondary minima found. This additional list element occurs only if there is actually a minimisation performed.
a result from a call to timeTransME
a result from a call to timeTransME
vector of observed values
vector of predicted values
vector of observation times
vector of times for predicted values
one of "raw"
, "centered"
, "scaled"
or
"ordered"
as defined in generalME
to specify the aspects
of the data to be ignored.
one of "real", "logarithmic", "geometric", "ordinal"
as defined in generalME
to specify the geometry of
the observed data.
one of "mad", "sd", "var"
to specify the type of
error to be measured.
one of
"dissimilarity"
, "normalized"
, "similarity"
or
"reference"
as defined in generalME
to
specify the type of deviance measure to be used.
a vector with two entries giving start and end time of the experiment.
indicates wether the time should actually be transformed. LCS is currently not implemented. Use the LCS method directly.
the model function for the time transformation. See
transBezier
for possible alternatives.
the identity parameters for the time-transformation. A non
identity value can be given to force specific parameters for the
transformation with time = "fixed"
.
number or vector providing the minimal allowed values for the parameters of the transformation.
number or vector providing the minimal allowed values for the parameters of the transformation.
The timeTransME
minimizes a weighted sum of the
deformation of the time scale and of the data values
according to
totalME =
minimum of
ME(o(x), p(trans(x, timep)), MEtype) +
timeMEFactor * timeME(x * timeScale,
trans(x, timep) * timeScale, timeMEtype)
over p
for
x = c(ot, trans(pt, timep, inv = TRUE))
.
timeME
specifies the function to be used to quantify the temporal deformation.
the type of deviance measure (``dissimilarity'' or
``normalized'') to be used for timeME
.
a real value specifying the weighting of the time deformation against the value deformation. A value of 0 avoids penalty for time deformation.
a scaling applied to the time values before
timeME
is applied. This can be used to change the units of
measurement for the time.
the deviance function to be used for the data. See MSE
for alternatives.
the type of Mean Error to be used in the calculations. This is not the type of Measure to be reported.
The number of random starting values that should be used during the optimization of the time transformation. The optimization of the time transformation is a very critical task of this procedure and it had been shown by practical tests that a single local optimization typically fails to find the globally best fit. Depending on the number of parameters a value between 100 and 10000 seems reasonable for this parameter.
a logical. If true some diagnostic information for the optimization step is printed.
further parameters to be passed to
plot
color to plot the observations
color to plot the predictions
color to plot the mapped predictions
the sub-headline of the plot
the label of the x-axis of the plot
the size of the plot in x-direction
the size of the plot in y-direction
y unused
number of significant digits displayed
Common quantitative deviance measures underestimate the
similarity of patterns if there are shifts in time between measurement
and simulation. An alternative to measure model performance
independent of shifts in time is to transform the time of the
simulation, i.e. to run the time faster or slower, and to compare the
performance before and after the transformation. The applied
transformation function must be monotonic. timeTransME
minimizes the joint criterium
ME(o(x), p(trans(x, timep)), MEtype) +
timeMEFactor * timeME(x * timeScale, trans(x, timep) * timeScale, timeMEtype)
to find a best fitting time transformation.
print.timeTransME
prints only the requested value, without additional information.
summary.timeTransME
prints all the additional information.
plot.timeTransME
shows a picture visualising the fit of the transformed dataset. This can be used as a diagnostic.
transBeta
,
transBezier
set.seed(123)
## a constructed example
x <- seq(0, 2*pi, length=10)
o <- 5 + sin(x) + rnorm(x, sd=0.2) # observation with random error
p <- 5 + sin(x-1) # simulation with time shift
# timeTransME(o, p) # reasonably accurate but takes very long!
# timeTransME(o, p, trials=5, debug=TRUE)
ttbeta <- timeTransME(o, p, trials=5)
plot(ttbeta)
if (FALSE) {
ttsimplex <- timeTransME(o, p, trans = transSimplex, trials=5)
plot(ttsimplex)
ttbezier <- timeTransME(o, p, trans = transBezier, trials=5)
plot(ttbezier)
}
## observed and measured data with non-matching time intervals
data(phyto)
bbobs <- dpill(obs$t, obs$y)
n <- diff(range(obs$t)) + 1
obss <- ksmooth(obs$t, obs$y, kernel = "normal", bandwidth = bbobs,
n.points = n)
names(obss) <- c("t", "y")
obss <- as.data.frame(obss)[match(sim$t, obss$t), ]
tt <- timeTransME(obss$y, sim$y, obss$t, sim$t, ME = SMSE,
timeMEFactor = 0, time = "transform", type = "n", trials = 5)
round(tt$totalME, digits = 3)
basedate <- as.Date("1960/1/1")
plot(basedate + sim$t, sim$y, type="l", ylim = c(min(obs$y, sim$y),
max(obs$y, sim$y)), xlab = "time", ylab = "Phytoplankton (mg/L)",
col = 2, font = 2, lwd = 2, cex.lab = 1.2, las = 1)
lines(basedate + obss$t, obss$y, lwd = 2)
points(basedate + obs$t, obs$y, lwd = 2)
lines(basedate + tt$x, tt$yp, lwd = 2, col = 2, lty = 2)
legend(basedate + 12600, 50, c("measurement", "smoothed measurement",
"simulation", "transformed simulation"), lty = c(0, 1, 1, 2),
pch = c(1, NA, NA, NA), lwd = 2, col = c(1, 1, 2, 2))
tt1 <- timeTransME(obs$y, sim$y, obs$t, sim$t, ME = SMSLE, type = "n",
time = "fixed")
tt1
plot(tt1)
summary(tt1)
if (FALSE) {
tt2 <- timeTransME(obss$y, sim$y, obss$t, sim$t, ME = SMSLE, type = "n",
time = "trans", debug = TRUE)
tt2
plot(tt2) # logarithm (SMSLE) is not appropriate for the example
summary(tt2)
tt3 <- timeTransME(obss$y, sim$y, obss$t, sim$t, ME = SMSE, type = "n",
time = "trans", trans = transBezier, debug = TRUE)
tt3
plot(tt3)
summary(tt3)
tt4 <- timeTransME(obss$y, sim$y, obss$t, sim$t, ME = MSOE, type = "n",
time = "trans", trans = transBezier, debug = TRUE)
tt4
plot(tt4)
summary(tt4)
}
Run the code above in your browser using DataLab