| truncatedNormalMoment | R Documentation |
This function recursively calculates k-th order moment of truncated normal distribution.
truncatedNormalMoment(
k = 1L,
x_lower = numeric(0),
x_upper = numeric(0),
mean = 0,
sd = 1,
pdf_lower = numeric(0),
cdf_lower = numeric(0),
pdf_upper = numeric(0),
cdf_upper = numeric(0),
cdf_difference = numeric(0),
return_all_moments = FALSE,
is_validation = TRUE,
is_parallel = FALSE,
diff_type = "NO"
)
k |
non-negative integer moment order. |
x_lower |
numeric vector of lower truncation points. |
x_upper |
numeric vector of upper truncation points. |
mean |
numeric expected value. |
sd |
positive numeric standard deviation. |
pdf_lower |
non-negative numeric matrix of precalculated normal
density functions with mean |
cdf_lower |
non-negative numeric matrix of
precalculated normal cumulative distribution functions
with mean |
pdf_upper |
non-negative numeric matrix of precalculated normal
density functions with mean |
cdf_upper |
non-negative numeric matrix of
precalculated normal cumulative distribution functions
with mean |
cdf_difference |
non-negative numeric matrix of
precalculated |
return_all_moments |
logical; if |
is_validation |
logical value indicating whether function input
arguments should be validated. Set it to |
is_parallel |
if |
diff_type |
string value indicating the type of the argument
the moment should be differentiated respect to.
Default value is |
This function estimates k-th order moment of
normal distribution which mean equals to mean and standard deviation
equals to sd truncated at points given by x_lower and
x_upper. Note that the function is vectorized so you can provide
x_lower and x_upper as vectors of equal size. If vectors values
for x_lower and x_upper are not provided then their default
values will be set to -(.Machine$double.xmin * 0.99) and
(.Machine$double.xmax * 0.99) correspondingly.
Note that parameter k value automatically converts
to integer. So passing non-integer k value will not cause
any errors but the calculations will be performed for rounded
k value only.
If there is precalculated density or cumulative distribution
functions at standardized truncation points (subtract mean
and then divide by sd) then it is possible to provide
them through pdf_lower, pdf_upper,
cdf_lower and cdf_upper arguments in
order to decrease number of calculations.
This function returns vector of k-th order moments for normally
distributed random variable with mean = mean and standard
deviation = sd under x_lower and x_upper truncation
points x_lower and x_upper correspondingly.
If return_all_moments is TRUE then see this argument
description above for output details.
## Calculate 5-th order moment of three truncated normal random
## variables (x1, x2, x3) which mean is 5 and standard deviation is 3.
## These random variables truncation points are given
## as follows:-1<x1<1, 0<x2<2, 1<x3<3.
k <- 3
x_lower <- c(-1, 0, 1, -Inf, -Inf)
x_upper <- c(1, 2 , 3, 2, Inf)
mean <- 3
sd <- 5
# get the moments
truncatedNormalMoment(k, x_lower, x_upper, mean, sd)
# get matrix of (0-5)-th moments (columns) for each variable (rows)
truncatedNormalMoment(k, x_lower, x_upper,
mean, sd,
return_all_moments = TRUE)
# get the moments derivatives respect to mean
truncatedNormalMoment(k, x_lower, x_upper,
mean, sd,
diff_type = "mean")
# get the moments derivatives respect to standard deviation
truncatedNormalMoment(k, x_lower, x_upper,
mean, sd,
diff_type = "sd")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.