moments: Moment function

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Calcule theoretical raw, central, absolute or absolute central moments of continuous or discrete probability distribution function.

Usage

1
moments(k, dist, param, domain, central = FALSE, absolute = FALSE)

Arguments

k

order of the moment of interest

dist

density or mass name for the distribution. The created density or mass functions must have a name of the form dxxx. To understand its use see details and examples.

param

are the parameters of the distribution. The name of each parameter must be specified. To understand its use see examples.

domain

defines the domain of the distribution function. The type of domain of distribution to be tried see details.

central

logical; if TRUE, the k-th central moments are given as E[(X-μ)^k]. FALSE is the default value.

absolute

logical; if TRUE, the k-th absolute moments are given as E|X|^k]. FALSE is the default value.

Details

The moments function supports probability distribution functions of a large number of libraries.

In the dist argument, you must enter the name of the distribution of interest, for example, you can enter "gamma" or "dgamma", both will produce the same result.

If f(x) has no parameters, then do param = NULL.

The following are the different domain argument:

If central = TRUE and absolute = TRUE are selected, the k-th central absolute moments is calculated and given as E|(X-μ)^k|.

Value

moments gives the theorical k-th raw, central, absolute or central-absolute moments of any continuous or discrete probability distribution function.

Note

Many continuous distributions support domain = "realline" even though they are not defined from - to because of their programming.

In the same way, many discrete distributions support domain = "counts" even though they are not defined from 0 to or 1 to because of their programming.

It is recommended to try initially with this argument.

Discrete distributions require the existence of the quantile function, of the form qxxx.

Author(s)

Jorge Iván Pérez, jivan.perez@udea.edu.co

See Also

Distributions for other standard distributions.

cumulants, skew, kurt.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Let's try first with distributions of the library stats
moments(k = 1:4, dist = "dchisq", param = c(df = 3), domain = "realplus")
# or
moments(k = 1:4, dist = "chisq", param = c(df = 4), domain = "realplus")

#---------------------------------------------------------------------------------------

# The name of the created density functions must have a name
# of the form dxxx. Also, how does it not have parameters
# then param = NULL
dmyfunction <- function(x) x^3/4 
# so that it integrates to 1, x must be between 0 to 2.
moments(k = 1:4, dist = "dmyfunction", param = NULL, domain = c(0, 2))

#---------------------------------------------------------------------------------------

# Let's try distributions from other libraries
if(!require("extraDistr")) install.packages("extraDistr") # to install the package
# The same result is obtained with the diferent domain (see 'Note')
moments(k = 1:2, dist = "dpareto", param = c(a = 3, b = 7),
        domain = "realline")
# or
moments(k = 1:2, dist = "dpareto", param = c(a = 3, b = 7),
        domain = c(7, Inf))
# In this case, no moments are calculated for k> 2, because the
# parameter of the pareto distribution is a = 3, and
# therefore, the moments are defined for E (X ^ k) < a.
# Read about pareto distribution for more information.

#---------------------------------------------------------------------------------------

# Let's try distributions from other libraries to calculated rae, central
# and absolute moments
if(!require("gamlss.dist")) install.packages("gamlss.dist") # to install the package
moments(k = 3, dist = "PE", param = c(mu = -25, sigma = 7, nu = 4),
        domain = "realline") 
moments(k = 3, dist = "PE", param = c(mu = -25, sigma = 7, nu = 4),
        central = TRUE, domain = "realline") 
moments(k = 3, dist = "PE", param = c(mu = -25, sigma = 7, nu = 4),
        absolute = TRUE, domain = "realline")
moments(k = 3, dist = "PE", param = c(mu = -25, sigma = 7, nu = 4),
        central = TRUE, absolute = TRUE, domain = "realline")

#---------------------------------------------------------------------------------------

# Let's try with a discrete counting distribution to calculated
# raw and central moments
if(!require("gamlss.dist")) install.packages("gamlss.dist") # to install the package
moments(k = 1:4, dist = "DEL", param = c(mu = 2, sigma = 3, nu = 0.5),
        domain = "counts")
moments(k = 1:4, dist = "DEL", param = c(mu = 2, sigma = 3, nu = 0.5),
        domain = "counts", central = TRUE)
        
#---------------------------------------------------------------------------------------

# Let's try with a discrete binomial type distribution to calculated
# raw and central moments
moments(k = 1:4, dist = "binom", param = c(size = 15, prob = 0.3),
        domain = "binom")
moments(k = 1:4, dist = "binom", param = c(size = 15, prob = 0.3),
        domain = "binom", central = TRUE)

jiperezga/DistMom documentation built on May 26, 2019, 9:32 a.m.