Last data update: 2014.03.03

R: Maximum _a posteriori_ (MAP) Classification
MAPR Documentation

Maximum a posteriori (MAP) Classification

Description

MAP obtains maximum a posteriori (MAP) classifications. unMAP converts a classification vector into an indicator matrix.

Usage

MAP(mat, tie = c("random", "standard"))
unMAP(vec)

Arguments

mat

An N \times G matrix, typically N denotes observations from a dataset and G denotes the number of underlying groups in the data. Each row is expected to contain positive entries which sum to 1, but this isn't strictly necessary.

tie

May take one of two values, "random" or "standard". Takes the value "random" by default. See 'Details'.

vec

An vector consisting of integer entries. unMAP is intended to be used with a vector whose entries are classifications of dataset observations.

Details

For each row in mat, MAP assigns an indexing value identifying the entry in the row taking the highest value. In the case where multiple values in a row share a common largest value, tie determines how such a value is chosen. If tie = "random", one of the suitable values is chosen at random; when tie = "standard", the first such suitable value is selected, in common with other packages. Defaults to "random".

Value

MAP returns a classification vector. unMAP returns a classification matrix, with each row indicating group membership by the column entry which is non-zero (and equal to one).

Author(s)

Arthur White

See Also

Zscore

Examples

##Simple example
s1<- sample(1:2, 10, replace=TRUE)
unMAP(s1)
MAP(unMAP(s1))

##More to the point
data(Alzheimer)
fit<- blca.em(Alzheimer, 2)
MAP(fit$Z) ## Best estimates of group membership. 

mat1<- matrix(1/3, nrow=10, ncol=3) ##demonstrating the use of "tie" argument
MAP(mat1, tie="random")
MAP(mat1, tie="standard")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BayesLCA)
Loading required package: e1071
Loading required package: coda
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/BayesLCA/MAP.Rd_%03d_medium.png", width=480, height=480)
> ### Name: MAP
> ### Title: Maximum _a posteriori_ (MAP) Classification
> ### Aliases: MAP unMAP
> ### Keywords: map unmap
> 
> ### ** Examples
> 
> ##Simple example
> s1<- sample(1:2, 10, replace=TRUE)
> unMAP(s1)
      [,1] [,2]
 [1,]    1    0
 [2,]    1    0
 [3,]    1    0
 [4,]    0    1
 [5,]    1    0
 [6,]    0    1
 [7,]    0    1
 [8,]    1    0
 [9,]    0    1
[10,]    1    0
> MAP(unMAP(s1))
 [1] 1 1 1 2 1 2 2 1 2 1
> 
> ##More to the point
> data(Alzheimer)
> fit<- blca.em(Alzheimer, 2)
Restart number 1, logpost = -749.43... 
Restart number 2, logpost = -749.44... 
Restart number 3, logpost = -749.44... 
Restart number 4, logpost = -749.44... 
Restart number 5, logpost = -749.44... 
> MAP(fit$Z) ## Best estimates of group membership. 
 [1] 1 1 1 1 1 2 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 2 2 2 2 1 1 2 2 1 1 2 2 2 2
[39] 2
> 
> mat1<- matrix(1/3, nrow=10, ncol=3) ##demonstrating the use of "tie" argument
> MAP(mat1, tie="random")
[1] "Some observations mapped to more than one group - these will be chosen at random."
 [1] 2 3 1 3 2 1 1 2 1 2
> MAP(mat1, tie="standard")
 [1] 1 1 1 1 1 1 1 1 1 1
Warning messages:
1: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
2: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
3: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
4: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
5: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
6: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
7: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
8: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
9: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
10: In map1[ind] <- M[mat[ind, ] == maxmat[ind]] :
  number of items to replace is not a multiple of replacement length
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>