gensphere: Generalized spherical distribution definition, density,...

Description Usage Arguments Details Value See Also Examples

View source: R/gensphere.R

Description

Define a generalized spherical distribution by specifying a contour function, a radial density function, a radial simulation function, and a value of the density at the origin. Once it is defined, compute density and simulate that distribution.

Usage

1
2
3
gensphere(cfunc, dradial, rradial, g0)
dgensphere(x, gs.dist)
rgensphere(n, gs.dist)

Arguments

cfunc

contour function object defined by cfunc.new, cfunc.add.term and cfunc.finish

dradial

a function to evaluate the density for the radial component of distribution

rradial

a function to simulate values of the radial distribution

g0

g(0) = value of the multivariate density at the origin

x

(d x n) matrix of point where the density is to be evaluated. Columns x[,i] are vectors in d-space

gs.dist

a generalized spherical distribution, an object returned by function gensphere

n

number of values to generate

Details

A generalized spherical distribution is specified by calling function gensphere with the contour function (defined via function cfunc.new, cfunc.add.term and cfunc.finish), a function to compute the density of the radial term R, a runction to simulate from the radial term R, and g(0)=the value of the density at the origin. See the general representation of generalized spherical laws in gensphere-package.

If the distribution is d dimensional and the radial term is a gamma distribution with shape=shape and scale=1,g(0)=0 if d < shape, g(0)=cfunc$norm.const if d=shape, g(0)=Inf if d > shape. In general, g(0)=lim_{r -> 0+} r^(1-d)*dradial(r).

Value

gensphere returns an S3 object of class "gensphere.distribution" with components:

cfunc

a contour function defined with cfunc.new, etc.

dradial

a function that evaluates the desnity of the radial component

rradial

a function that simulates values of the radial component

g0

g(0), the value of the multivariate density g(x) at the origin

dgensphere returns a numeric vector y that contains the value of the density of X: y[i]=g(x[,i]), i=1,...,n. Note that g(x) is the density of the vector X, whereas dradial is the denis of the univariate radial term R.

rgensphere returns a (d x n) matrix of simulated values of X. Note that these values are an approximation to the distribution of X because the contour is approximated to a limited accuracy in cfund.finish.

Here are plots of the density surface and simulated points generated by the examples below.

densitysurface.png rgensphere.png

See Also

gensphere-package, cfunc.new

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
# define a diamond shaped contour
cfunc1 <- cfunc.new(d=2)
#cfunc1 <- cfunc.add.term( cfunc1,"lp.norm",k=c(1,1))
cfunc1 <- cfunc.add.term( cfunc1,"gen.lp.norm",k=c(1,1,2,0,0,1))
cfunc1 <- cfunc.finish( cfunc1 )
cfunc1


# define a generalized spherical distribution
rradial <- function( n ) { rgamma( n, shape=2 ) }
dradial <- function( x ) { dgamma( x, shape=2 ) }
dist1 <- gensphere( cfunc1, dradial, rradial, g0=cfunc1$norm.const ) 
dist1

# calculate density at a few points
dgensphere( x=matrix( c(0,0, 0,1, 0,2), nrow=2, ncol=3), dist1 )

# calculate and plot density surface on a grid
xy.grid <- seq(-3,3,.1)
z <- gs.pdf2d.plot( dist1, xy.grid )
title3d("density surface")

# simulate values from the distribution
x <- rgensphere( 10000, dist1 )
plot(t(x),xlab="x",ylab="y",main="simulated points")

gensphere documentation built on Sept. 17, 2017, 1:02 a.m.