hist_3d: hist_3d

hist_3dR Documentation

hist_3d

Description

This function can be used in order to construct a 3D histogram based on 3 variables and relative breaks directly provided as inputs.

Usage

hist_3d(
  x,
  y,
  z,
  breaks_x,
  breaks_y,
  breaks_z,
  same.scale = FALSE,
  na.rm = TRUE,
  FUN = length
)

Arguments

x

either a numerical vector to be partitioned or a matrix with 3 numerical columns to be partitioned.

y

a numerical vector to be partitioned. Not required if x is a matrix.

z

a numerical vector to be partitioned. Not required if x is a matrix

breaks_x

a numerical vector. Contains the breaks related to x for the histogram

breaks_y

a numerical vector. Contains the breaks related to y for the histogram

breaks_z

a numerical vector. Contains the breaks related to z for the histogram

same.scale

logical. Default to FALSE. If TRUE, breaks_x will be used for x, y and z

na.rm

logical. Default to TRUE. Indicates whether missing values should be removed

FUN

function used to summarize bin contents.

Details

The default function used for the argument FUN is the function length. When another function is used, it is applied on x or on the first column of x if this is a three-column matrix. The lower limit of each class interval is included in the class and the upper limit is not.

Value

Using a given set of breaks per each variable, the function returns :

Hist.Values

a 3 dimensional array. The 1st (respectively 2nd, 3rd) dimension is related to the class intervals of x (resp. y, z). Contingency table is returned if FUN=length

breaks_x, breaks_y, breaks_z

same as the inputs of the function

Midpoints.x, Midpoints.y, Midpoints.z

the midpoints for each bin per variable

nobs.x , nobs.y, nobs.z

number of observations of x, y and z

n.bins

vector of 3 elements containing the number of bins for x, y and z

Examples

set.seed(4)
hist_3d(x = rnorm(1000),
        y = rnorm( 1000,5,0.1),
        z = rnorm( 1000,2,1),
        breaks_x = seq(-4, 4, by =1),
        breaks_y = seq(2, 8, by =1),
        breaks_z = seq(-2, 6, by =1))

SpiceFP documentation built on June 7, 2023, 5:55 p.m.