Learn R Programming

NormalGamma (version 1.1)

dnormgam: Normal-gamma density

Description

Computes the convolution product of a normal and a gamma densities.

Usage

dnormgam(par, x = NULL, N0 = 65536, plot = TRUE, log = FALSE, tail.cor = TRUE, cor = 1e-15, mu = par[1], sigma = par[2], k = par[3], theta = par[4])

Arguments

par
vector of parameters; (par[1],par[2]) are the mean and standard deviation of the normal distribution and (par[3],par[4]) are the shape and scale parameters of the gamma distribution.

x
vector of values where the density is computed; if x == NULL, the density is computed on a sequence of values from 0 to par[1]+5*par[2]+q where q is the quantile of probability 0.99999 of the gamma distribution.

N0
number of equally spaced values in the Fast Fourier Transform (see details).
plot
logical; if TRUE plot of the density.

log
logical; if TRUE density d is given as log(d).
tail.cor
logical; if TRUE a linear approximation of right tail adjusts numerical instability.
cor
limit of right tail correction; if tail.cor == TRUE, linear approximation is applied to values with density estimate smaller than cor.
mu, sigma
alternative definition of mean and standard deviation of the normal distribution.
k, theta
alternative definition of shape and scale parameters of the gamma distribution.

Value

xout
vector of values where normal-gamma density is computed; equal to x when x is not NULL.
dout
vector of values of normal-gamma density.

Details

The convoluted density is computed using the fft function (Fast Fourier Transform). See details in Plancade S., Rozenholc Y. and Lund E., BMC Bioinfo 2012.

Only one definition of the parameters is required, either par or (mu, sigma, k, theta). If both are specified and do not match, an error message is returned.

References

Plancade S., Rozenholc Y. and Lund E. "Generalization of the normal-exponential model : exploration of a more accurate parametrisation for the signal distribution on Illumina BeadArrays", BMC Bioinfo 2012, 13(329).

See Also

normgam.fit computes the Maximum Likelihood Estimator and normgam.signal implements the background correction using the normal-gamma model.

Examples

Run this code

## Example 1

par = c(-10, 5, 2, 20)
F = dnormgam(par)

## Example 2 

n = 50000
par = c(60,5,0.15,400)
F = dnormgam(par, plot=FALSE)

X = rnorm(n, mean=par[1], sd=par[2]) + rgamma(n, shape=par[3], scale=par[4]) 
H = histogram(X, type='irregular', verbose=FALSE, plot=FALSE)
plot(H, xlim=c(0,500))
lines(F$xout, F$dout, col='red')

Run the code above in your browser using DataLab