spikecomp
spikecomp.RdCompute Elements of a Spike Histogram
Arguments
- x
a numeric variable
- method
specifies the binning and output method. The default is
'tryactual'and is intended to be used for spike histograms plotted in a way that allows for random x-coordinates and data gaps. No binning is done if there are less than 100 distinct values and the closest distinctxvalues are distinguishable (not with 1/500th of the data range of each other). Binning usespretty. Whentransis specified to transformxto reduce long tails due to outliers,prettyrounding is not done, andlumptailsis ignored.method='grid'is intended for sparkline spike histograms drawn with bar charts, where plotting is done in a way that x-coordinates must be equally spaced. For this method, extensive binning information is returned. For either'tryactual'or'grid', the default iftransis omitted is to put all values beyond the 0.01 or 0.99 quantiles into a single bin so that outliers will not create long nearly empty tails. Whenyis specified,methodis ignored.- lumptails
the quantile to use for lumping values into a single left and a single right bin for two of the methods. When outer quantiles using
lumptailsequal outer quantiles using2*lumptails,lumptailsis ignored as this indicates a large number of ties in the tails of the distribution.- normalize
set to
FALSEto not divide frequencies by maximum frequency- y
a vector of frequencies corresponding to
xif you want the (x,y) pairs to be taken as a possibly irregular-spaced frequency tabulation for which you want to convert to a regularly-spaced tabulation likecount='tabulate'produces. If there is a constant gap betweenxvalues, the original pairs are return, with possible removal ofNAs.- trans
a list with three elements: the name of a transformation to make on
x, the transformation function, and the inverse transformation function. The latter is used formethod='grid'. Whentransis givenlumptailsis ignored.transapplies only tomethod='tryactual'.- tresult
applies only to
method='tryactual'. The default'list'returns a list with elementsx,y, androundedTo.method='segments'returns a list suitable for drawing line segments, with elementsx, y1, y2.method='roundeddata'returns a list with elementsx(non-tabulated rounded data vector after excludingNAs) and vectorroundedTo.
Value
when y is specified, a list with elements x and y. When method='tryactual' the returned value depends on tresult. For method='grid', a list with elements x and y and scalar element roundedTo containing the typical bin width. Here x is a character string.
Details
Derives the line segment coordinates need to draw a spike histogram. This is useful for adding elements to ggplot2 plots and for the describe function to construct spike histograms. Date/time variables are handled by doing calculations on the underlying numeric scale then converting back to the original class. For them the left endpoint of the first bin is taken as the minimal data value instead of rounded using pretty().