predict.rda: Regularized Discriminant Analysis (RDA)

Description Usage Arguments Value Author(s) See Also Examples

View source: R/rda.R

Description

Classifies new observations using parameters determined by the rda-function.

Usage

1
2
3
## S3 method for class 'rda'
predict(object, newdata, posterior = TRUE, 
    aslist = TRUE, ...)

Arguments

object

Object of class rda.

newdata

Data frame (or matrix) of cases to be classified.

posterior

Logical; indicates whether a matrix of posterior probabilites over all classes for each observation shall be returned in addition to classifications.

aslist

Logical; if TRUE, a list containing classifications and posterior probabilities is returned, otherwise a vector with an attribute ‘posterior’.

...

currently unused

Value

Depends on the value of argument ‘aslist’:

Either a vector (of class factor) of classifications that (optionally) has an attribute ‘posterior’ containing the posterior probability matrix, or

A list with elements ‘class’ and ‘posterior’.

Author(s)

Christian Röver, [email protected]

See Also

rda

Examples

1
2
3
data(iris)
x <- rda(Species ~ ., data = iris, gamma = 0.05, lambda = 0.2)
predict(x, iris[, 1:4])

Example output

Loading required package: MASS
$class
  [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     setosa     setosa     setosa     setosa     setosa    
 [31] setosa     setosa     setosa     setosa     setosa     setosa    
 [37] setosa     setosa     setosa     setosa     setosa     setosa    
 [43] setosa     setosa     setosa     setosa     setosa     setosa    
 [49] setosa     setosa     versicolor versicolor versicolor versicolor
 [55] versicolor versicolor versicolor versicolor versicolor versicolor
 [61] versicolor versicolor versicolor versicolor versicolor versicolor
 [67] versicolor versicolor versicolor versicolor virginica  versicolor
 [73] versicolor versicolor versicolor versicolor versicolor versicolor
 [79] versicolor versicolor versicolor versicolor versicolor virginica 
 [85] versicolor versicolor versicolor versicolor versicolor versicolor
 [91] versicolor versicolor versicolor versicolor versicolor versicolor
 [97] versicolor versicolor versicolor versicolor virginica  virginica 
[103] virginica  virginica  virginica  virginica  virginica  virginica 
[109] virginica  virginica  virginica  virginica  virginica  virginica 
[115] virginica  virginica  virginica  virginica  virginica  virginica 
[121] virginica  virginica  virginica  virginica  virginica  virginica 
[127] virginica  virginica  virginica  virginica  virginica  virginica 
[133] virginica  versicolor virginica  virginica  virginica  virginica 
[139] virginica  virginica  virginica  virginica  virginica  virginica 
[145] virginica  virginica  virginica  virginica  virginica  virginica 
Levels: setosa versicolor virginica

$posterior
              setosa   versicolor    virginica
  [1,]  1.000000e+00 3.374052e-22 2.238500e-36
  [2,]  1.000000e+00 1.004371e-16 4.882247e-31
  [3,]  1.000000e+00 6.190112e-19 1.536447e-32
  [4,]  1.000000e+00 3.894442e-16 1.105635e-28
  [5,]  1.000000e+00 5.871159e-23 1.573698e-36
  [6,]  1.000000e+00 1.690683e-22 1.756676e-35
  [7,]  1.000000e+00 1.130283e-18 6.200653e-31
  [8,]  1.000000e+00 4.662823e-20 1.320080e-33
  [9,]  1.000000e+00 1.136032e-14 3.399897e-27
 [10,]  1.000000e+00 1.004444e-17 1.738683e-31
 [11,]  1.000000e+00 2.874473e-24 9.290293e-39
 [12,]  1.000000e+00 1.339773e-18 6.198687e-31
 [13,]  1.000000e+00 2.357871e-17 2.207062e-31
 [14,]  1.000000e+00 2.935151e-18 1.282383e-31
 [15,]  1.000000e+00 2.303342e-31 4.377680e-48
 [16,]  1.000000e+00 2.894819e-31 5.478051e-45
 [17,]  1.000000e+00 3.090004e-26 1.114835e-40
 [18,]  1.000000e+00 3.083450e-21 3.027448e-35
 [19,]  1.000000e+00 3.083932e-23 1.074773e-37
 [20,]  1.000000e+00 1.842475e-23 1.842665e-36
 [21,]  1.000000e+00 3.931588e-19 2.711184e-33
 [22,]  1.000000e+00 2.366874e-21 2.389675e-34
 [23,]  1.000000e+00 1.104632e-24 3.244097e-38
 [24,]  1.000000e+00 1.579444e-14 3.636831e-27
 [25,]  1.000000e+00 1.008788e-15 1.110720e-26
 [26,]  1.000000e+00 2.847415e-15 4.595319e-29
 [27,]  1.000000e+00 3.454515e-17 5.558366e-30
 [28,]  1.000000e+00 1.358255e-21 1.008652e-35
 [29,]  1.000000e+00 2.253937e-21 3.774306e-36
 [30,]  1.000000e+00 1.870069e-16 8.963785e-29
 [31,]  1.000000e+00 8.296001e-16 1.121689e-28
 [32,]  1.000000e+00 4.886127e-19 1.023649e-33
 [33,]  1.000000e+00 3.528712e-29 7.213749e-42
 [34,]  1.000000e+00 2.544073e-31 1.982600e-45
 [35,]  1.000000e+00 7.037118e-17 1.392365e-30
 [36,]  1.000000e+00 2.060715e-20 1.238251e-35
 [37,]  1.000000e+00 7.434255e-24 4.497988e-40
 [38,]  1.000000e+00 1.369176e-23 8.458276e-37
 [39,]  1.000000e+00 2.836429e-16 4.776307e-29
 [40,]  1.000000e+00 2.623165e-20 3.029926e-34
 [41,]  1.000000e+00 8.779641e-22 8.758384e-36
 [42,]  1.000000e+00 6.350675e-10 1.066769e-23
 [43,]  1.000000e+00 5.498786e-18 2.083363e-30
 [44,]  1.000000e+00 6.940621e-16 8.957600e-28
 [45,]  1.000000e+00 2.325599e-18 1.157260e-29
 [46,]  1.000000e+00 1.197851e-15 2.388076e-29
 [47,]  1.000000e+00 1.431360e-23 3.212755e-36
 [48,]  1.000000e+00 7.523665e-18 1.200723e-30
 [49,]  1.000000e+00 5.134773e-24 4.102791e-38
 [50,]  1.000000e+00 6.888647e-20 4.559252e-34
 [51,]  7.619881e-43 9.997318e-01 2.682240e-04
 [52,]  1.450095e-40 9.987631e-01 1.236947e-03
 [53,]  2.362227e-49 9.939245e-01 6.075452e-03
 [54,]  7.082365e-34 9.977098e-01 2.290230e-03
 [55,]  4.359412e-45 9.943165e-01 5.683455e-03
 [56,]  1.778753e-40 9.881763e-01 1.182373e-02
 [57,]  6.166469e-46 9.852686e-01 1.473138e-02
 [58,]  6.769142e-19 9.999904e-01 9.574436e-06
 [59,]  2.275620e-41 9.993911e-01 6.089421e-04
 [60,]  2.235754e-32 9.952018e-01 4.798210e-03
 [61,]  1.443308e-23 9.999368e-01 6.322143e-05
 [62,]  1.345399e-36 9.978208e-01 2.179167e-03
 [63,]  1.148363e-30 9.999720e-01 2.799999e-05
 [64,]  4.583235e-45 9.818697e-01 1.813034e-02
 [65,]  6.790245e-24 9.999782e-01 2.175359e-05
 [66,]  1.568749e-37 9.999175e-01 8.250134e-05
 [67,]  4.613236e-43 9.572172e-01 4.278279e-02
 [68,]  3.943309e-29 9.999216e-01 7.842504e-05
 [69,]  1.924596e-46 9.190936e-01 8.090643e-02
 [70,]  2.571732e-28 9.999364e-01 6.359993e-05
 [71,]  1.440634e-53 3.889136e-01 6.110864e-01
 [72,]  8.517216e-31 9.999635e-01 3.649101e-05
 [73,]  5.534533e-53 7.016668e-01 2.983332e-01
 [74,]  1.546270e-42 9.883513e-01 1.164871e-02
 [75,]  1.570656e-35 9.999116e-01 8.844410e-05
 [76,]  2.940986e-38 9.998402e-01 1.598288e-04
 [77,]  9.437226e-48 9.954649e-01 4.535141e-03
 [78,]  1.265592e-55 8.053851e-01 1.946149e-01
 [79,]  8.639237e-43 9.868730e-01 1.312703e-02
 [80,]  6.825222e-20 9.999996e-01 4.317328e-07
 [81,]  2.903450e-27 9.999463e-01 5.372001e-05
 [82,]  2.365955e-24 9.999889e-01 1.114212e-05
 [83,]  2.104365e-28 9.999668e-01 3.318261e-05
 [84,]  1.091105e-58 1.588245e-01 8.411755e-01
 [85,]  1.270751e-43 9.143387e-01 8.566131e-02
 [86,]  7.415916e-42 9.897451e-01 1.025491e-02
 [87,]  3.875702e-45 9.976641e-01 2.335883e-03
 [88,]  3.001787e-41 9.980155e-01 1.984518e-03
 [89,]  4.860773e-32 9.994961e-01 5.038800e-04
 [90,]  6.146972e-33 9.987520e-01 1.248037e-03
 [91,]  2.941524e-38 9.879763e-01 1.202369e-02
 [92,]  1.798928e-42 9.939163e-01 6.083657e-03
 [93,]  1.005014e-30 9.999051e-01 9.492713e-05
 [94,]  3.131376e-19 9.999936e-01 6.397911e-06
 [95,]  2.030346e-35 9.979250e-01 2.075045e-03
 [96,]  3.911021e-32 9.996288e-01 3.711689e-04
 [97,]  3.101508e-34 9.991648e-01 8.351581e-04
 [98,]  1.414739e-35 9.997877e-01 2.122658e-04
 [99,]  4.089675e-15 9.999990e-01 1.022588e-06
[100,]  6.141397e-33 9.995101e-01 4.898967e-04
[101,] 2.767363e-102 2.631718e-07 9.999997e-01
[102,]  3.941395e-66 3.121039e-03 9.968790e-01
[103,]  6.628994e-88 1.897266e-04 9.998103e-01
[104,]  4.052230e-74 5.017620e-03 9.949824e-01
[105,]  1.071933e-88 2.670125e-05 9.999733e-01
[106,] 1.224547e-108 2.475180e-06 9.999975e-01
[107,]  1.118573e-51 2.454419e-02 9.754558e-01
[108,]  1.668595e-93 7.781144e-05 9.999222e-01
[109,]  9.528132e-82 2.810513e-04 9.997189e-01
[110,] 9.200983e-101 3.136694e-06 9.999969e-01
[111,]  6.946121e-64 3.794630e-02 9.620537e-01
[112,]  1.006358e-69 4.899731e-03 9.951003e-01
[113,]  1.828255e-77 8.950302e-04 9.991050e-01
[114,]  9.482035e-68 2.041397e-04 9.997959e-01
[115,]  9.921376e-81 9.027461e-08 9.999999e-01
[116,]  5.510354e-78 3.807128e-05 9.999619e-01
[117,]  2.078624e-70 2.502491e-02 9.749751e-01
[118,] 8.851902e-108 6.271618e-05 9.999373e-01
[119,] 2.612860e-126 1.770041e-09 1.000000e+00
[120,]  3.203035e-57 8.694135e-02 9.130586e-01
[121,]  6.147472e-87 3.578267e-05 9.999642e-01
[122,]  2.429092e-64 1.106121e-03 9.988939e-01
[123,] 2.549210e-111 5.736816e-07 9.999994e-01
[124,]  9.950080e-58 1.384121e-01 8.615879e-01
[125,]  6.997680e-81 1.460068e-03 9.985399e-01
[126,]  4.013168e-82 5.170859e-03 9.948291e-01
[127,]  5.464735e-55 2.421162e-01 7.578838e-01
[128,]  2.452232e-56 2.505623e-01 7.494377e-01
[129,]  5.319408e-82 8.390581e-05 9.999161e-01
[130,]  5.037102e-74 2.845196e-02 9.715480e-01
[131,]  1.927968e-90 1.967398e-04 9.998033e-01
[132,]  3.298328e-93 2.730162e-03 9.972698e-01
[133,]  8.027852e-85 1.392729e-05 9.999861e-01
[134,]  9.199376e-56 5.793808e-01 4.206192e-01
[135,]  1.142992e-68 3.106159e-03 9.968938e-01
[136,]  5.007892e-99 5.722710e-06 9.999943e-01
[137,]  6.409086e-88 6.838325e-06 9.999932e-01
[138,]  5.647382e-70 3.099884e-02 9.690012e-01
[139,]  2.573895e-54 2.870968e-01 7.129032e-01
[140,]  4.968089e-74 2.953225e-03 9.970468e-01
[141,]  1.512354e-88 1.987583e-06 9.999980e-01
[142,]  1.020049e-72 8.544253e-05 9.999146e-01
[143,]  3.941395e-66 3.121039e-03 9.968790e-01
[144,]  1.752433e-92 1.608792e-05 9.999839e-01
[145,]  3.621681e-93 5.354998e-07 9.999995e-01
[146,]  3.774501e-76 2.589253e-05 9.999741e-01
[147,]  7.441418e-64 6.323582e-03 9.936764e-01
[148,]  1.123578e-67 9.926968e-03 9.900730e-01
[149,]  5.416835e-80 6.750667e-05 9.999325e-01
[150,]  9.969191e-62 6.324651e-02 9.367535e-01

klaR documentation built on March 19, 2018, 5:03 p.m.