dgennorm: PDF for the generalised gaussian function

Description Usage Arguments Details Value Author(s) Examples

View source: R/dgennorm.R

Description

Calculate the PDF of the generalised normal distribution.

Usage

1
dgennorm(x, scale, shape, log = F)

Arguments

x:

Vector of (positive) deviates from the mean.

scale:

Float giving scale parameter.

shape:

Float giving shape parameter

Details

The generalised normal distribution (GGD) is a generalisation of the exponential family of functions. It has the form:

b/(2aΓ(1/b)) exp[-(x/a)^b]

where x is vector of positive values, a is a scale parameter, and b is a shape parameter. Γ indicates the standard Euler Gamma function. The GDD is identical to the normal (with SD=sqrt(a)) and exponential distributions when b is 2 and 1 respectively. The GGD is useful because it allows for modelling leptokurtosis; decreasing values of b indicate fatter tails.

Value

'dgennorm' gives a vector of probabilities of the data given shape and scale parameters.

Author(s)

Tom Ellis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Basic example for when the gen. gaussian matches the common-or-garden gaussian.
d  <- rnorm(1000) # simulate a standard normal
# throws an error because of negative values
d_generalised_gaussian(d, scale = 1, shape =2)

# Try again, but make sure values are positive
d <- abs(rnorm(1000))
# Determine the maximum likelihood value for the scale
(in theis case equivalent to the variance of the Gaussian).
sc <- seq(1, 3, 0.01) # values to test
# Get the likelihood of the data for each value in sc
yv <- sapply(sh, function(v) sum(d_generalised_gaussian(d, scale = v, shape =2, log=T)))
plot(sh, yv, type='l') # Plot likelihood curve.
# ML value is around 1.44, which is approximately sqrt(2)
sh[which(yv == max(yv))]

ellisztamas/snaptools documentation built on May 19, 2020, 2:03 p.m.