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

matrixfunctions.sirt

Some Matrix Functions


Description

Some matrix functions which are written in Rcpp for speed reasons.

Usage

rowMaxs.sirt(matr)      # rowwise maximum

rowMins.sirt(matr)      # rowwise minimum

rowCumsums.sirt(matr)   # rowwise cumulative sum

colCumsums.sirt(matr)   # columnwise cumulative sum

rowIntervalIndex.sirt(matr,rn) # first index in row nn when matr(nn,zz) > rn(nn)

rowKSmallest.sirt(matr, K, break.ties=TRUE) # k smallest elements in a row
rowKSmallest2.sirt(matr, K )

Arguments

matr

A numeric matrix

rn

A vector, usually a random number in applications

K

An integer indicating the number of smallest elements to be extracted

break.ties

A logical which indicates if ties are randomly broken. The default is TRUE.

Details

The function rowIntervalIndex.sirt searches for all rows n the first index i for which matr(n,i) > rn(n) holds.

The functions rowKSmallest.sirt and rowKSmallest2.sirt extract the K smallest entries in a matrix row. For small numbers of K the function rowKSmallest2.sirt is the faster one.

Value

The output of rowMaxs.sirt is a list with the elements maxval (rowwise maximum values) and maxind (rowwise maximum indices). The output of rowMins.sirt contains corresponding minimum values with entries minval and minind.

The output of rowKSmallest.sirt are two matrices: smallval contains the K smallest values whereas smallind contains the K smallest indices.

Author(s)

Alexander Robitzsch

The Rcpp code for rowCumsums.sirt is copied from code of Romain Francois (https://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-October/001198.html).

See Also

For other matrix functions see the matrixStats package.

Examples

#############################################################################
# EXAMPLE 1: a small toy example (I)
#############################################################################
set.seed(789)
N1 <- 10 ; N2 <- 4
M1 <- round( matrix( runif(N1*N2), nrow=N1, ncol=N2), 1 )

rowMaxs.sirt(M1)      # rowwise maximum
rowMins.sirt(M1)      # rowwise minimum
rowCumsums.sirt(M1)   # rowwise cumulative sum

# row index for exceeding a certain threshold value
matr <- M1
matr <- matr / rowSums( matr )
matr <- sirt::rowCumsums.sirt( matr )
rn <- runif(N1)    # generate random numbers
rowIntervalIndex.sirt(matr,rn)

# select the two smallest values
rowKSmallest.sirt(matr=M1, K=2)
rowKSmallest2.sirt(matr=M1, K=2)

sirt

Supplementary Item Response Theory Models

v3.10-118
GPL (>= 2)
Authors
Alexander Robitzsch [aut,cre] (<https://orcid.org/0000-0002-8226-3132>)
Initial release
2021-09-22 17:45:34

We don't support your browser anymore

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