predict.MclustDA: Classify multivariate observations by Gaussian finite mixture...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/mclustda.R

Description

Classify multivariate observations based on Gaussian finite mixture models estimated by MclustDA.

Usage

1
2
  ## S3 method for class 'MclustDA'
predict(object, newdata, prop = object$prop, ...)

Arguments

object

an object of class 'MclustDA' resulting from a call to MclustDA.

newdata

a data frame or matrix giving the data. If missing the train data obtained from the call to MclustDA are classified.

prop

the class proportions or prior class probabilities to belong to each class; by default, this is set at the class proportions in the training data.

...

further arguments passed to or from other methods.

Value

Returns a list of with the following components:

classification

a factor of predicted class labels for newdata.

z

a matrix whose [i,k]th entry is the probability that observation i in newdata belongs to the kth class.

Author(s)

Luca Scrucca

See Also

MclustDA.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
odd <- seq(from = 1, to = nrow(iris), by = 2)
even <- odd + 1
X.train <- iris[odd,-5]
Class.train <- iris[odd,5]
X.test <- iris[even,-5]
Class.test <- iris[even,5]

irisMclustDA <- MclustDA(X.train, Class.train)

predTrain <- predict(irisMclustDA)
predTrain
predTest <- predict(irisMclustDA, X.test)
predTest

## End(Not run)

Example output

Package 'mclust' version 5.4.1
Type 'citation("mclust")' for citing this R package in publications.
$classification
 [1] setosa     setosa     setosa     setosa     setosa     setosa    
 [7] setosa     setosa     setosa     setosa     setosa     setosa    
[13] setosa     setosa     setosa     setosa     setosa     setosa    
[19] setosa     setosa     setosa     setosa     setosa     setosa    
[25] setosa     versicolor versicolor versicolor versicolor versicolor
[31] versicolor versicolor versicolor versicolor versicolor versicolor
[37] versicolor versicolor versicolor versicolor versicolor versicolor
[43] versicolor versicolor versicolor versicolor versicolor versicolor
[49] versicolor versicolor virginica  virginica  virginica  virginica 
[55] virginica  virginica  virginica  virginica  virginica  virginica 
[61] virginica  virginica  virginica  virginica  virginica  virginica 
[67] virginica  virginica  virginica  virginica  virginica  virginica 
[73] virginica  virginica  virginica 
Levels: setosa versicolor virginica

$z
           setosa   versicolor    virginica
