# NOT RUN {
# define a diamond shaped contour
cfunc1 <- cfunc.new(d=2)
cfunc1 <- cfunc.add.term( cfunc1,"gen.lp.norm",k=c(1,1,2,0,0,1))
cfunc1 <- cfunc.finish( cfunc1 )
cfunc1
# }
# NOT RUN {
# 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 )
# simulate values from the distribution
x <- rgensphere( 10000, dist1 )
# calculate and plot density surface on a grid
xy.grid <- seq(-3,3,.1)
if( interactive() ) {
z <- gs.pdf2d.plot( dist1, xy.grid )
title3d("density surface")
plot(t(x),xlab="x",ylab="y",main="simulated points")
}
# }
Run the code above in your browser using DataLab