characRV | R Documentation |
This function computes the main characteristics of a random variable (expectation, median, standard deviation, ...)
characRV(D, charact = c("expectation", "median", "sd", "IQR", "skewness", "kurtosis",
"moment", "cmoment"), moment = 1, cmoment = 2)
D |
An object of the class |
charact |
any of " |
moment |
an integer indicating the moment with respect to the origin to be calculated. |
cmoment |
an integer indicating the moment with respect to the expectation to be calculated. |
'characRV' returns a table containing the selected characteristics.
E
, median
, sd
, IQR
,
skewness
, kurtosis
##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (D, charact = c("expectation", "median", "sd", "IQR",
"skewness", "kurtosis", "moment", "cmoment"), moment = 1,
cmoment = 2)
{
if (missing(charact))
charact <- c("expectation", "sd")
charact <- match.arg(charact, c("expectation", "median",
"sd", "IQR", "skewness", "kurtosis", "moment", "cmoment"),
several.ok = TRUE)
moment <- if ("moment" %in% charact)
moment
else NULL
cmoment <- if ("cmoment" %in% charact)
cmoment
else NULL
mom <- if (!is.null(moment))
paste("alpha_", moment, sep = "")
else NULL
cmom <- if (!is.null(cmoment))
paste("mu_", cmoment, sep = "")
else NULL
chars <- c(c("expectation", "median", "sd", "IQR", "skewness",
"kurtosis")[c("expectation", "median", "sd", "IQR", "skewness",
"kurtosis") %in% charact], mom, cmom)
nchars <- length(chars)
table <- matrix(0, 1, nchars)
rownames(table) <- gsub("[[:space:]]", "", deparse(substitute(D)))
colnames(table) <- chars
if ("expectation" %in% chars)
table[, "expectation"] <- distrEx::E(D)
if ("median" %in% chars)
table[, "median"] <- distrEx::median(D)
if ("sd" %in% chars)
table[, "sd"] <- distrEx::sd(D)
if ("IQR" %in% chars)
table[, "IQR"] <- distrEx::IQR(D)
if ("skewness" %in% chars)
table[, "skewness"] <- distrEx::skewness(D)
if ("kurtosis" %in% chars)
table[, "kurtosis"] <- distrEx::kurtosis(D)
if ("moment" %in% charact)
table[, mom] <- distrEx::E(D, fun = function(x) {
x^moment
})
if ("cmoment" %in% charact)
table[, cmom] <- distrEx::E(D, fun = function(x) {
(x - distrEx::E(D))^cmoment
})
print(table)
return(invisible(table))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.