gx.mvalloc: Function for Allocation on the basis of Multivariate Data

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/gx.mvalloc.R

Description

Function to allocate individuals (observations, cases or samples) into one of multiple reference groups (populations) on the basis of their Mahalanobis distances. If an individual's predicted probability of group membership (typicality) falls below a user defined ‘cut-off’, pcrit, the individual is allocated to an ‘outlier bin’.

Usage

1
gx.mvalloc(pcrit = 0.05, x, ...)

Arguments

pcrit

the critical cut-off probability for group membership below which an individual will be classified as an ‘outlier’. By default the critical probability of group membership is set to pcrit = 0.05.

x

a n by p matrix containing the n individuals, with p variables determined on each, to be allocated, see Details below.

...

a list of objects saved from any of functions gx.md.gait, gx.md.gait.closed, gx.mva, gx.robmva or
gx.robmva.closed, containing the vectors of means and covariance matrices for the ‘reference’ groups into which the individuals are to be classified.

Details

It is imperative that the data matrix x contains no special codes and all records (individuals) with NAs have been removed, see Notes below. It is also imperative that the variables in the reference groups and in the matrix x of individuals to be classified are identical and in the same order.

The allocations are made on the assumption that the covariance structures are inhomogeneous, i.e. that the population hyperellipsoids are of different size, shape and orientation in p-space.

Value

The following are returned as an object to be saved for display with gx.mvalloc.print:

groups

a list of the names of the kk reference groups.

kk

the number of reference groups passed to the function.

n

the number of individuals (observations, cases or samples) allocated.

p

the number of variables in the reference and allocated data.

pcrit

the critical cut-off probability for reference group membership.

pgm

a vector of kk predicted probabilities of reference group memberships.

xalloc

the reference group, 1:kk, that the individual was allocated into. All outliers, i.e. all pgm(1:kk) < crit are allocated to group zero, 0. Therefore xalloc will be in the range of 0:kk.

Note

Any less than detection limit values represented by negative values, or zeros or other numeric codes representing blanks in the data, must be removed from the matrix x prior to executing this function, see ltdl.fix.df. Additionally, any rows in the data matrix with NAs also must have been removed prior to computations, see na.omit and remove.na.

It is recommended that when applying this procedure to compositional data an ilr transformation be undertaken, this can be done at execution time. This implies that the reference group means and covariance matrices must have also been estimated following an ilr transformation.

Author(s)

Robert G. Garrett

References

Garrett, R.G., 1990. A robust multivariate allocation procedure with applications to geochemical data. In Proc. Colloquium on Statistical Applications in the Earth Sciences (Eds F.P. Agterberg & G.F. Bonham-Carter). Geological Survey of Canada Paper 89-9, pp. 309-318.

Reimann, C., Filzmoser, P., Garrett, R. and Dutter, R., 2008. Statistical Data Analysis Explained: Applied Environmental Statistics with R. John Wiley & Sons, Ltd., 362 p.

See Also

gx.md.gait, gx.md.gait.closed, gx.mva, gx.robmva, gx.robmva.closed, gx.mvalloc.print, ltdl.fix.df, remove.na, na.omit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## Generate three groups of synthetic bivariate normal data
grp1 <- mvrnorm(100, mu = c(40, 30), Sigma = matrix(c(6, 3, 3, 2), 2, 2))
grp1 <- cbind(grp1, rep(1, 100))
grp2 <- mvrnorm(100 ,mu = c(50, 40), Sigma = matrix(c(4, -3, -3, 5), 2, 2))
grp2 <- cbind(grp2, rep(2, 100))
grp3 <- mvrnorm(100 ,mu = c(30, 45), Sigma = matrix(c(6, 4, 4, 5), 2, 2))
grp3 <- cbind(grp3 ,rep(3, 100))
## Generate a set of six (6) outliers
anom <- matrix(c(35, 40, 25, 60, 25, 60, 35, 40, 25, 60, 60, 25),6, 2)
anom <- cbind(anom, rep(4, 6))
## Bind the test data sets together and display the test data 
test.mvalloc.mat <- rbind(grp1, grp2, grp3, anom)
test.mvalloc <- as.data.frame(test.mvalloc.mat)
dimnames(test.mvalloc)[[2]] <- c("x","y","grp")
attach(test.mvalloc)
xyplot.tags(x, y, grp, cex = 0.75)

## Generate robust reference groups 
test.save.grp1 <- gx.md.gait(grp1[, -3], mcdstart = TRUE)
test.save.grp2 <- gx.md.gait(grp2[, -3], mcdstart = TRUE)
test.save.grp3 <- gx.md.gait(grp3[, -3], mcdstart = TRUE)

## Allocate the synthetic data into the three reference groups
test.save.mvalloc <- gx.mvalloc(pcrit = 0.05, test.mvalloc.mat[,-3],
test.save.grp1, test.save.grp2, test.save.grp3)
## Display the results of the allocation
xyplot.tags(x, y, test.save.mvalloc$xalloc, cex = 0.75)
gx.mvalloc.print(test.save.mvalloc)

## Save the allocation as a csv file
gx.mvalloc.print(test.save.mvalloc, ifprint = FALSE,
file = " ")

## Clean-up and detach synthetic test data
rm(grp1)
rm(grp2)
rm(grp3)
rm(anom)
rm(test.mvalloc)
rm(test.save.grp1)
rm(test.save.grp2)
rm(test.save.grp3)
rm(test.save.mvalloc)
detach(test.mvalloc)

Example output

Loading required package: MASS
Loading required package: fastICA
  k = 3 	 px = 2 	 nx = 306 
  Reference Groups:
     1    grp1[, -3] 
     2    grp2[, -3] 
     3    grp3[, -3] 
  pcrit was set to: 0.05 

  Row    Group  Probabilities of Group Membership:

   2      0    0.008 0 0 
   27      0    0.0336 0 0 
   30      0    0.0211 0 0 
   95      0    0.0291 0 0 
   132      0    0 0.0331 0 
   142      0    0 0.0226 0 
   178      0    0 0.0166 0 
   196      0    0 0.0346 0 
   211      0    0 0 0.0403 
   223      0    0 0 0.0253 
   225      0    0 0 0.0089 
   233      0    0 0 0.0485 
   236      0    0 0 9e-04 
   237      0    0 0 0.0108 
   238      0    0 0 0.0352 
   246      0    0 0 0.0262 
   250      0    0 0 0.0366 
   272      0    0 0 0.0374 
   286      0    0 0 0.0374 
   290      0    0 0 0.0378 
   301      0    0 0 0 
   302      0    0 0 0 
   303      0    0 0 0 
   304      0    0 0 0 
   305      0    0 0 0 
   306      0    0 0 0 

  Reference Groups:
     1    grp1[, -3] 
     2    grp2[, -3] 
     3    grp3[, -3] 
  pcrit was set to: 0.05 

  Saved table will be in:
   /work/tmp/test.save.mvalloc_mvalloc.csv 

rgr documentation built on May 2, 2019, 6:09 a.m.

Related to gx.mvalloc in rgr...