1    1.000000e+00 2.886459e-77 2.855419e-40
3    1.000000e+00 1.978416e-81 4.191116e-35
5    1.000000e+00 4.745047e-80 1.628560e-40
7    1.000000e+00 8.144944e-78 2.283033e-32
9    1.000000e+00 1.065919e-80 1.393967e-28
11   1.000000e+00 4.316603e-74 1.537964e-44
13   1.000000e+00 6.488706e-80 1.532678e-33
15   1.000000e+00 6.307901e-85 3.948914e-57
17   1.000000e+00 3.942854e-79 5.020818e-46
19   1.000000e+00 9.176222e-64 5.203283e-44
21   1.000000e+00 1.605478e-65 1.196276e-37
23   1.000000e+00 4.889354e-94 1.314152e-40
25   1.000000e+00 2.600808e-76 1.573182e-29
27   1.000000e+00 2.292257e-64 8.638535e-32
29   1.000000e+00 9.219406e-75 4.499233e-40
31   1.000000e+00 3.173517e-73 7.092360e-31
33   1.000000e+00 1.087970e-87 4.865629e-49
35   1.000000e+00 4.580298e-73 3.076358e-33
37   1.000000e+00 3.919175e-77 3.741457e-46
39   1.000000e+00 1.032017e-83 9.058168e-31
41   1.000000e+00 9.234429e-78 4.556033e-39
43   1.000000e+00 2.000396e-86 3.085854e-32
45   1.000000e+00 5.591335e-62 2.659050e-33
47   1.000000e+00 3.671574e-78 1.555004e-41
49   1.000000e+00 2.649624e-75 1.601636e-43
51   1.127998e-98 9.999997e-01 2.560888e-07
53  1.086396e-112 9.999342e-01 6.576818e-05
55  9.938179e-104 9.994730e-01 5.269925e-04
57  9.802943e-112 9.993941e-01 6.059479e-04
59   3.852160e-87 9.999277e-01 7.232676e-05
61   7.074660e-49 9.999812e-01 1.877614e-05
63   7.018070e-58 9.999969e-01 3.070890e-06
65   1.107108e-60 9.999974e-01 2.597179e-06
67   2.582376e-96 9.797356e-01 2.026441e-02
69  1.115375e-104 9.966115e-01 3.388494e-03
71  8.186617e-133 7.001111e-01 2.998889e-01
73  2.554943e-113 7.596093e-01 2.403907e-01
75   2.428854e-78 9.999863e-01 1.373535e-05
77  7.499974e-103 9.998971e-01 1.029446e-04
79   3.608160e-98 9.919923e-01 8.007722e-03
81   9.039535e-57 9.999942e-01 5.827206e-06
83   2.397775e-62 9.999942e-01 5.846121e-06
85   5.622575e-96 9.809932e-01 1.900679e-02
87  8.514977e-106 9.999604e-01 3.964607e-05
89   1.231647e-70 9.997794e-01 2.205827e-04
91   6.483744e-74 9.941609e-01 5.839062e-03
93   1.573054e-65 9.999797e-01 2.033119e-05
95   6.594133e-76 9.994260e-01 5.740226e-04
97   2.450647e-74 9.997943e-01 2.056631e-04
99   2.595835e-40 9.999999e-01 5.210133e-08
101 7.729031e-266 6.015295e-18 1.000000e+00
103 9.919427e-213 2.874490e-13 1.000000e+00
105 1.894623e-218 2.959173e-11 1.000000e+00
107 4.135594e-117 2.854541e-03 9.971455e-01
109 3.136751e-175 1.838891e-09 1.000000e+00
111 9.655725e-167 4.355094e-07 9.999996e-01
113 8.905189e-196 4.750698e-12 1.000000e+00
115 1.773405e-219 2.646848e-22 1.000000e+00
117 5.009080e-159 1.326186e-04 9.998674e-01
119 2.697956e-289 4.824647e-34 1.000000e+00
121 2.330370e-229 8.381126e-21 1.000000e+00
123 7.537934e-240 1.436330e-25 1.000000e+00
125 7.153954e-201 2.882592e-08 1.000000e+00
127 6.328807e-136 3.527802e-02 9.647220e-01
129 6.505182e-199 1.607667e-08 1.000000e+00
131 6.803255e-200 6.186049e-13 1.000000e+00
133 8.922304e-212 7.664385e-12 1.000000e+00
135 2.787881e-125 2.569215e-03 9.974308e-01
137 6.466090e-236 1.511198e-16 1.000000e+00
139 2.694087e-134 4.203971e-01 5.796029e-01
141 3.073503e-239 6.601367e-27 1.000000e+00
143 2.775054e-156 1.978341e-02 9.802166e-01
145 4.610118e-257 1.554188e-30 1.000000e+00
147 1.001946e-155 2.147622e-05 9.999785e-01
149 4.635544e-214 1.314436e-12 1.000000e+00

$classification
 [1] setosa     setosa     setosa     setosa     setosa     setosa    
 [7] setosa     setosa     setosa     setosa     setosa     setosa    
[13] setosa     setosa     setosa     setosa     setosa     setosa    
[19] setosa     setosa     setosa     setosa     setosa     setosa    
[25] setosa     versicolor versicolor versicolor versicolor versicolor
[31] versicolor versicolor versicolor versicolor versicolor versicolor
[37] versicolor versicolor versicolor versicolor versicolor virginica 
[43] versicolor versicolor versicolor versicolor versicolor versicolor
[49] versicolor versicolor virginica  virginica  virginica  virginica 
[55] virginica  virginica  virginica  virginica  virginica  virginica 
[61] virginica  virginica  virginica  virginica  virginica  virginica 
[67] virginica  virginica  virginica  virginica  virginica  virginica 
[73] virginica  virginica  virginica 
Levels: setosa versicolor virginica

$z
           setosa   versicolor    virginica
