Title: | Simulate and Visualize Kendall Random Walks and Related Distributions |
---|---|
Description: | Kendall random walks are a continuous-space Markov chains generated by the Kendall generalized convolution. This package provides tools for simulating these random walks and studying distributions related to them. For more information about Kendall random walks see Jasiulis-Gołdyn (2014) <arXiv:1412.0220>. |
Authors: | Mateusz Staniak [aut, cre] |
Maintainer: | Mateusz Staniak <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.4 |
Built: | 2024-12-21 06:48:58 UTC |
Source: | CRAN |
PDF of Kendall stable distribution
dkend(m_alpha)
dkend(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function that returns values of the PDF
dKend <- dkend(function(x) 1) # Step distribution: delta_{1} dKendall <- dKend(1:10, 0.5) # Values of PDF for arguments 1:10 and alpha = 0.5
dKend <- dkend(function(x) 1) # Step distribution: delta_{1} dKendall <- dKend(1:10, 0.5) # Values of PDF for arguments 1:10 and alpha = 0.5
Fit alpha parameter using MLE for distribution with one parameter
estimate_stable_alpha(data)
estimate_stable_alpha(data)
data |
Numeric vector |
list with optimal parameter and loglikelihood value
Fit stable Kendall distribution for given data and m_alpha function.
fit_kendall(data)
fit_kendall(data)
data |
Numeric vector of observation to which the distribution will be fitted. |
fitted quantiles
Function for fitting stable Kendall distribution separately to two parts of data
fit_separate(data, separation_point)
fit_separate(data, separation_point)
data |
Numeric vector. Observation to which the distribution will be fitted. |
separation_point |
Order above which data (quantiles) will be separated. |
List of class kendall_fit with estimated and theoretical quantiles and estimated parameters.
Fit stable Kendall distribution with one parameter (alpha)
fit_stable_alpha(data)
fit_stable_alpha(data)
data |
Numeric vector of data. |
list of type kendall_fit
Gradient of minus loglikelihood for stable Kendall distribution with 3 parameters.
full_loglik_gradient(data)
full_loglik_gradient(data)
data |
numeric vector of observation. |
Function of one argument of length 3 (alpha, location, scale).
Negative loglikelihood for stable Kendall distr. with 3 parameters.
full_minus_loglik(data)
full_minus_loglik(data)
data |
Dataset for which the loglikelihood will be calculated. |
numeric, value of loglikelihood
This function return only approximated values. To check their precisions use g_function_single function with an argument of length 1.
g_function(t, alpha, density)
g_function(t, alpha, density)
t |
Argument to the function. |
alpha |
Value of the alpha parameter. |
density |
Density function of the step distribution. |
Object of class "integrate"
g_function(1:5, 0.75, dnorm)
g_function(1:5, 0.75, dnorm)
This function return the whole "integrate" object, so precision of the approximation can be checked.
g_function_single(t, alpha, density)
g_function_single(t, alpha, density)
t |
Argument to the function. |
alpha |
Value of the alpha parameter. |
density |
Density function of the step distribution. |
Object of class "integrate"
g_function_single(5, 0.26, dnorm)
g_function_single(5, 0.26, dnorm)
Log-likelihood for stable kendall distribution with m_alpha = 1
kendall_loglik(alpha, x)
kendall_loglik(alpha, x)
alpha |
alpha parameter of the Kendall random walk |
x |
numeric vector of observations |
numeric
Kendall random walks are Markov processes generated by the Kendall convolution. This package helps simulate and visualize these random walks and associated distributions. It also provides function to fit these distributions to data.
simulate_kendall_rw
simulates Kendall random walks.
transform_kendall_rw
applies scaling and shift to simulated Kendall r.w-s.
ladder_moment
estimates the distribution of first ladder moment
by simulating Kendall random walks.
ladder_height
estimates the distribution of first ladder height
by simulating Kendall random walks.
ladder_moment_pmf
computes the PMF of the distribution of first
ladder moment.
g_function
Finds the value of G(t) numerically.
pkend
, dkend
, qkend
, rkend
give CDF, PDF, quantile function and random numbers from stable Kendall distribution.
NA is returned if the level wasn't crossed. Printing the resulting object will give summary of the estimated distribution and information whether level wasn't crossed in some simulations. This information can be used to pick the right trajectory length for the given level.
ladder_height(simulations, level)
ladder_height(simulations, level)
simulations |
kendall_simulation object |
level |
Positive numeric |
tibble
{ kendall_rw <- simulate_kendall_rw(100, 100, runif, 0.5) estim_ladder <- ladder_height(kendall_rw, 1000) estim_ladder }
{ kendall_rw <- simulate_kendall_rw(100, 100, runif, 0.5) estim_ladder <- ladder_height(kendall_rw, 1000) estim_ladder }
NA is returned if the level wasn't crossed. Printing the resulting object will give summary of the estimated distribution and information whether level wasn't crossed in some simulations. This information can be used to pick the right trajectory length for the given level.
ladder_moment(simulations, level)
ladder_moment(simulations, level)
simulations |
kendall_simulation object |
level |
Positive numeric |
tibble
{ kendall_rw <- simulate_kendall_rw(100, 100, runif, 0.5) estim_ladder <- ladder_moment(kendall_rw, 1000) estim_ladder }
{ kendall_rw <- simulate_kendall_rw(100, 100, runif, 0.5) estim_ladder <- ladder_moment(kendall_rw, 1000) estim_ladder }
Distribution of the first ladder moment.
ladder_moment_pmf(n, level, alpha, step_cdf, step_pdf)
ladder_moment_pmf(n, level, alpha, step_cdf, step_pdf)
n |
Argument to the PDF. |
level |
Level a to be crossed. |
alpha |
Alpha parameter of Kendall random walk. |
step_cdf |
CDF of the step distribution. |
step_pdf |
PDF of the step distribution. |
Value of PMF of the distribution of first ladder moment
prob <- ladder_moment_pmf(10, 1000, 0.5, pnorm, dnorm) prob
prob <- ladder_moment_pmf(10, 1000, 0.5, pnorm, dnorm) prob
Mutate each trajectory.
mutate_kendall_rw(simulations, mutate_function, df = T)
mutate_kendall_rw(simulations, mutate_function, df = T)
simulations |
Object of class kendall_simulation. |
mutate_function |
Function that will be applied to each trajectory. |
df |
If TRUE, a d.f will be returned, if FALSE, simulations in the kendall_simulation object passed in simulations argument will be replaced by the result of mutate_function. |
data frame or a list (of class kendall_simulation)
CDF of Kendall stable distribution
pkend(m_alpha)
pkend(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function function giving values of CDF of Kendall stable distribution
pKend <- pkend(function(x) 1) # Step distribution: delta_{1} pKendall <- pKend(1:10, 0.5) # Values of CDF for arguments 1:10 and alpha = 0.5
pKend <- pkend(function(x) 1) # Step distribution: delta_{1} pKendall <- pKend(1:10, 0.5) # Values of CDF for arguments 1:10 and alpha = 0.5
CDF of symmetrical Kendall stable distribution
pkendSym(m_alpha)
pkendSym(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function function giving values of CDF of Kendall stable distribution
pKend <- pkendSym(function(x) 1) # Step distribution: delta_{1} pKendall <- pKend(1:10, 0.5) # Values of CDF for arguments 1:10 and alpha = 0.5
pKend <- pkendSym(function(x) 1) # Step distribution: delta_{1} pKendall <- pKend(1:10, 0.5) # Values of CDF for arguments 1:10 and alpha = 0.5
Generic function for plotting results of ladder_moment function.
## S3 method for class 'kendall_barrier_crossing' plot(x, ...)
## S3 method for class 'kendall_barrier_crossing' plot(x, ...)
x |
kendall_barrier_crossing object |
... |
Additional arguments |
ggplot2
QQ-plot for the result of fitting stable Kendall distribtion.
## S3 method for class 'kendall_fit' plot(x, ...)
## S3 method for class 'kendall_fit' plot(x, ...)
x |
List returned by fit_separate or fit_kendall function. |
... |
Aditional arguments. |
ggplot2 object
Generic function that draws simulated trajectories of Kendall random walk
## S3 method for class 'kendall_simulation' plot(x, max_x = NULL, max_id = NULL, level = NULL, ...)
## S3 method for class 'kendall_simulation' plot(x, max_x = NULL, max_id = NULL, level = NULL, ...)
x |
object returned by normalising_sequences function. |
max_x |
maximum value on x axis. |
max_id |
Number of trajectories to plot. If NULL, all paths will be plotted. |
level |
Y-axis value which will be marked (level to be crossed). |
... |
Other arguments |
ggplot2 object
Plot summary of Kendall random walk simulations.
## S3 method for class 'kendall_summary' plot(x, ..., type = "density")
## S3 method for class 'kendall_summary' plot(x, ..., type = "density")
x |
Object of class kendall_summary |
... |
Optional arguments, currently ignored |
type |
Type of the plot: density, histogram or boxplot |
ggplot2 object
Generic function for printing result of ladder_moment function
## S3 method for class 'kendall_barrier_crossing' print(x, ...)
## S3 method for class 'kendall_barrier_crossing' print(x, ...)
x |
kendall_barrier_crossing object |
... |
Additional arguments |
invisible x
Generic function that prints information about simulated Kendall random walk
## S3 method for class 'kendall_simulation' print(x, ...)
## S3 method for class 'kendall_simulation' print(x, ...)
x |
Object returned by simulate_kendall_rw or transform_kendall_rw function. |
... |
Other arguments. |
Print summary of Kendall random walk simulations.
## S3 method for class 'kendall_summary' print(x, ...)
## S3 method for class 'kendall_summary' print(x, ...)
x |
Object of type kendall_summary |
... |
Optional parameters, currently ignored |
Quantiles of Kendall stable distribution
qkend(m_alpha)
qkend(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function function returning quantiles of given orders
qKend <- qkend(function(x) 1) # Step distribution: delta_{1} qKendall <- qKend(c(0.1, 0.9), 0.5) # Quantiles of order 0.1 and 0.9 for alpha = 0.5
qKend <- qkend(function(x) 1) # Step distribution: delta_{1} qKendall <- qKend(c(0.1, 0.9), 0.5) # Quantiles of order 0.1 and 0.9 for alpha = 0.5
Quantiles of symmetrical Kendall stable distribution
qkendSym(m_alpha)
qkendSym(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function function returning quantiles of given orders
qKend <- qkendSym(function(x) 1) # Step distribution: delta_{1} qKendall <- qKend(c(0.1, 0.9), 0.5) # Quantiles of order 0.1 and 0.9 for alpha = 0.5
qKend <- qkendSym(function(x) 1) # Step distribution: delta_{1} qKendall <- qKend(c(0.1, 0.9), 0.5) # Quantiles of order 0.1 and 0.9 for alpha = 0.5
Helper function
Qn(x, y, alpha)
Qn(x, y, alpha)
x |
numeric |
y |
numeric |
alpha |
numeric, parameter of Kendall random walk |
0 or 1 with probability depending on x, y, alpha
Pseudo-random number from Kendall stable distribution
rkend(m_alpha)
rkend(m_alpha)
m_alpha |
function giving moments of order alpha of step dist. |
function return n numbers genereted from Kendall stable dist.
rKend <- rkend(function(x) 1) # Step distribution: delta_{1} rKendall <- rKend(10, 0.5) # Ten random number from stable Kendall distribution with alpha = 0.5
rKend <- rkend(function(x) 1) # Step distribution: delta_{1} rKendall <- rKend(10, 0.5) # Ten random number from stable Kendall distribution with alpha = 0.5
Object returned by this has print and plot methods.
simulate_kendall_rw(number_of_simulations, trajectory_length, step_dist, alpha, symmetric = FALSE, ...)
simulate_kendall_rw(number_of_simulations, trajectory_length, step_dist, alpha, symmetric = FALSE, ...)
number_of_simulations |
number of trajectories to generate. |
trajectory_length |
length of trajectories. |
step_dist |
function returning random numbers from step dist. |
alpha |
alpha parameter. |
symmetric |
If TRUE, random walk on the whole real line will be simulated. |
... |
parameters for step distribution. |
Object of class kendall_simulation. It is a list that consists of
simulation |
Tibble with simulation id and simulated values, |
step_distribution |
Name of the step distribution, |
alpha |
Value of alpha parameter, |
is_symmetric |
Logical value indicating if this is a symmetric Kendall R.W. |
kendall_simulations <- simulate_kendall_rw(10, 1000, runif, 0.5) # Kendall R.W. on positive half-line with uniform step distribution - 10 trajectories. only_simulations <- kendall_simulations$simulation # tibble with simulated values kendall_simulations
kendall_simulations <- simulate_kendall_rw(10, 1000, runif, 0.5) # Kendall R.W. on positive half-line with uniform step distribution - 10 trajectories. only_simulations <- kendall_simulations$simulation # tibble with simulated values kendall_simulations
Simulate one trajectory ofa Kendall random walk
simulateOneTrajectory(trajectory_length, step_dist, alpha, symmetric = FALSE, ...)
simulateOneTrajectory(trajectory_length, step_dist, alpha, symmetric = FALSE, ...)
trajectory_length |
Number of samples to simulate. |
step_dist |
Function that returns random numbers from step distribution. |
alpha |
Alpha parameter of the random walk |
symmetric |
If TRUE, random walk on the whole real line will be simulated. |
... |
Additional parameters to step distribution. |
Generated path of the random walk.
Calculate some characteristic for every simulated instance.
summarise_kendall_rw(simulations, summary_function)
summarise_kendall_rw(simulations, summary_function)
simulations |
Object of class kendall_simulation. |
summary_function |
Function that will be applied to each trajectory. |
data frame of class "kendall_summary".
If one trajectory has length n, an_seq and bn_seq arguments should be sequnces of length n. Object returned by this function has plot and print methods.
transform_kendall_rw(simulations, an_seq = 1, bn_seq = 0)
transform_kendall_rw(simulations, an_seq = 1, bn_seq = 0)
simulations |
tibble returned by simulation function |
an_seq |
sequence that the trajectories will be multiplied by |
bn_seq |
sequence that will be substracted from scaled trajectory |
List like in simulate_kendall_rw function after transforming trajectories.
kendall_simulations <- simulate_kendall_rw(10, 1000, runif, 0.5) scaled_kendall <- transform_kendall_rw(kendall_simulations, (1:1000)^(-2)) scaled_kendall # kendall random walked scaled by the sequence n^(-1/alpha) scaled_data <- scaled_kendall$simulation # simulated values plot(scaled_kendall)
kendall_simulations <- simulate_kendall_rw(10, 1000, runif, 0.5) scaled_kendall <- transform_kendall_rw(kendall_simulations, (1:1000)^(-2)) scaled_kendall # kendall random walked scaled by the sequence n^(-1/alpha) scaled_data <- scaled_kendall$simulation # simulated values plot(scaled_kendall)
Helper function
U(x, y)
U(x, y)
x |
numeric |
y |
numeric |
sign of the argument whose abs. val. is bigger
Helper function: min/max
Z(x, y)
Z(x, y)
x |
numeric |
y |
numeric |
min of arguments divided by max of arguments