Learn R Programming

mvmesh (version 1.2)

mvhist: Multivariate histograms

Description

Tabulate and plot histograms for multivariate data, including directional histograms

Usage

histDirectional( x, k, p=2, plot.type="default", freq=TRUE, positive.only=FALSE, 
     report="summary", label.octants=TRUE, normalize.by.area=FALSE, ... )
histDirectionalQuantileThreshold( x, probs=1, p=2, k=3, positive.only=FALSE, ... )
histDirectionalAbsoluteThreshold( x, thresholds=0, p=2, k=3, positive.only=FALSE,...)     
histRectangular( x, breaks=10, plot.type="default", freq=TRUE, report="summary", ... )
histSimplex( x, S, plot.type="default", freq=TRUE, report="summary", ... )

TallyHrep( x, H, report="summary" )  
DrawPillars( S, height, shift=rep(0.0,3), ... )

Arguments

x
data in an (n x d) matrix; rows are d-dimensional data vectors
k
number of subdivisions
p
power of p-norm
freq
TRUE for a frequency histogram, FALSE for a relative frequency histogram. See note about normalize.by.area
normalize.by.area
if TRUE, then the counts are normalized by the surface area of the corresponding simplex on the sphere. This is useful since in general the surface area varies and counts will vary accordingly. In particular, isotropic data will not appear isotropic
breaks
specifes the subdivision of the region; see 'breaks' in RectangularMesh
plot.type
type of plot, see details below
positive.only
If TRUE, look only in the first octant
report
level of warning messages; one of "summary", "all", "none".
label.octants
If plot.type="index", this controls whether or not the octants are labeled on the plot.
probs
vector of probabilites specifying what fraction of the extremes to keep
thresholds
vector of thresholds specifying cutoff for extremes to keep
...
Optional arguments to plot
S
(vps x d x nS) array of simplices in V representation, see V2Hrep
H
array of simplices in H representation, see V2Hrep
height
vector of length nS giving the heights of the pillars
shift
shift of the pillars, typically (0,0,0) for 2d data or (0,0,z0) for 3d data

Value

  • A plot is drawn (unless plot.type="none"). A list is returned invisibly, with fields:
    • counts - frequency count in each bin
    • nrejects - number of x values not in any bin
    • nties - number of points in more than one bin (if bins are set up to be non-overlapping, this should only occur on a shared edge between two simplices)
    • nx - total number of data points in x
    • rel.freq - counts/nx
    • rel.rejects - nrejects/nx
    • mesh - object of type mvmesh, seemvmesh
    • plot.type - input value
    • report - input value

Warning

This is experimental code, and not throughly tested. If you have problems, please let me know.

Details

Calculate and plot multivariate histograms. histDirectional plots a directional histogram for all the data, histDirectionalQuantileThreshold plots m=length(probs) directional histograms, with plot i using the top probs[i] fraction of the data, histDirectionalAbsoluteThreshold plots m=length(cut.off) directional histograms, with plot i using the top probs[i] fraction of the data, histSimplex plots histogram based on simplices specified in S, histRectangular plots histogram based on a rectangular grid, In all cases, the bins are simplices computed from some description computed using the H-representation by TallyHrep. TallyCones does a similar function for cones generated by a list of base simplices. DrawPillars is used to plot 3-dimensional 'pillars' showing heights over a simplex. 'plot.type' values depend on the type of plot being used. Possible values are:
  • "none" - does not show a plot, just return the counts
  • "index" - shows a histogram of simplex index number versus count, does not show the geometry, but works in any dimension
  • "pillars" - shows a 3D plot with pillars/columns having base the shape of the simplices and height proportional to frequency counts. When the points are 2D, this works forhistRectangularandhistSimplex; when the points are 3D, this only works forhistRectangular
  • "counts" - shows frequency counts as a number in the center of each simplex
  • "radial" -histDirectionalonly, shows radial spikes proportional to the counts
  • "grayscale" -histDirectionalonly, shows radial spikes proportional to the counts
  • "orthogonal" -histDirectionalonly, shows radial spikes proportional to the counts
  • "default" - type depends on the dimension of the data and type of histogram

Examples

Run this code
# two dimensional, isotropic
x <- matrix( rnorm(8000), ncol=2 )
histDirectional( x, k=1 )

histRectangular( x, breaks=5 )

# some directional 2-dim data
n <- 1000
A <- matrix( c(1,2, 4,1), nrow=2,ncol=2)
x2 <- matrix( 0.0, nrow=n, ncol=2 )
for (i in 1:n) { x2[i,] <- Adev.new(); par(mfrow=c(2,2))
plot(x2,main="Raw data",col='red')
histDirectionalQuantileThreshold( x2, probs=c(1,0.25,0.1), p=1, 
    positive.only=TRUE, col='green',lwd=3)
dev.new(); par(mfrow=c(2,2))
histDirectionalAbsoluteThreshold( x2, thresholds=c(0,50,100,200), p=1, 
    positive.only=TRUE, col='blue',lwd=3)


# three dimensional positive data
x3 <- matrix( abs(rnorm(9000)), ncol=3 )
histDirectional( x3, k=3, positive.only=TRUE, col='blue', lwd=3 )
histRectangular( x3, breaks=4 )

demo(mvhist) # shows a range of multivariate histograms
}

Run the code above in your browser using DataLab