Classifier_Bayes function

Classifier based on Bayes rule

Classifier based on Bayes rule

A classifier based on Bayes rule, that is maximum a posterior probabilities of class membership

Classifier_Bayes(dat, n, p, g, pi, mu, sigma, ncov = 2)

Arguments

  • dat: An n×pn\times p matrix where each row represents an individual observation
  • n: Number of observations.
  • p: Dimension of observation vecor.
  • g: Number of classes.
  • pi: A g-dimensional vector for the initial values of the mixing proportions.
  • mu: A p×gp \times g matrix for the initial values of the location parameters.
  • sigma: A p×pp\times p covariance matrix if ncov=1, or a list of g covariance matrices with dimension p×p×gp\times p \times g if ncov=2.
  • ncov: Options of structure of sigma matrix; the default value is 2; ncov = 1 for a common covariance matrix; ncov = 2 for the unequal covariance/scale matrices.

Returns

  • cluster: A vector of the class membership.

Details

The posterior probability can be expressed as

τi(yj;θ)=Prob{zij=1yj}=πiϕ(yj;μi,Σi)h=1gπhϕ(yj;μh,Σh), \tau_i(y_j;\theta)=Prob\{z_{ij}=1|y_j\}=\frac{\pi_i\phi(y_j;\mu_i,\Sigma_i)}{\sum_{h=1}^g\pi_h\phi(y_j;\mu_h,\Sigma_h) },

where ϕ\phi is a normal probability function with mean μi\mu_i and covariance matrix Σi\Sigma_i, and zijz_{ij} is is a zero-one indicator variable denoting the class of origin. The Bayes' Classifier of allocation assigns an entity with feature vector yjy_j to Class CkC_k if

k=argmaxiτi(yj;θ). k= arg max_i \tau_i(y_j;\theta).

Examples

n<-150 pi<-c(0.25,0.25,0.25,0.25) sigma<-array(0,dim=c(3,3,4)) sigma[,,1]<-diag(1,3) sigma[,,2]<-diag(2,3) sigma[,,3]<-diag(3,3) sigma[,,4]<-diag(4,3) mu<-matrix(c(0.2,0.3,0.4,0.2,0.7,0.6,0.1,0.7,1.6,0.2,1.7,0.6),3,4) dat<-rmix(n=n,pi=pi,mu=mu,sigma=sigma,ncov=2) cluster<-Classifier_Bayes(dat=dat$Y,n=150,p=3,g=4,mu=mu,sigma=sigma,pi=pi,ncov=2)
  • Maintainer: Ziyang Lyu
  • License: GPL-3
  • Last published: 2022-10-18

Useful links