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"
)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.
non-negative integer moment order.
numeric vector of lower truncation points.
numeric vector of upper truncation points.
numeric expected value.
positive numeric standard deviation.
non-negative numeric matrix of precalculated normal
density functions with mean mean and standard deviation sd at
points given by x_lower.
non-negative numeric matrix of
precalculated normal cumulative distribution functions
with mean mean and standard deviation
sd at points given by x_lower.
non-negative numeric matrix of precalculated normal
density functions with mean mean and standard deviation sd at
points given by x_upper.
non-negative numeric matrix of
precalculated normal cumulative distribution functions
with mean mean and standard deviation
sd at points given by x_upper.
non-negative numeric matrix of
precalculated cdf_upper-cdf_lower values.
logical; if TRUE, function returns the
matrix of moments of normally distributed random variable with
mean = mean and standard deviation = sd under lower and upper
truncation points x_lower and x_upper correspondingly.
Note that element in i-th row and j-th column of this matrix corresponds to
the i-th observation (j-1)-th order moment.
logical value indicating whether function input
arguments should be validated. Set it to FALSE for slight
performance boost (default value is TRUE).
if TRUE then multiple cores will be
used for some calculations. It usually provides speed advantage for
large enough samples (about more than 1000 observations).
string value indicating the type of the argument
the moment should be differentiated respect to.
Default value is "NO" so the moments itself will be returned.
Alternative values are "mean" and "sd". Also
"x_lower" and "x_upper" values are available for
truncatedNormalMoment.
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.
## 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:-1Run the code above in your browser using DataLab