| Title: | Stochastic Bridges for Levy Degradation Processes |
|---|---|
| Description: | Exact simulation of the bridges of Levy degradation processes (gamma, Wiener, inverse Gaussian, variance-gamma and Meixner processes) and resampling of trajectories observed at regular or irregular inspection times onto a regular time grid, following the interpolation algorithm of Grall-Maes (2012) <doi:10.1177/1748006X12462522>. |
| Authors: | Amedée Rytrace Tito [aut, cre], Christian Paroissin [aut] |
| Maintainer: | Amedée Rytrace Tito <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-11-29 04:53:01 UTC |
| Source: | https://github.com/rytracetito/levy_packages |
levyBridge simulates exactly the bridges of Levy degradation processes,
and uses them to resample degradation trajectories, observed at regular or
irregular inspection times, onto a regular time grid.
The package has two kinds of functions, for each process:
the bridge functions gamma_bridge(), wiener_bridge(),
ig_bridge(), vg_bridge() and meixner_bridge() draw the value
of the process at one time , given its levels at two
times ;
the resampling functions gamma_resampling(), wiener_resampling(),
ig_resampling(), vg_resampling() and meixner_resampling() resample
whole trajectories onto a regular grid, by calling the bridge function at
each grid point.
All these functions take the vector of all the parameters of
the process, as a named vector theta, for instance c(a = 2, b = 3) for
the gamma process.
Let be a Levy process such that has the density
, and let . Given and
, the value has the density
(Hoyle, Hughston and Macrina, 2011). The bridge functions draw exactly from this distribution. The functions of each process are:
| Process | Bridge | Resampling |
| gamma | gamma_bridge() |
gamma_resampling() |
| Wiener | wiener_bridge() |
wiener_resampling() |
| inverse Gaussian | ig_bridge() |
ig_resampling() |
| variance-gamma | vg_bridge() |
vg_resampling() |
| Meixner | meixner_bridge() |
meixner_resampling()
|
and the parameters in (argument theta) are:
| Process | theta |
Used by the bridge |
| gamma | a, b |
a |
| Wiener | mu, sigma |
sigma |
| inverse Gaussian | mu, eta |
eta |
| variance-gamma | theta, sigma, nu |
all |
| Meixner | a, b, d, m |
a, d, m
|
The distribution of the bridge does not always depend on all the
parameters: the parameters that it does not use are ignored by the bridge
functions, and used by the resampling functions only to extend the
trajectories (option 2 of the method "MultiBridge"). The help page of
each bridge function gives the distribution of its bridge and the way it
is drawn.
The argument x of the resampling functions accepts three formats:
one trajectory: a data frame whose first column contains the inspection times and second column the degradation levels;
several trajectories, each with its own inspection times: a list of
such data frames, one per trajectory, for instance the result of a
simulation function of DegradSim when the trajectories have different
inspection times;
several trajectories with the same inspection times: a matrix whose
first column contains the times and the other columns the levels, one
column per trajectory, for instance the result of a simulation function
of DegradSim when all the trajectories have the same inspection times.
The columns are read by position, not by name. The inspection times of a trajectory start at 0 and are strictly increasing.
Exact increments. The observed increment between two inspections is
the difference of the two levels. A level only keeps about 16 significant
digits, so that an increment very small compared with the level (for
instance a gamma increment over a short time step) can be found equal
to 0. The simulation functions of DegradSim keep the increments exactly
as drawn, in attr(x, "dx"): when x has this attribute, a list with one
vector of increments per trajectory whose cumulated sums give the levels,
these increments are used instead of the differences of the levels. The
resampling is otherwise the same.
Let be the inspection times of a
trajectory and its observed levels. The method
(section Resampling methods) gives a regular grid
, and the resampled levels are
computed in increasing order of :
if is an inspection time, is the observed level;
otherwise, is drawn by the bridge function between the last
known point on the left (the inspection time or the grid point
, whichever is closer to ) and the next
inspection time on the right.
This is the interpolation algorithm of Grall-Maës (2012), proposed for the gamma process and used here for all the processes.
A grid point that differs from an inspection time only by a rounding
error of the computer (relative difference below ) is set to
that inspection time.
Every resampling function has an argument method, which chooses the grid.
"Bridge" (default). The grid of Grall-Maës (2012):
with as many points as observations and the same end points. Each
trajectory has its own grid, of step .
"ExtBridge". A grid that contains all the inspection times. The
times are taken with decimal places (argument digits) and
where is the largest integer not greater than
. The step is the largest one such that every inspection
time, truncated to decimal places, is a grid point: all the observations are kept. The grid
has steps, with equality if and only if the
inspection times are regular; the grid is then the inspection times and
the data are returned unchanged.
With digits = NULL (default), is the number of decimal places
of the inspection times, that is the smallest integer such that
all the times are multiples of , up to rounding errors of the
computer. This package looks for between 0 and 6, a limit chosen to
avoid very fine grids; if the times have more decimal places, an error
asks for digits. When digits is given and some times have more decimal
places, they are truncated to digits decimal places, with a warning;
two times equal after truncation give an error. A warning is also given when the
grid has more than steps, since the resampling then takes time.
Each trajectory has its own step . With common_step = TRUE,
and are computed from the inspection times of all the
trajectories, which then have the same step.
"MultiBridge". One step common to all the trajectories: the
trajectory , observed on with
increments, is resampled on with
the total observed duration divided by the total number of increments.
Grall-Maës (2012, eq. (7)) proposes this step for two trajectories. The
number of reconstructed increments is then about the number of observed
ones; for one trajectory, and the method is "Bridge".
The grid does not necessarily contain the inspection times.
option = 1 (default): the trajectory is resampled on the grid
points , that is up to its own last inspection.
The end of the trajectory, between its last grid point and
, is not used. A trajectory shorter than gives
no increment, with a warning.
option = 2: all the trajectories are resampled up to the last
inspection time over all of them, . The grid
ends exactly at : the number of steps is rounded to
the nearest integer , and the step becomes ,
close to ; the grid is
, , the same for all the
trajectories, and attr(res, "teq") gives . Beyond its
last inspection, a trajectory is extended by increments of the process
drawn with the given parameters, starting from its last observed level.
This needs all the parameters of the process (for instance the rate b
of the gamma process), and the extended values do not come from the
data.
Choice of the method.
"Bridge": one grid per trajectory, with as many points as
observations; the steps of two trajectories are different in general.
"ExtBridge": all the observations are kept on the grid, which can have
many more points than observations.
"MultiBridge", or "ExtBridge" with common_step = TRUE: the same
step for all the trajectories.
A resampling function returns an object of class "levybridge", a list
with one data frame per trajectory:
res[[k]] is the -th trajectory on its regular grid, with the
columns t (grid) and X (resampled levels);
attr(res, "teq") gives the step of the grid of each trajectory;
attr(res, "dx") gives, for each trajectory, the increments between
consecutive grid points. They are computed directly by the bridges, not
as differences of the resampled levels: a very small increment keeps its
significant digits instead of being rounded to 0;
attr(res, "observed") gives the observed data, one data frame per
trajectory (with the method "ExtBridge", the truncated times when a
truncation was needed);
attr(res, "model"), attr(res, "parameters") and
attr(res, "method") recall the call.
Printing res shows the model, the parameters, the steps and the first
resampled levels. The function plot_bridge() compares the observed and
resampled levels. The bridge values are random: use set.seed() before a
resampling to make it reproducible.
Maintainer: Amedée Rytrace Tito [email protected]
Authors:
Christian Paroissin [email protected]
Grall-Maës, E. (2012). Use of the Kolmogorov-Smirnov test for gamma process. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 226(6), 624-634. doi:10.1177/1748006X12462522
Hoyle, E., Hughston, L. P. and Macrina, A. (2011). Lévy random bridges and the modelling of financial information. Stochastic Processes and their Applications, 121(4), 856-884.
Useful links:
https://github.com/rytracetito/levy_packages/tree/main/levyBridge
Report bugs at https://github.com/rytracetito/levy_packages/issues
# 1. The bridge: draws of X_2 given X_1 = 3 and X_4 = 6 (gamma, a = 2, b = 3) set.seed(1) gamma_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 2, b = 3), n = 5) # 2. Resampling of one gamma trajectory observed at 11 irregular times t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_gamma(t, a = 2, b = 3) # on the regular grid 0, 2.25, 4.5, ..., 22.5 r <- gamma_resampling(x, theta = c(a = 2, b = 3)) r r[[1]] attr(r, "teq") attr(r, "dx") plot_bridge(r) # 3. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_gamma(t, a = 2, b = 3, n_traj = 5) head(xm) plot_bridge(gamma_resampling(xm, theta = c(a = 2, b = 3)), trajectory = 1:5) # 4. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) # One grid per trajectory, then the two methods with a common step theta <- c(a = 2, b = 3) attr(gamma_resampling(xs, theta), "teq") attr(gamma_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") attr(gamma_resampling(xs, theta, method = "MultiBridge"), "teq") plot_bridge(gamma_resampling(xs, theta, method = "MultiBridge"), trajectory = 1:3) # "MultiBridge", option 2: the grid ends exactly at the last inspection # time (40), and the shorter trajectories are extended up to it r2 <- gamma_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r2, function(d) max(d$t)) plot_bridge(r2, trajectory = 1:3)# 1. The bridge: draws of X_2 given X_1 = 3 and X_4 = 6 (gamma, a = 2, b = 3) set.seed(1) gamma_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 2, b = 3), n = 5) # 2. Resampling of one gamma trajectory observed at 11 irregular times t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_gamma(t, a = 2, b = 3) # on the regular grid 0, 2.25, 4.5, ..., 22.5 r <- gamma_resampling(x, theta = c(a = 2, b = 3)) r r[[1]] attr(r, "teq") attr(r, "dx") plot_bridge(r) # 3. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_gamma(t, a = 2, b = 3, n_traj = 5) head(xm) plot_bridge(gamma_resampling(xm, theta = c(a = 2, b = 3)), trajectory = 1:5) # 4. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) # One grid per trajectory, then the two methods with a common step theta <- c(a = 2, b = 3) attr(gamma_resampling(xs, theta), "teq") attr(gamma_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") attr(gamma_resampling(xs, theta, method = "MultiBridge"), "teq") plot_bridge(gamma_resampling(xs, theta, method = "MultiBridge"), trajectory = 1:3) # "MultiBridge", option 2: the grid ends exactly at the last inspection # time (40), and the shorter trajectories are extended up to it r2 <- gamma_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r2, function(d) max(d$t)) plot_bridge(r2, trajectory = 1:3)
Draws the value at time of a gamma process known at two times
, from the distribution of the gamma bridge. This
function is used by gamma_resampling() at each point of the grid.
gamma_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)gamma_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)
t_A, x_A
|
Time and level of the known point on the left. |
t_B, x_B
|
Time and level of the known point on the right,
|
t |
Time of the draw, |
theta |
Vector |
n |
Number of independent draws, a positive integer (default 1). |
A numeric vector of n independent draws of given
and .
The gamma process with shape and rate has
, independent increments and
for (shape
, rate ). Its trajectories are increasing. The
vector of its parameters is .
Given and ,
(Grall-Maës, 2012, eq. (3)). This distribution does not depend on the rate
. When (two equal levels, which can happen after
rounding), the bridge is constant.
Grall-Maës, E. (2012). Use of the Kolmogorov-Smirnov test for gamma process. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 226(6), 624-634. doi:10.1177/1748006X12462522
gamma_resampling(): resampling of trajectories on a regular grid;
wiener_bridge(), ig_bridge(), vg_bridge(), meixner_bridge(): the bridges of the other processes.
# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (a = 2, b = 3) set.seed(1) gamma_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 2, b = 3)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s f <- function(x, s) dgamma(x, shape = 2 * s, rate = 3) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 3), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # The rate b does not change the bridge set.seed(2); y1 <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 3), n = 5) set.seed(2); y2 <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 100), n = 5) identical(y1, y2) # 3. Equal levels give a constant bridge; a decrease is impossible gamma_bridge(0, 1, 2, 1, 0.5, theta = c(a = 2, b = 3)) try(gamma_bridge(0, 2, 2, 1, 0.5, theta = c(a = 2, b = 3))) # Errors: t outside (t_A, t_B), theta without all the parameters try(gamma_bridge(1, 3, 4, 6, 5, theta = c(a = 2, b = 3))) try(gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2))) # 4. Parameters estimated with levyfit on a simulated trajectory t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_gamma(t, a = 2, b = 3) est <- levyfit::gamma_mle(x) est # Three draws at t = 1.5, between the inspections 1.2 and 2 gamma_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = est, n = 3)# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (a = 2, b = 3) set.seed(1) gamma_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 2, b = 3)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s f <- function(x, s) dgamma(x, shape = 2 * s, rate = 3) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 3), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # The rate b does not change the bridge set.seed(2); y1 <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 3), n = 5) set.seed(2); y2 <- gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2, b = 100), n = 5) identical(y1, y2) # 3. Equal levels give a constant bridge; a decrease is impossible gamma_bridge(0, 1, 2, 1, 0.5, theta = c(a = 2, b = 3)) try(gamma_bridge(0, 2, 2, 1, 0.5, theta = c(a = 2, b = 3))) # Errors: t outside (t_A, t_B), theta without all the parameters try(gamma_bridge(1, 3, 4, 6, 5, theta = c(a = 2, b = 3))) try(gamma_bridge(1, 3, 4, 6, 2, theta = c(a = 2))) # 4. Parameters estimated with levyfit on a simulated trajectory t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_gamma(t, a = 2, b = 3) est <- levyfit::gamma_mle(x) est # Three draws at t = 1.5, between the inspections 1.2 and 2 gamma_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = est, n = 3)
Resamples one or several trajectories of a gamma process onto a regular
time grid: each grid point that is not an inspection time is drawn with
gamma_bridge() between the known levels around it. The grids and the
resampling algorithm are described in levyBridge-package.
gamma_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )gamma_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )
x |
The observed trajectories: a data frame whose first column
contains the inspection times (starting at 0, strictly increasing) and
second column the degradation levels; a list of such data frames, one
per trajectory; or a matrix whose first column contains the times and
the other columns the levels, one column per trajectory. The results of
the simulation functions of |
theta |
Vector |
method |
Grid of the resampling: |
digits |
Used only with |
common_step |
Used only with |
option |
Used only with |
An object of class "levybridge": a list with one data frame per
trajectory, with the columns t (regular grid) and X (resampled
levels), and the attributes teq (step of each grid), dx (increments
between consecutive grid points), observed, model, parameters and
method. See the section Results of levyBridge-package.
Grall-Maës, E. (2012). Use of the Kolmogorov-Smirnov test for gamma process. Proceedings of the Institution of Mechanical Engineers, Part O: Journal of Risk and Reliability, 226(6), 624-634. doi:10.1177/1748006X12462522
gamma_bridge() for the distribution of the bridge,
levyBridge-package for the grids and the algorithm, plot_bridge().
# 1. One trajectory observed at 11 irregular times (a = 2, b = 3) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_gamma(t, a = 2, b = 3) theta <- c(a = 2, b = 3) r <- gamma_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 2.0, 4.1, 4.6, 6.8)) gamma_resampling(x2, theta)[[1]] # Equal observed levels give a constant bridge; a decrease is impossible gamma_resampling(data.frame(t = c(0, 1, 2.5, 3), X = c(0, 1, 1, 2)), theta)[[1]] try(gamma_resampling(data.frame(t = c(0, 1, 2, 3), X = c(0, 2, 1.5, 3)), theta)) # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- gamma_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(gamma_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_gamma(t, a = 2, b = 3, n_traj = 5) head(xm) r4 <- gamma_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) # One grid and one step per trajectory attr(gamma_resampling(xs, theta), "teq") attr(gamma_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(gamma_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- gamma_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses b) r6 <- gamma_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- gamma_resampling(x, theta)[[1]]$X set.seed(2); y2 <- gamma_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit theta_hat <- levyfit::gamma_mle(xs) theta_hat r7 <- gamma_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Gamma process (a = 5, b = 1/3), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_gamma(liste_t, a = 5, b = 1/3) theta8 <- levyfit::gamma_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- gamma_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- gamma_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)# 1. One trajectory observed at 11 irregular times (a = 2, b = 3) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_gamma(t, a = 2, b = 3) theta <- c(a = 2, b = 3) r <- gamma_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 2.0, 4.1, 4.6, 6.8)) gamma_resampling(x2, theta)[[1]] # Equal observed levels give a constant bridge; a decrease is impossible gamma_resampling(data.frame(t = c(0, 1, 2.5, 3), X = c(0, 1, 1, 2)), theta)[[1]] try(gamma_resampling(data.frame(t = c(0, 1, 2, 3), X = c(0, 2, 1.5, 3)), theta)) # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- gamma_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(gamma_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_gamma(t, a = 2, b = 3, n_traj = 5) head(xm) r4 <- gamma_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) # One grid and one step per trajectory attr(gamma_resampling(xs, theta), "teq") attr(gamma_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(gamma_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- gamma_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses b) r6 <- gamma_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- gamma_resampling(x, theta)[[1]]$X set.seed(2); y2 <- gamma_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit theta_hat <- levyfit::gamma_mle(xs) theta_hat r7 <- gamma_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Gamma process (a = 5, b = 1/3), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_gamma(liste_t, a = 5, b = 1/3) theta8 <- levyfit::gamma_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- gamma_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- gamma_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)
Draws the value at time of an inverse Gaussian process known at two
times , from the distribution of the inverse Gaussian
bridge. This function is used by ig_resampling() at each point of the
grid.
ig_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)ig_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)
t_A, x_A
|
Time and level of the known point on the left. |
t_B, x_B
|
Time and level of the known point on the right,
|
t |
Time of the draw, |
theta |
Vector |
n |
Number of independent draws, a positive integer (default 1). |
A numeric vector of n independent draws of given
and .
The inverse Gaussian process with parameters and
has , independent increments and
(mean
, shape ). Its trajectories are
increasing. The vector of its parameters is .
Let . Given and ,
the ratio has the density
where and
. Ribeiro and Webber (2003,
section 3.3, eq. (27)) give this density for the inverse ratio
. Splitting the factor , it is the mixture
then . This distribution does not
depend on . When (two equal levels, which can
happen after rounding), the bridge is constant.
The variable is drawn from one Gaussian and one uniform variable,
by the method of Michael, Schucany and Haas (1976) as adapted by Ribeiro
and Webber (2003, sections 3.3 and 3.4).
Michael, J. R., Schucany, W. R. and Haas, R. W. (1976). Generating random
variates using transformations with multiple roots. The American
Statistician, 30(2), 88-90.
doi:10.1080/00031305.1976.10479147
Ribeiro, C. and Webber, N. (2003). A Monte Carlo method for the normal inverse Gaussian option valuation model using an inverse Gaussian bridge. Computing in Economics and Finance 2003, 5.
ig_resampling(): resampling of trajectories on a regular grid;
gamma_bridge(), wiener_bridge(), vg_bridge(), meixner_bridge(): the bridges of the other processes.
# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (mu = 1, eta = 3) set.seed(1) ig_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(mu = 1, eta = 3)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (inverse Gaussian with mean mu s = s and shape eta s^2 = 3 s^2) f <- function(x, s) sqrt(3 * s^2 / (2 * pi * x^3)) * exp(-3 * (x - s)^2 / (2 * x)) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- ig_bridge(1, 3, 4, 6, 2, theta = c(mu = 1, eta = 3), n = 10000) range(y) hist(y, breaks = 50, freq = FALSE) curve(dens, from = 3.001, to = 5.999, add = TRUE, col = "red") # 3. Equal levels give a constant bridge; a decrease is impossible ig_bridge(0, 1, 2, 1, 0.5, theta = c(mu = 1, eta = 3)) try(ig_bridge(0, 2, 2, 1, 0.5, theta = c(mu = 1, eta = 3))) # Errors: t outside (t_A, t_B), theta without all the parameters try(ig_bridge(1, 3, 4, 6, 5, theta = c(mu = 1, eta = 3))) try(ig_bridge(1, 3, 4, 6, 2, theta = c(eta = 3))) # 4. Parameters estimated with levyfit on a simulated trajectory t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_ig(t, mu = 1, eta = 3) est <- levyfit::ig_mle(x) ig_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = est, n = 3)# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (mu = 1, eta = 3) set.seed(1) ig_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(mu = 1, eta = 3)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (inverse Gaussian with mean mu s = s and shape eta s^2 = 3 s^2) f <- function(x, s) sqrt(3 * s^2 / (2 * pi * x^3)) * exp(-3 * (x - s)^2 / (2 * x)) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- ig_bridge(1, 3, 4, 6, 2, theta = c(mu = 1, eta = 3), n = 10000) range(y) hist(y, breaks = 50, freq = FALSE) curve(dens, from = 3.001, to = 5.999, add = TRUE, col = "red") # 3. Equal levels give a constant bridge; a decrease is impossible ig_bridge(0, 1, 2, 1, 0.5, theta = c(mu = 1, eta = 3)) try(ig_bridge(0, 2, 2, 1, 0.5, theta = c(mu = 1, eta = 3))) # Errors: t outside (t_A, t_B), theta without all the parameters try(ig_bridge(1, 3, 4, 6, 5, theta = c(mu = 1, eta = 3))) try(ig_bridge(1, 3, 4, 6, 2, theta = c(eta = 3))) # 4. Parameters estimated with levyfit on a simulated trajectory t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_ig(t, mu = 1, eta = 3) est <- levyfit::ig_mle(x) ig_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = est, n = 3)
Resamples one or several trajectories of an inverse Gaussian process onto
a regular time grid: each grid point that is not an inspection time is
drawn with ig_bridge() between the known levels around it. The grids and
the resampling algorithm are described in levyBridge-package.
ig_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )ig_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )
x |
The observed trajectories: a data frame whose first column
contains the inspection times (starting at 0, strictly increasing) and
second column the degradation levels; a list of such data frames, one
per trajectory; or a matrix whose first column contains the times and
the other columns the levels, one column per trajectory. The results of
the simulation functions of |
theta |
Vector |
method |
Grid of the resampling: |
digits |
Used only with |
common_step |
Used only with |
option |
Used only with |
An object of class "levybridge": a list with one data frame per
trajectory, with the columns t (regular grid) and X (resampled
levels), and the attributes teq (step of each grid), dx (increments
between consecutive grid points), observed, model, parameters and
method. See the section Results of levyBridge-package.
ig_bridge() for the distribution of the bridge,
levyBridge-package for the grids and the algorithm, plot_bridge().
# 1. One trajectory observed at 11 irregular times (mu = 1, eta = 3) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_ig(t, mu = 1, eta = 3) theta <- c(mu = 1, eta = 3) r <- ig_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 2.0, 4.1, 4.6, 6.8)) ig_resampling(x2, theta)[[1]] # Equal observed levels give a constant bridge; a decrease is impossible ig_resampling(data.frame(t = c(0, 1, 2.5, 3), X = c(0, 1, 1, 2)), theta)[[1]] try(ig_resampling(data.frame(t = c(0, 1, 2, 3), X = c(0, 2, 1.5, 3)), theta)) # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- ig_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(ig_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_ig(t, mu = 1, eta = 3, n_traj = 5) head(xm) r4 <- ig_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_ig(plan, mu = 1, eta = 3) # One grid and one step per trajectory attr(ig_resampling(xs, theta), "teq") attr(ig_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(ig_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- ig_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses mu) r6 <- ig_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- ig_resampling(x, theta)[[1]]$X set.seed(2); y2 <- ig_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit theta_hat <- levyfit::ig_mle(xs) theta_hat r7 <- ig_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Inverse Gaussian process (mu = 1, eta = 3), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_ig(liste_t, mu = 1, eta = 3) theta8 <- levyfit::ig_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- ig_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- ig_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)# 1. One trajectory observed at 11 irregular times (mu = 1, eta = 3) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_ig(t, mu = 1, eta = 3) theta <- c(mu = 1, eta = 3) r <- ig_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 2.0, 4.1, 4.6, 6.8)) ig_resampling(x2, theta)[[1]] # Equal observed levels give a constant bridge; a decrease is impossible ig_resampling(data.frame(t = c(0, 1, 2.5, 3), X = c(0, 1, 1, 2)), theta)[[1]] try(ig_resampling(data.frame(t = c(0, 1, 2, 3), X = c(0, 2, 1.5, 3)), theta)) # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- ig_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(ig_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_ig(t, mu = 1, eta = 3, n_traj = 5) head(xm) r4 <- ig_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_ig(plan, mu = 1, eta = 3) # One grid and one step per trajectory attr(ig_resampling(xs, theta), "teq") attr(ig_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(ig_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- ig_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses mu) r6 <- ig_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- ig_resampling(x, theta)[[1]]$X set.seed(2); y2 <- ig_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit theta_hat <- levyfit::ig_mle(xs) theta_hat r7 <- ig_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Inverse Gaussian process (mu = 1, eta = 3), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_ig(liste_t, mu = 1, eta = 3) theta8 <- levyfit::ig_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- ig_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- ig_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)
Draws the value at time of a Meixner process known at two times
, from the distribution of the Meixner bridge. This
function is used by meixner_resampling() at each point of the grid.
meixner_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)meixner_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)
t_A, x_A
|
Time and level of the known point on the left. |
t_B, x_B
|
Time and level of the known point on the right,
|
t |
Time of the draw, |
theta |
Vector |
n |
Number of independent draws, a positive integer (default 1). |
A numeric vector of n independent draws of given
and .
The distribution, ,
, , real, has density
(Schoutens and Teugels, 1998). The Meixner process has ,
independent increments and
. Its
trajectories are not monotone. The vector of its parameters is
.
Write and
Given and ,
, where the random variable has
the density
which is the formula of the section Bridge of a Levy process of
levyBridge-package with Meixner densities. This distribution does not
depend on .
The random variable is drawn exactly by acceptance-rejection
(Devroye, 1986, section II.3): a value is proposed from a simpler density,
the envelope, and accepted or rejected so that the accepted values follow
exactly the distribution of . The envelope is built in three steps.
A bound of the gamma function. For ,
a bound close to for all , which
uses only elementary functions.
A piecewise exponential envelope. The product of the bounds for
and is bounded above by an
exponential function on each of a set of intervals, which are halved
until this exponential function is close to the product. Beyond these
intervals, the two tails are bounded by exponential functions.
Acceptance-rejection. A piece of the envelope is chosen with a
probability proportional to its area, a value is drawn from it by
inversion of its distribution function, and this value is accepted with
the probability given by the ratio of the density of to the
envelope.
Guarantee. For all the parameters, a proposed value is accepted with
probability at least 0.57, so that at most 1.75 values are proposed on
average for each draw. The cost of the envelope changes little with
, and for draws with the same endpoints it is built only
once.
Details. The bound of step 1 follows from the product formula of the
gamma function (DLMF, equation 5.8.3) and the partial fraction expansion of
(DLMF, equation 4.36.3). The function
is computed with
gsl::lngamma_complex(), and only when the bound of step 1 and a similar
lower bound cannot decide the acceptance alone. When and
are both smaller than about , the two peaks
of the density cannot be resolved with floating point numbers: the draws
stay exact, but the probability of acceptance can be lower.
Devroye, L. (1986). Non-Uniform Random Variate Generation. Springer.
NIST Digital Library of Mathematical Functions (DLMF), release 1.2.8,
2026-09-15, https://dlmf.nist.gov/: equation 5.8.3 (product formula
of the gamma function) and equation 4.36.3 (partial fraction expansion of
).
Schoutens, W. and Teugels, J. L. (1998). Lévy processes, polynomials and martingales. Communications in Statistics. Stochastic Models, 14(1-2), 335-349.
meixner_resampling(): resampling of trajectories on a regular grid;
gamma_bridge(), wiener_bridge(), ig_bridge(), vg_bridge(): the bridges of the other processes.
# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (a = 1, b = 0.3, d = 1.5, m = 0.2) set.seed(1) meixner_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (see the section Model, computed on the log scale) f <- function(x, s, a = 1, b = 0.3, d = 1.5, m = 0.2) { exp(2 * d * s * log(2 * cos(b / 2)) - log(2 * a * pi) - lgamma(2 * d * s) + b * (x - m * s) / a + 2 * Re(gsl::lngamma_complex(rep(d * s, length(x)), (x - m * s) / a))) } dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 50000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # The skewness b does not change the bridge set.seed(2) y1 <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 5) set.seed(2) y2 <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = -2, d = 1.5, m = 0.2), n = 5) identical(y1, y2) # A bridge far from its typical value: x_B - x_A is more than 1000 times its # standard deviation, and the draws stay fast and exact system.time(y <- meixner_bridge(0, 0, 1, 2000, 0.5, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 1000)) summary(y) # Errors: t outside (t_A, t_B), theta without all the parameters try(meixner_bridge(1, 3, 4, 6, 5, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2))) try(meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, d = 1.5, m = 0.2))) try(meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 4, d = 1.5, m = 0.2))) # 3. Parameters estimated with levyfit on simulated trajectories set.seed(1) plan <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) x <- DegradSim::sim_meixner(plan, a = 1, b = 0.3, d = 1.5, m = 0.2) est <- levyfit::meixner_mle(x) est meixner_bridge(0, 0, 2, 1, 1, theta = est, n = 3)# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (a = 1, b = 0.3, d = 1.5, m = 0.2) set.seed(1) meixner_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (see the section Model, computed on the log scale) f <- function(x, s, a = 1, b = 0.3, d = 1.5, m = 0.2) { exp(2 * d * s * log(2 * cos(b / 2)) - log(2 * a * pi) - lgamma(2 * d * s) + b * (x - m * s) / a + 2 * Re(gsl::lngamma_complex(rep(d * s, length(x)), (x - m * s) / a))) } dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 50000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # The skewness b does not change the bridge set.seed(2) y1 <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 5) set.seed(2) y2 <- meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = -2, d = 1.5, m = 0.2), n = 5) identical(y1, y2) # A bridge far from its typical value: x_B - x_A is more than 1000 times its # standard deviation, and the draws stay fast and exact system.time(y <- meixner_bridge(0, 0, 1, 2000, 0.5, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2), n = 1000)) summary(y) # Errors: t outside (t_A, t_B), theta without all the parameters try(meixner_bridge(1, 3, 4, 6, 5, theta = c(a = 1, b = 0.3, d = 1.5, m = 0.2))) try(meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, d = 1.5, m = 0.2))) try(meixner_bridge(1, 3, 4, 6, 2, theta = c(a = 1, b = 4, d = 1.5, m = 0.2))) # 3. Parameters estimated with levyfit on simulated trajectories set.seed(1) plan <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) x <- DegradSim::sim_meixner(plan, a = 1, b = 0.3, d = 1.5, m = 0.2) est <- levyfit::meixner_mle(x) est meixner_bridge(0, 0, 2, 1, 1, theta = est, n = 3)
Resamples one or several trajectories of a Meixner process onto a regular
time grid: each grid point that is not an inspection time is drawn with
meixner_bridge() between the known levels around it. The grids and the
resampling algorithm are described in levyBridge-package.
meixner_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )meixner_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )
x |
The observed trajectories: a data frame whose first column
contains the inspection times (starting at 0, strictly increasing) and
second column the degradation levels; a list of such data frames, one
per trajectory; or a matrix whose first column contains the times and
the other columns the levels, one column per trajectory. The results of
the simulation functions of |
theta |
Vector |
method |
Grid of the resampling: |
digits |
Used only with |
common_step |
Used only with |
option |
Used only with |
An object of class "levybridge": a list with one data frame per
trajectory, with the columns t (regular grid) and X (resampled
levels), and the attributes teq (step of each grid), dx (increments
between consecutive grid points), observed, model, parameters and
method. See the section Results of levyBridge-package.
meixner_bridge() for the distribution of the bridge,
levyBridge-package for the grids and the algorithm, plot_bridge().
# 1. One trajectory observed at 11 irregular times (a = 1, b = 0.3, d = 1.5, m = 0.2) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_meixner(t, a = 1, b = 0.3, d = 1.5, m = 0.2) theta <- c(a = 1, b = 0.3, d = 1.5, m = 0.2) r <- meixner_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) meixner_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- meixner_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(meixner_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_meixner(t, a = 1, b = 0.3, d = 1.5, m = 0.2, n_traj = 5) head(xm) r4 <- meixner_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_meixner(plan, a = 1, b = 0.3, d = 1.5, m = 0.2) # One grid and one step per trajectory attr(meixner_resampling(xs, theta), "teq") attr(meixner_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(meixner_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- meixner_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses b) r6 <- meixner_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- meixner_resampling(x, theta)[[1]]$X set.seed(2); y2 <- meixner_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit set.seed(1) plan_e <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) xe <- DegradSim::sim_meixner(plan_e, a = 1, b = 0.3, d = 1.5, m = 0.2) theta_hat <- levyfit::meixner_mle(xe) theta_hat r7 <- meixner_resampling(xe, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Meixner process (a = 1, b = 0.3, d = 1.5, m = 0.2). With these 32 # increments, levyfit::meixner_mle() often finds no maximum inside the # parameter space: the true parameters are used set.seed(46) x8 <- DegradSim::sim_meixner(liste_t, a = 1, b = 0.3, d = 1.5, m = 0.2) theta8 <- c(a = 1, b = 0.3, d = 1.5, m = 0.2) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- meixner_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- meixner_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)# 1. One trajectory observed at 11 irregular times (a = 1, b = 0.3, d = 1.5, m = 0.2) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_meixner(t, a = 1, b = 0.3, d = 1.5, m = 0.2) theta <- c(a = 1, b = 0.3, d = 1.5, m = 0.2) r <- meixner_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) meixner_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- meixner_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(meixner_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_meixner(t, a = 1, b = 0.3, d = 1.5, m = 0.2, n_traj = 5) head(xm) r4 <- meixner_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_meixner(plan, a = 1, b = 0.3, d = 1.5, m = 0.2) # One grid and one step per trajectory attr(meixner_resampling(xs, theta), "teq") attr(meixner_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(meixner_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- meixner_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses b) r6 <- meixner_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- meixner_resampling(x, theta)[[1]]$X set.seed(2); y2 <- meixner_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit set.seed(1) plan_e <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) xe <- DegradSim::sim_meixner(plan_e, a = 1, b = 0.3, d = 1.5, m = 0.2) theta_hat <- levyfit::meixner_mle(xe) theta_hat r7 <- meixner_resampling(xe, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Meixner process (a = 1, b = 0.3, d = 1.5, m = 0.2). With these 32 # increments, levyfit::meixner_mle() often finds no maximum inside the # parameter space: the true parameters are used set.seed(46) x8 <- DegradSim::sim_meixner(liste_t, a = 1, b = 0.3, d = 1.5, m = 0.2) theta8 <- c(a = 1, b = 0.3, d = 1.5, m = 0.2) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- meixner_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- meixner_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)
Draws, for one or several trajectories, the observed values at the
inspection times and the values resampled on the regular grid by a
resampling function, with ggplot2.
plot_bridge(x, trajectory = 1, title = NULL, same_scale = TRUE)plot_bridge(x, trajectory = 1, title = NULL, same_scale = TRUE)
x |
An object of class |
trajectory |
Indices of the trajectories to plot in |
title |
Title of the plot, a character string; by default the name of
the bridge, for instance |
same_scale |
Used with several trajectories: |
A ggplot object. It is displayed when printed, and it can be
modified with the usual ggplot2 functions, added with +: for instance
+ ggplot2::labs(x = "Time (hours)").
t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_gamma(t, a = 2, b = 3) r <- gamma_resampling(x, theta = c(a = 2, b = 3)) # Observed levels (red) and resampled levels on the regular grid (blue) plot_bridge(r) # Custom title and axis labels plot_bridge(r, title = "Gamma bridge, a = 2") + ggplot2::labs(x = "Time (hours)", y = "Degradation (%)") # Several trajectories: one panel per trajectory plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) plot_bridge(gamma_resampling(xs, theta = c(a = 2, b = 3)), trajectory = 1:3) # Each panel with its own axes plot_bridge(gamma_resampling(xs, theta = c(a = 2, b = 3)), trajectory = 1:3, same_scale = FALSE)t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_gamma(t, a = 2, b = 3) r <- gamma_resampling(x, theta = c(a = 2, b = 3)) # Observed levels (red) and resampled levels on the regular grid (blue) plot_bridge(r) # Custom title and axis labels plot_bridge(r, title = "Gamma bridge, a = 2") + ggplot2::labs(x = "Time (hours)", y = "Degradation (%)") # Several trajectories: one panel per trajectory plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_gamma(plan, a = 2, b = 3) plot_bridge(gamma_resampling(xs, theta = c(a = 2, b = 3)), trajectory = 1:3) # Each panel with its own axes plot_bridge(gamma_resampling(xs, theta = c(a = 2, b = 3)), trajectory = 1:3, same_scale = FALSE)
Draws the value at time of a variance-gamma process known at two
times , from the distribution of the variance-gamma
bridge. This function is used by vg_resampling() at each point of the
grid.
vg_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)vg_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)
t_A, x_A
|
Time and level of the known point on the left. |
t_B, x_B
|
Time and level of the known point on the right,
|
t |
Time of the draw, |
theta |
Vector |
n |
Number of independent draws, a positive integer (default 1). |
A numeric vector of n independent draws of given
and .
The variance-gamma process with parameters ,
and is
(Madan, Carr and Chang, 1998), where is a gamma process with
with scale (mean ,
variance ) and an independent standard Brownian
motion. Its trajectories are not monotone. The vector of its parameters is
: the drift is one of the
parameters, not the whole vector .
Given and ,
where the random variables , and are independent:
the variable follows the distribution
in the notation of Peña and
Jauch (2025), with density proportional to
where and
;
;
.
This representation is given by Hoyle (2010, section 2.7.2): equations
(2.83) to (2.87) for the standard variance-gamma process, whose parameter
is here, and equation (2.77), which writes the bridge
of any variance-gamma process as a scaled bridge of the standard one.
When , the last parameter of the GIG distribution is 0: the
variable then has the gamma distribution with shape and
rate if ; if , this case has
probability zero and the package takes .
The variable is the increment
of the gamma process given the
observations, and is the fraction of this increment reached at
time , as in the gamma bridge; given , the Brownian
motion gives the Gaussian term. The bridge uses the three
parameters. The GIG variable is drawn with GIGrvg::rgig() (Hörmann and
Leydold, 2014).
Hörmann, W. and Leydold, J. (2014). Generating generalized inverse Gaussian random variates. Statistics and Computing, 24, 547-557. doi:10.1007/s11222-013-9387-3
Hoyle, A. E. V. (2010). Information-Based Models for Finance and Insurance. PhD thesis, Imperial College London. arXiv:1010.0829.
Peña, V. and Jauch, M. (2025). Properties of the generalized inverse Gaussian with applications to Monte Carlo simulation and distribution function evaluation. arXiv:2401.00749.
Madan, D. B., Carr, P. P. and Chang, E. C. (1998). The variance gamma process and option pricing. European Finance Review, 2(1), 79-105. doi:10.1023/A:1009703431535
vg_resampling(): resampling of trajectories on a regular grid;
gamma_bridge(), wiener_bridge(), ig_bridge(), meixner_bridge(): the bridges of the other processes.
# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (theta = 0.5, sigma = 1.5, nu = 2) set.seed(1) vg_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(theta = 0.5, sigma = 1.5, nu = 2)) # 2. Many draws of X_3 given X_1 = 3 and X_6 = 6: the histogram of the # draws and, in red, the density of the bridge, # f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (Madan, Carr and Chang, 1998, computed on the log scale). With nu = 2, # the times are such that t - t_A > nu / 2 and t_B - t > nu / 2: otherwise # the density of the bridge is infinite at x_A or x_B f <- function(x, s, th = 0.5, sg = 1.5, nu = 2) { k <- sqrt(th^2 + 2 * sg^2 / nu) z <- k * abs(x) / sg^2 exp(log(2) + th * x / sg^2 - (s / nu) * log(nu) - log(sqrt(2 * pi) * sg) - lgamma(s / nu) + (s / nu - 0.5) * log(abs(x) / k) + log(besselK(z, s / nu - 0.5, expon.scaled = TRUE)) - z) } dens <- function(x) f(x - 3, 2) * f(6 - x, 3) / f(3, 5) y <- vg_bridge(1, 3, 6, 6, 3, theta = c(theta = 0.5, sigma = 1.5, nu = 2), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red", n = 500) # Errors: t outside (t_A, t_B), theta without all the parameters try(vg_bridge(1, 3, 4, 6, 5, theta = c(theta = 0.5, sigma = 1.5, nu = 2))) try(vg_bridge(1, 3, 4, 6, 2, theta = c(sigma = 1.5, nu = 2))) # 3. Parameters estimated with levyfit on simulated trajectories set.seed(1) plan <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) x <- DegradSim::sim_vg(plan, theta = 0.5, sigma = 1.5, nu = 2) est <- levyfit::vg_mle(x) est vg_bridge(0, 0, 2, 1, 1, theta = est, n = 3)# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (theta = 0.5, sigma = 1.5, nu = 2) set.seed(1) vg_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(theta = 0.5, sigma = 1.5, nu = 2)) # 2. Many draws of X_3 given X_1 = 3 and X_6 = 6: the histogram of the # draws and, in red, the density of the bridge, # f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s # (Madan, Carr and Chang, 1998, computed on the log scale). With nu = 2, # the times are such that t - t_A > nu / 2 and t_B - t > nu / 2: otherwise # the density of the bridge is infinite at x_A or x_B f <- function(x, s, th = 0.5, sg = 1.5, nu = 2) { k <- sqrt(th^2 + 2 * sg^2 / nu) z <- k * abs(x) / sg^2 exp(log(2) + th * x / sg^2 - (s / nu) * log(nu) - log(sqrt(2 * pi) * sg) - lgamma(s / nu) + (s / nu - 0.5) * log(abs(x) / k) + log(besselK(z, s / nu - 0.5, expon.scaled = TRUE)) - z) } dens <- function(x) f(x - 3, 2) * f(6 - x, 3) / f(3, 5) y <- vg_bridge(1, 3, 6, 6, 3, theta = c(theta = 0.5, sigma = 1.5, nu = 2), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red", n = 500) # Errors: t outside (t_A, t_B), theta without all the parameters try(vg_bridge(1, 3, 4, 6, 5, theta = c(theta = 0.5, sigma = 1.5, nu = 2))) try(vg_bridge(1, 3, 4, 6, 2, theta = c(sigma = 1.5, nu = 2))) # 3. Parameters estimated with levyfit on simulated trajectories set.seed(1) plan <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) x <- DegradSim::sim_vg(plan, theta = 0.5, sigma = 1.5, nu = 2) est <- levyfit::vg_mle(x) est vg_bridge(0, 0, 2, 1, 1, theta = est, n = 3)
Resamples one or several trajectories of a variance-gamma process onto a
regular time grid: each grid point that is not an inspection time is drawn
with vg_bridge() between the known levels around it. The grids and the
resampling algorithm are described in levyBridge-package.
vg_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )vg_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )
x |
The observed trajectories: a data frame whose first column
contains the inspection times (starting at 0, strictly increasing) and
second column the degradation levels; a list of such data frames, one
per trajectory; or a matrix whose first column contains the times and
the other columns the levels, one column per trajectory. The results of
the simulation functions of |
theta |
Vector |
method |
Grid of the resampling: |
digits |
Used only with |
common_step |
Used only with |
option |
Used only with |
An object of class "levybridge": a list with one data frame per
trajectory, with the columns t (regular grid) and X (resampled
levels), and the attributes teq (step of each grid), dx (increments
between consecutive grid points), observed, model, parameters and
method. See the section Results of levyBridge-package.
vg_bridge() for the distribution of the bridge,
levyBridge-package for the grids and the algorithm, plot_bridge().
# 1. One trajectory observed at 11 irregular times (theta = 0.5, sigma = 1.5, nu = 2) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_vg(t, theta = 0.5, sigma = 1.5, nu = 2) theta <- c(theta = 0.5, sigma = 1.5, nu = 2) r <- vg_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) vg_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- vg_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(vg_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_vg(t, theta = 0.5, sigma = 1.5, nu = 2, n_traj = 5) head(xm) r4 <- vg_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_vg(plan, theta = 0.5, sigma = 1.5, nu = 2) # One grid and one step per trajectory attr(vg_resampling(xs, theta), "teq") attr(vg_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(vg_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- vg_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process r6 <- vg_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- vg_resampling(x, theta)[[1]]$X set.seed(2); y2 <- vg_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit set.seed(1) plan_e <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) xe <- DegradSim::sim_vg(plan_e, theta = 0.5, sigma = 1.5, nu = 2) theta_hat <- levyfit::vg_mle(xe) theta_hat r7 <- vg_resampling(xe, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Variance-gamma process (theta = 0.5, sigma = 1.5, nu = 2), parameters # estimated by levyfit set.seed(46) x8 <- DegradSim::sim_vg(liste_t, theta = 0.5, sigma = 1.5, nu = 2) theta8 <- levyfit::vg_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- vg_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- vg_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)# 1. One trajectory observed at 11 irregular times (theta = 0.5, sigma = 1.5, nu = 2) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_vg(t, theta = 0.5, sigma = 1.5, nu = 2) theta <- c(theta = 0.5, sigma = 1.5, nu = 2) r <- vg_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) vg_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- vg_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(vg_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_vg(t, theta = 0.5, sigma = 1.5, nu = 2, n_traj = 5) head(xm) r4 <- vg_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_vg(plan, theta = 0.5, sigma = 1.5, nu = 2) # One grid and one step per trajectory attr(vg_resampling(xs, theta), "teq") attr(vg_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(vg_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- vg_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process r6 <- vg_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- vg_resampling(x, theta)[[1]]$X set.seed(2); y2 <- vg_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit set.seed(1) plan_e <- DegradSim::inspection_times("decreasing", n = 20, n_traj = 10, tmax = 40) xe <- DegradSim::sim_vg(plan_e, theta = 0.5, sigma = 1.5, nu = 2) theta_hat <- levyfit::vg_mle(xe) theta_hat r7 <- vg_resampling(xe, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Variance-gamma process (theta = 0.5, sigma = 1.5, nu = 2), parameters # estimated by levyfit set.seed(46) x8 <- DegradSim::sim_vg(liste_t, theta = 0.5, sigma = 1.5, nu = 2) theta8 <- levyfit::vg_mle(x8) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- vg_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- vg_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)
Draws the value at time of a Wiener process with drift known at two
times , from the distribution of the Brownian bridge.
This function is used by wiener_resampling() at each point of the grid.
wiener_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)wiener_bridge(t_A, x_A, t_B, x_B, t, theta, n = 1)
t_A, x_A
|
Time and level of the known point on the left. |
t_B, x_B
|
Time and level of the known point on the right,
|
t |
Time of the draw, |
theta |
Vector |
n |
Number of independent draws, a positive integer (default 1). |
A numeric vector of n independent draws of given
and .
The Wiener process with drift and volatility is
, with a standard Brownian motion:
, independent increments and
. Its
trajectories are not monotone. The vector of its parameters is
.
Given and ,
which is the formula of the section Bridge of a Levy process of
levyBridge-package with Gaussian densities. This distribution does not
depend on the drift .
wiener_resampling(): resampling of trajectories on a regular grid;
gamma_bridge(), ig_bridge(), vg_bridge(), meixner_bridge(): the bridges of the other processes.
# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (mu = 0.5, sigma = 1.5) set.seed(1) wiener_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(mu = 0.5, sigma = 1.5)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s f <- function(x, s) dnorm(x, mean = 0.5 * s, sd = 1.5 * sqrt(s)) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- wiener_bridge(1, 3, 4, 6, 2, theta = c(mu = 0.5, sigma = 1.5), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # 3. A decrease is possible: the process is not monotone wiener_bridge(0, 2, 2, 1, 0.5, theta = c(mu = 0.5, sigma = 1.5), n = 3) # Errors: t outside (t_A, t_B), theta without all the parameters try(wiener_bridge(1, 3, 4, 6, 5, theta = c(mu = 0.5, sigma = 1.5))) try(wiener_bridge(1, 3, 4, 6, 2, theta = c(sigma = 1.5))) # 4. Parameters estimated with levyfit (variance sigma2 turned into sigma) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5) est <- levyfit::wiener_mle(x) theta <- c(mu = est[["mu"]], sigma = sqrt(est[["sigma2"]])) wiener_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = theta, n = 3)# 1. One draw of X_2, given X_1 = 3 and X_4 = 6 (mu = 0.5, sigma = 1.5) set.seed(1) wiener_bridge(t_A = 1, x_A = 3, t_B = 4, x_B = 6, t = 2, theta = c(mu = 0.5, sigma = 1.5)) # 2. Many draws: the histogram of the draws and, in red, the density of # the bridge, f_{t - t_A}(x - x_A) f_{t_B - t}(x_B - x) / f_{t_B - t_A}(x_B - x_A) # (see ?levyBridge), where f_s is the density of X_s f <- function(x, s) dnorm(x, mean = 0.5 * s, sd = 1.5 * sqrt(s)) dens <- function(x) f(x - 3, 1) * f(6 - x, 2) / f(3, 3) y <- wiener_bridge(1, 3, 4, 6, 2, theta = c(mu = 0.5, sigma = 1.5), n = 10000) hist(y, breaks = 50, freq = FALSE) curve(dens, add = TRUE, col = "red") # 3. A decrease is possible: the process is not monotone wiener_bridge(0, 2, 2, 1, 0.5, theta = c(mu = 0.5, sigma = 1.5), n = 3) # Errors: t outside (t_A, t_B), theta without all the parameters try(wiener_bridge(1, 3, 4, 6, 5, theta = c(mu = 0.5, sigma = 1.5))) try(wiener_bridge(1, 3, 4, 6, 2, theta = c(sigma = 1.5))) # 4. Parameters estimated with levyfit (variance sigma2 turned into sigma) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) x <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5) est <- levyfit::wiener_mle(x) theta <- c(mu = est[["mu"]], sigma = sqrt(est[["sigma2"]])) wiener_bridge(1.2, x[2, 2], 2, x[3, 2], 1.5, theta = theta, n = 3)
Resamples one or several trajectories of a Wiener process with drift onto
a regular time grid: each grid point that is not an inspection time is
drawn with wiener_bridge() between the known levels around it. The grids
and the resampling algorithm are described in levyBridge-package.
wiener_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )wiener_resampling( x, theta, method = "Bridge", digits = NULL, common_step = FALSE, option = 1 )
x |
The observed trajectories: a data frame whose first column
contains the inspection times (starting at 0, strictly increasing) and
second column the degradation levels; a list of such data frames, one
per trajectory; or a matrix whose first column contains the times and
the other columns the levels, one column per trajectory. The results of
the simulation functions of |
theta |
Vector |
method |
Grid of the resampling: |
digits |
Used only with |
common_step |
Used only with |
option |
Used only with |
An object of class "levybridge": a list with one data frame per
trajectory, with the columns t (regular grid) and X (resampled
levels), and the attributes teq (step of each grid), dx (increments
between consecutive grid points), observed, model, parameters and
method. See the section Results of levyBridge-package.
wiener_bridge() for the distribution of the bridge,
levyBridge-package for the grids and the algorithm, plot_bridge().
# 1. One trajectory observed at 11 irregular times (mu = 0.5, sigma = 1.5) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5) theta <- c(mu = 0.5, sigma = 1.5) r <- wiener_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) wiener_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- wiener_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(wiener_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5, n_traj = 5) head(xm) r4 <- wiener_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_wiener(plan, mu = 0.5, sigma = 1.5) # One grid and one step per trajectory attr(wiener_resampling(xs, theta), "teq") attr(wiener_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(wiener_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- wiener_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses mu) r6 <- wiener_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- wiener_resampling(x, theta)[[1]]$X set.seed(2); y2 <- wiener_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit est <- levyfit::wiener_mle(xs) theta_hat <- c(mu = est[["mu"]], sigma = sqrt(est[["sigma2"]])) theta_hat r7 <- wiener_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Wiener process (mu = 0.5, sigma = 1.5), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_wiener(liste_t, mu = 0.5, sigma = 1.5) est8 <- levyfit::wiener_mle(x8) theta8 <- c(mu = est8[["mu"]], sigma = sqrt(est8[["sigma2"]])) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- wiener_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- wiener_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)# 1. One trajectory observed at 11 irregular times (mu = 0.5, sigma = 1.5) t <- c(0, 1.2, 2, 3.8, 5.5, 7.1, 10.4, 12.9, 15.3, 18.7, 22.5) set.seed(1) x <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5) theta <- c(mu = 0.5, sigma = 1.5) r <- wiener_resampling(x, theta) r # The resampled trajectory, on the regular grid 0, 2.25, 4.5, ..., 22.5 r[[1]] attr(r, "teq") plot_bridge(r) # 2. One trajectory given as a data frame (times, then levels): the grid is # 0, 2, 4, 6, 8, 10, and the inspection times 2 and 6 keep their levels x2 <- data.frame(t = c(0, 2, 3, 6, 7, 10), X = c(0, 1.4, 0.9, 3.1, 2.6, 4.8)) wiener_resampling(x2, theta)[[1]] # 3. Method "ExtBridge": the times have 1 decimal place, so the grid # 0, 0.1, ..., 22.5 contains all of them r3 <- wiener_resampling(x, theta, method = "ExtBridge") attr(r3, "teq") all(t %in% r3[[1]]$t) plot_bridge(r3) # digits = 0 truncates the times to integers, with a warning attr(wiener_resampling(x, theta, method = "ExtBridge", digits = 0), "teq") # 4. Five trajectories with the same inspection times (a matrix) xm <- DegradSim::sim_wiener(t, mu = 0.5, sigma = 1.5, n_traj = 5) head(xm) r4 <- wiener_resampling(xm, theta) attr(r4, "teq") plot_bridge(r4, trajectory = 1:5) # 5. Three trajectories, each with its own inspection times (a list) plan <- DegradSim::inspection_times("decreasing", n = 10, n_traj = 3, tmax = c(20, 30, 40), digits = 1) xs <- DegradSim::sim_wiener(plan, mu = 0.5, sigma = 1.5) # One grid and one step per trajectory attr(wiener_resampling(xs, theta), "teq") attr(wiener_resampling(xs, theta, method = "ExtBridge"), "teq") # The same step for all the trajectories attr(wiener_resampling(xs, theta, method = "ExtBridge", common_step = TRUE), "teq") r5 <- wiener_resampling(xs, theta, method = "MultiBridge") attr(r5, "teq") sapply(r5, nrow) plot_bridge(r5, trajectory = 1:3) # Option 2: all the trajectories up to 40; beyond its last inspection, each # one is extended by increments of the process (this uses mu) r6 <- wiener_resampling(xs, theta, method = "MultiBridge", option = 2) sapply(r6, nrow) plot_bridge(r6, trajectory = 1:3) # 6. The bridge values are random: set.seed() makes them reproducible set.seed(2); y1 <- wiener_resampling(x, theta)[[1]]$X set.seed(2); y2 <- wiener_resampling(x, theta)[[1]]$X identical(y1, y2) # 7. With the parameters estimated by levyfit est <- levyfit::wiener_mle(xs) theta_hat <- c(mu = est[["mu"]], sigma = sqrt(est[["sigma2"]])) theta_hat r7 <- wiener_resampling(xs, theta_hat) attr(r7, "parameters") # 8. Four trajectories observed up to 8, 12, 45 and 58, each with its own # inspection times, resampled with "MultiBridge" liste_t <- list(c(0, 3, 8), c(0, 2, 5, 9, 12), c(0, 4, 7, 11, 15, 18, 22, 27, 33, 39, 45), c(0, 2, 3, 5, 8, 9, 14, 15, 17, 20, 22, 25, 27, 30, 33, 46, 58)) # Wiener process (mu = 0.5, sigma = 1.5), parameters estimated by levyfit set.seed(46) x8 <- DegradSim::sim_wiener(liste_t, mu = 0.5, sigma = 1.5) est8 <- levyfit::wiener_mle(x8) theta8 <- c(mu = est8[["mu"]], sigma = sqrt(est8[["sigma2"]])) # Option 1: one grid for all the trajectories; each one stops at the last # grid point before its last inspection r8 <- wiener_resampling(x8, theta8, method = "MultiBridge") attr(r8, "teq") sapply(r8, function(d) max(d$t)) plot_bridge(r8, trajectory = 1:4) # Option 2: the grid ends exactly at 58; beyond its last inspection, each # shorter trajectory is extended by increments of the process r8b <- wiener_resampling(x8, theta8, method = "MultiBridge", option = 2) attr(r8b, "teq") sapply(r8b, function(d) max(d$t)) plot_bridge(r8b, trajectory = 1:4)