Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

makePatterns

Concatenate Multivariate Data into Numeric or Character Patterns


Description

Function to concatenate the columns of a matrix or data frame for each row into a single character variable, which can optionally be reconverted to numeric. Called internally by sorter. For example, a row of a matrix containing c(1, 2, 3, 5) will be concatenated to "1235".

Usage

makePatterns(dat, times, 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, should a numeric version of the concatenate rows be return. Default is TRUE. When num=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. Users are encouraged to try sorting with num=TRUE and num=FALSE when experimenting to find the sorting that leads to the clearest plot. When lc$sorted=FALSE and there is no missing data in lc$y and lc$IntTime=FALSE, longCatPlot will change num to FALSE.

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 (where times - times[,1] changes the times from a matrix of observed times to a matrix of durations for each state in dat). 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. See norpt.

Value

out

A vector of patterns of length nrow(dat)

.

Author(s)

Stephen 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

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 ) )

longCatEDA

Package for Plotting Categorical Longitudinal and Time-Series Data

v0.31
GPL (>= 3)
Authors
Stephen Tueller. Funded by the National Institute on Drug Abuse (NIDA) Award number 1R03DA030850, the National Institute on Alcohol Abuse and Alcoholism (NIAAA) Award Number R03 AA019775, and the National Institute of Justice Award Number 2011-RY-BX-0003.
Initial release
2017-03-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.