makePatterns: Concatenate Multivariate Data into Numeric or Character...

View source: R/sorter.R

makePatternsR Documentation

Concatenate Multivariate Data into Numeric or Character Patterns

Description

This function concatenates the columns of a matrix or data frame for each row into a single character variable, which can optionally be reconverted to numeric. It is typically called internally by sorter. For example, a row of a matrix containing c(1, 2, 3, 5) will be concatenated into ⁠"1235"⁠.

Usage

makePatterns(dat, times = NULL, num = TRUE, mindur = NULL, igrpt = FALSE)

Arguments

dat

A matrix or data frame such as lc$y from an longCat object created by longCat.

times

See times in longCat.

num

Logical indicator, specifying whether a numeric version of the concatenated rows should be returned. When TRUE, the return is rescaled by moving a decimal point between the first and second digits. This ensures that, under different numbers of observations or missing data, ordering is not unduly impacted by patterns of missing data. Default is TRUE.

mindur

Minimum duration. If times is a matrix or data frame of individually varying times of observation of the same dimension as dat, selecting mindur > 0 results in all cells in y corresponding to cells in times - times[,1] < mindur being changed to NA. This minimizes the effect of short durations on the sorting algorithm in sorter. Default is NULL.

igrpt

Option to ignore repeated values when sorting, allowing the sorting algorithm in sorter to smooth over regions of no change for each row in lc$y. Default is FALSE.

Value

A vector of patterns of length nrow(dat).

Author(s)

Stephen J. Tueller

References

Tueller, S. J., Van Dorn, R. A., & Bobashev, G. V. (2016). Visualization of categorical longitudinal and times series data (Report No. MR-0033-1602). Research Triangle Park, NC: RTI Press. http://www.rti.org/publication/visualization-categorical-longitudinal-and-times-series-data

See Also

sorter for further processing of patterns.

Examples

# create an arbitrary matrix and demonstrate
temp <- matrix( sample(1:9, 40, replace=TRUE), 10, 4)
print(temp)
makePatterns(temp, num=FALSE)

# examine the unique patterns of data
bindat <- matrix( sample(0:1, 500, replace=TRUE), 100, 5)
uniquePatterns <- makePatterns(bindat, num=FALSE)
as.matrix(table(uniquePatterns))


stueller/longCatEDA documentation built on March 9, 2024, 4:08 a.m.