The Normal or Gaussian distribution, is an absolute continuous probability distribution characterized by two parameters: the mean \(\mu\) and the standard deviation \(\sigma > 0\).
Usage
Norm(mean = 0, sd = 1)
# S4 method for class 'Norm,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Norm,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Norm,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Norm,numeric'
r(distr, n)
# S4 method for class 'Norm'
mean(x)
# S4 method for class 'Norm'
median(x)
# S4 method for class 'Norm'
mode(x)
# S4 method for class 'Norm'
var(x)
# S4 method for class 'Norm'
sd(x)
# S4 method for class 'Norm'
skew(x)
# S4 method for class 'Norm'
kurt(x)
# S4 method for class 'Norm'
entro(x)
# S4 method for class 'Norm'
finf(x)
llnorm(x, mean, sd)
# S4 method for class 'Norm,numeric'
ll(distr, x)
enorm(x, type = "mle", ...)
# S4 method for class 'Norm,numeric'
mle(distr, x, na.rm = FALSE)
# S4 method for class 'Norm,numeric'
me(distr, x, na.rm = FALSE)
vnorm(mean, sd, type = "mle")
# S4 method for class 'Norm'
avar_mle(distr)
# S4 method for class 'Norm'
avar_me(distr)
Arguments
- mean, sd
numeric. The distribution parameters.
- distr
an object of class
Norm
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classNorm
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log, log.p
logical. Should the logarithm of the probability be returned?
- q
numeric. Vector of quantiles.
- lower.tail
logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).
- p
numeric. Vector of probabilities.
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.- type
character, case ignored. The estimator type (mle or me).
- ...
extra arguments.
- na.rm
logical. Should the
NA
values be removed?
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability density function (PDF) of the Normal distribution is: $$ f(x; \mu, \sigma) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{1}{2} \left(\frac{x - \mu}{\sigma}\right)^2} .$$
Examples
# -----------------------------------------------------
# Normal Distribution Example
# -----------------------------------------------------
# Create the distribution
m <- 3 ; s <- 5
D <- Norm(m, s)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 2, 10)) # density function
#> [1] 0.06896360 0.07820854 0.02994549
p(D, c(0.3, 2, 10)) # distribution function
#> [1] 0.2945985 0.4207403 0.9192433
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 1.733264 7.208106
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 0.078650831 0.071248098 0.063883691 0.045684726 0.074109441 0.068844386
#> [7] 0.070942812 0.039245920 0.063001126 0.050106204 0.077751153 0.014420567
#> [13] 0.064924210 0.032749269 0.050756855 0.074566208 0.079180545 0.075199984
#> [19] 0.061202487 0.033300464 0.030305207 0.071296206 0.073578283 0.058318078
#> [25] 0.050180746 0.059131967 0.002231858 0.078676649 0.070579973 0.070531879
#> [31] 0.038032248 0.069096838 0.070028032 0.078514822 0.072967542 0.079070596
#> [37] 0.009870757 0.059841532 0.046116138 0.076482025 0.024996400 0.069688283
#> [43] 0.018916438 0.009799191 0.011214694 0.070064918 0.045776051 0.048613564
#> [49] 0.065543760 0.072246114 0.031051671 0.060964405 0.067714085 0.078849400
#> [55] 0.023375544 0.079653692 0.026272925 0.076982656 0.076031342 0.078878473
#> [61] 0.079473201 0.027871007 0.055928284 0.031634101 0.026608836 0.034119315
#> [67] 0.075487196 0.006984688 0.053439934 0.067785005 0.057795736 0.078881932
#> [73] 0.079248060 0.075993189 0.079490983 0.076012578 0.066666695 0.055914427
#> [79] 0.052621715 0.079407901 0.069083091 0.079376200 0.078922940 0.032720113
#> [85] 0.034634206 0.010430785 0.074730977 0.078975642 0.061954748 0.077616054
#> [91] 0.072757376 0.079580945 0.079778382 0.064312658 0.053466269 0.073363851
#> [97] 0.079733806 0.078418515 0.008356410 0.027016940
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 3
median(D) # Median
#> [1] 3
mode(D) # Mode
#> [1] 3
var(D) # Variance
#> [1] 25
sd(D) # Standard Deviation
#> [1] 5
skew(D) # Skewness
#> [1] 0
kurt(D) # Excess Kurtosis
#> [1] 0
entro(D) # Entropy
#> [1] 3.028376
finf(D) # Fisher Information Matrix
#> mean sd
#> mean 0.04 0.00
#> sd 0.00 0.08
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 3
# ------------------
# Point Estimation
# ------------------
enorm(x, type = "mle")
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
enorm(x, type = "me")
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
mle(D, x)
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
me(D, x)
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
e(D, x, type = "mle")
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
mle("norm", x) # the distr argument can be a character
#> $mean
#> [1] 3.338379
#>
#> $sd
#> [1] 4.817788
#>
# ------------------
# Estimator Variance
# ------------------
vnorm(m, s, type = "mle")
#> mean sd
#> mean 25 0.0
#> sd 0 12.5
vnorm(m, s, type = "me")
#> mean sd
#> mean 25 0.0
#> sd 0 12.5
avar_mle(D)
#> mean sd
#> mean 25 0.0
#> sd 0 12.5
avar_me(D)
#> mean sd
#> mean 25 0.0
#> sd 0 12.5
v(D, type = "mle")
#> mean sd
#> mean 25 0.0
#> sd 0 12.5