bMM: Create a matrix out of a vector or data.frame

View source: R/bMM.R

bMMR Documentation

Create a matrix out of a vector or data.frame

Description

Adapted from bartModelMatrix(). The compiled functions of this package operate on matrices in memory. Therefore, if the user submits a vector or data.frame, then this function converts it to a matrix. Also, it determines the number of cutpoints necessary for each column when asked to do so.

Usage

bMM(X, numcut=0L, usequants=FALSE, type=7, xicuts=NULL, rm.const=FALSE,
    rm.dupe=FALSE, method="spearman", use="pairwise.complete.obs")

Arguments

X

A vector or data.frame to create the matrix from.

numcut

The maximum number of cutpoints to consider. If numcut=0, then just return a matrix; otherwise, return a list.

usequants

If usequants is FALSE, then the cutpoints in xinfo are generated uniformly; otherwise, if TRUE, quantiles are used for the cutpoints.

type

Determines which quantile algorithm is employed.

xicuts

To specify your own cut-points, use the xicuts argument.

rm.const

To remove constant variables or not.

rm.dupe

To remove duplicate variables or not.

method,use

Correlation options.

Value

If numcut==0 (the default), then a matrix of the covariates is returned; otherwise, a list is returned with the following values.

X

A matrix of the covariates with n rows and p columns.

numcut

A vector of length p of the number of cut-points for each covariate.

grp

A vector that corresponds to variables in the input data.frame that were translated into dummy columns in the output matrix, i.e., for each input variable in order, there is a number in the vector corresponding to the number of output columns created for it.

dummy

Corresponds to grp with a two row matrix including the start column of each dummy group in row 1 and the end column in row 2.

See Also

xicuts

Examples


set.seed(99)

a <- rbinom(10, 4, 0.4)

table(a)

x <- runif(10)

df <- data.frame(a=factor(a), x=x)

(b <- bMM(df))

(b <- bMM(df, numcut=9))

(b <- bMM(df, numcut=9, usequants=TRUE))

## Not run: 
    ## this is an error
    f <- bMM(as.character(a))

## End(Not run)

nftbart documentation built on May 1, 2023, 1:08 a.m.

Related to bMM in nftbart...