Learn R Programming

mvmesh (version 1.6)

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.orthants=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 without setting this to TRUE. If TRUE, the value of freq is ignored: the histogram always shows count/surface area

breaks

specifes the subdivision of the region; see 'breaks' in SolidRectangle

plot.type

type of plot, see details below

positive.only

If TRUE, look only in the first orthant

report

level of warning messages; one of "summary", "all", "none".

label.orthants

If plot.type="index", this controls whether or not the orthants 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, see mvmesh

  • 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 described in the H-representation and tallied by TallyHrep. TallyCones does a similar function for cones from the origin and generated by a list of base simplices.

'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 for histRectangular and histSimplex; when the points are 3D, this only works for histRectangular. DrawPillars is used to plot the pillars.

  • "counts" - shows frequency counts as a number in the center of each simplex

  • "radial" - histDirectional only, shows radial spikes proportional to the counts

  • "grayscale" - histDirectional only, color codes simplices proportional to the counts

  • "orthogonal" - histDirectional only, shows radial spikes proportional to the counts

  • "default" - type depends on the dimension of the data and type of histogram

Examples

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

# }
# NOT RUN {
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,] <- A <!-- %*% (1/runif(2)) } -->
dev.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