Learn R Programming

optmatch (version 0.9-3)

makeInfinitySparseMatrix: (Internal) Creating sparse matching problems

Description

Create InfinitySparseMatrix distance specifications. Finite entries indicate possible matches, while infinite entries indicated non-allowed matches. This data type can be more space efficient for sparse matching problems.

Usage

makeInfinitySparseMatrix(data, cols, rows,
    colnames = NULL, rownames = NULL, dimension = NULL,
    call = NULL)

as.InfinitySparseMatrix(x)

## S3 method for class 'InfinitySparseMatrix': dimnames(x)

## S3 method for class 'InfinitySparseMatrix': dimnames(x, value) <- value

Arguments

data
A vector of distances for the finite (allowed) treatment-control pairs.
cols
A vector indicating the column number for each entry in data.
rows
A vector indicating the row number for each entry in data.
colnames
A optional character vector with the columns names of the matrix.
rownames
A optional character vector with the row names of the matrix.
dimension
An optional vector giving the dimensions of the matrix, which can be useful for indicating matrices with entirely Inf rows or columns. If supplied with row and columns names, it must match.
x
A matrix to be converted to an InfinitySparseMatrix.
call
Optional call object to store with the distance specification. Allows calling update on the distance object at later points.
value
a possible value for dimnames(x): see the Value section.

Value

  • An object of class InfinitySparseMatrix, which will work as a distance argument to fullmatch or pairmatch

Details

Usually, users will create distance specification using match_on, caliper, or exactMatch, but if you need to generate sparse matching problems directly, use this function. If the data are already in a matrix form, use as.InfinitySparseMatrix. If you have the finite entries in a vector format, use makeInfinitySparseMatrix.

See Also

match_on, caliper, exactMatch, fullmatch, pairmatch

Examples

Run this code
example.matrix <- matrix(c(1,2,Inf, 3,Inf,4, Inf,Inf,Inf), byrow = TRUE, nrow = 3,
                          dimnames = list(letters[1:3], LETTERS[24:26]))

optmatch:::as.InfinitySparseMatrix(example.matrix)

# create the same sparse matrix directly, function will create the appropriate dims
# the data are in a different order, but the indices are correct
(example.ism <- 
  optmatch:::makeInfinitySparseMatrix(c(1,2,3,4), 
                                      c(1,2,1,3), 
                                      c(1,1,2,2), 
                                      LETTERS[24:26],
                                      letters[1:3]))

Run the code above in your browser using DataLab