2    1.000000e+00 5.398387e-74 6.024432e-34
4    1.000000e+00 5.048374e-79 3.539600e-31
6    1.000000e+00 4.531621e-64 4.486910e-40
8    1.000000e+00 4.659070e-75 1.304672e-36
10   1.000000e+00 8.524095e-78 1.377628e-33
12   1.000000e+00 2.671143e-77 2.157318e-33
14   1.000000e+00 5.468308e-92 6.235495e-31
16   1.000000e+00 1.867766e-73 9.296774e-52
18   1.000000e+00 5.329407e-74 7.979520e-39
20   1.000000e+00 4.161574e-75 3.717735e-41
22   1.000000e+00 2.597863e-70 9.883579e-38
24   1.000000e+00 4.003054e-56 1.424814e-27
26   1.000000e+00 1.261173e-67 4.830908e-31
28   1.000000e+00 8.574537e-74 6.157347e-40
30   1.000000e+00 1.078754e-76 7.032498e-31
32   1.000000e+00 2.458429e-66 1.852108e-37
34   1.000000e+00 2.645867e-81 2.753607e-53
36   1.000000e+00 1.346310e-79 2.225550e-38
38   1.000000e+00 8.207481e-87 1.809865e-40
40   1.000000e+00 1.281009e-73 1.269180e-37
42   1.000000e+00 3.565410e-33 1.025293e-18
44   1.000000e+00 2.079851e-59 4.207923e-27
46   1.000000e+00 3.268567e-70 1.733930e-30
48   1.000000e+00 1.377433e-81 3.713219e-33
50   1.000000e+00 1.450945e-75 9.428277e-37
52   4.914217e-98 9.999415e-01 5.853946e-05
54   5.223413e-72 7.905193e-01 2.094807e-01
56   1.765763e-82 9.972268e-01 2.773196e-03
58   4.694511e-39 9.996831e-01 3.169337e-04
60   6.873643e-75 9.857170e-01 1.428302e-02
62   2.117045e-88 9.891644e-01 1.083564e-02
64   6.116870e-95 9.605219e-01 3.947810e-02
66   2.716308e-88 9.999966e-01 3.374253e-06
68   9.891625e-51 9.178475e-01 8.215251e-02
70   9.051831e-58 9.999873e-01 1.273837e-05
72   8.614531e-70 9.999088e-01 9.120120e-05
74   1.788588e-80 9.719510e-01 2.804901e-02
76   1.043452e-88 9.999903e-01 9.678504e-06
78  2.051271e-132 8.128341e-01 1.871659e-01
80   1.077276e-41 9.999996e-01 4.317814e-07
82   2.367363e-48 9.999944e-01 5.625268e-06
84  1.196696e-125 1.027824e-04 9.998972e-01
86  5.661476e-104 9.985290e-01 1.470990e-03
88   5.105124e-86 9.998117e-01 1.882978e-04
90   7.198997e-72 9.967818e-01 3.218195e-03
92   1.091627e-91 9.929847e-01 7.015328e-03
94   1.905280e-41 9.999927e-01 7.263313e-06
96   4.274129e-64 9.903921e-01 9.607924e-03
98   3.301157e-77 9.997952e-01 2.048073e-04
100  6.885668e-73 9.998857e-01 1.142923e-04
102 2.775054e-156 1.978341e-02 9.802166e-01
104 2.600039e-162 6.028928e-08 9.999999e-01
106 1.387823e-245 1.076622e-22 1.000000e+00
108 2.128600e-195 1.996792e-18 1.000000e+00
110 1.273039e-274 6.712419e-30 1.000000e+00
112 4.832806e-165 3.931236e-04 9.996069e-01
114 9.240129e-166 9.947021e-04 9.990053e-01
116 2.040122e-212 2.217548e-19 1.000000e+00
118 1.022074e-258 1.762138e-20 1.000000e+00
120 3.836300e-118 7.092946e-04 9.992907e-01
122 2.442234e-160 1.883190e-03 9.981168e-01
124 4.090790e-140 2.411288e-02 9.758871e-01
126 5.115674e-180 4.009479e-10 1.000000e+00
128 1.081475e-137 4.376791e-01 5.623209e-01
130 4.959339e-153 4.680445e-09 1.000000e+00
132 7.368198e-221 6.093665e-13 1.000000e+00
134 2.005139e-116 7.663238e-04 9.992337e-01
136 5.531776e-251 1.354545e-32 1.000000e+00
138 1.129945e-157 4.586680e-05 9.999541e-01
140 7.911420e-192 4.580013e-14 1.000000e+00
142 6.986901e-207 1.690742e-39 1.000000e+00
144 1.543229e-236 8.784206e-17 1.000000e+00
146 1.425915e-210 4.418074e-31 1.000000e+00
148 1.795699e-171 3.875920e-07 9.999996e-01
150 3.941008e-143 2.753005e-02 9.724700e-01

mclust documentation built on Nov. 20, 2020, 5:09 p.m.