Learn R Programming

pmcgd (version 1.1)

class: Matrix of Indicator Variables given Classification

Description

Converts a classification vector into a matrix of indicator variables.

Usage

class(groups, k)

Arguments

groups
A numeric vector of integers. Typically the distinct entries of this vector would represent a classification of observations in a data set.
k
An integer indicating the number of groups.

Value

An $n$ (number of observations) by $k$ (number of groups) matrix of (0,1) indicator variables. The [i,j]th entry is 1 if groups[i] is j and 0 otherwise.

References

Punzo, A., and McNicholas, P. D. (2013). Outlier Detection via Parsimonious Mixtures of Contaminated Gaussian Distributions. arXiv.org e-print 1305.4669, available at: http://arxiv.org/abs/1305.4669.

See Also

pmcgd-package,MS

Examples

Run this code

n <- 20
k <- 3
prob <- c(0.5,0.3,0.2)
groups <- sample(1:k, size=n, replace = TRUE, prob = prob)
matclass <- class(groups, k)
matclass

Run the code above in your browser using DataLab