cvpvs.knn: Cross-Validated P-Values (k Nearest Neighbors)

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

Description

Computes cross-validated nonparametric p-values for the potential class memberships of the training data. The p-values are based on 'k nearest neighbors'.

Usage

1
2
cvpvs.knn(X, Y, k = NULL, distance = c('euclidean', 'ddeuclidean',
          'mahalanobis'), cova = c('standard', 'M', 'sym'))

Arguments

X

matrix containing training observations, where each observation is a row vector.

Y

vector indicating the classes which the training observations belong to.

k

number of nearest neighbors. If k is a vector or k = NULL, the program searches for the best k. For more information see section 'Details'.

distance

the distance measure:
"euclidean": fixed Euclidean distance,
"ddeuclidean": data driven Euclidean distance (component-wise standardization),
"mahalanobis": Mahalanobis distance.

cova

estimator for the covariance matrix:
'standard': standard estimator,
'M': M-estimator,
'sym': symmetrized M-estimator.

Details

Computes cross-validated nonparametric p-values for the potential class memberships of the training data. Precisely, for each feature vector X[i,] and each class b the number PV[i,b] is a p-value for the null hypothesis that Y[i] = b.
This p-value is based on a permutation test applied to an estimated Bayesian likelihood ratio, using 'k nearest neighbors' with estimated prior probabilities N(b)/n. Here N(b) is the number of observations of class b and n is the total number of observations.
If k is a vector, the program searches for the best k. To determine the best k for the p-value PV[i,b], the class label of the training observation X[i,] is set temporarily to b and then for all training observations with Y[j] != b the proportion of the k nearest neighbors of X[j,] belonging to class b is computed. Then the k which minimizes the sum of these values is chosen.
If k = NULL, it is set to 2:ceiling(length(Y)/2).

Value

PV is a matrix containing the cross-validated p-values. Precisely, for each feature vector X[i,] and each class b the number PV[i,b] is a p-value for the null hypothesis that Y[i] = b.
If k is a vector or NULL, PV has an attribute "opt.k", which is a matrix and opt.k[i,b] is the best k for observation X[i,] and class b (see section 'Details'). opt.k[i,b] is used to compute the p-value for observation X[i,] and class b.

Author(s)

Niki Zumbrunnen niki.zumbrunnen@gmail.com
Lutz Dümbgen lutz.duembgen@stat.unibe.ch
www.imsv.unibe.ch/duembgen/index_ger.html

References

Zumbrunnen N. and Dümbgen L. (2017) pvclass: An R Package for p Values for Classification. Journal of Statistical Software 78(4), 1–19. doi:10.18637/jss.v078.i04

Dümbgen L., Igl B.-W. and Munk A. (2008) P-Values for Classification. Electronic Journal of Statistics 2, 468–493, available at http://dx.doi.org/10.1214/08-EJS245.

Zumbrunnen N. (2014) P-Values for Classification – Computational Aspects and Asymptotics. Ph.D. thesis, University of Bern, available at http://boris.unibe.ch/id/eprint/53585.

See Also

cvpvs, cvpvs.gaussian, cvpvs.wnn, cvpvs.logreg

Examples

1
2
3
4
X <- iris[, 1:4]
Y <- iris[, 5]

cvpvs.knn(X, Y, k = c(5, 10, 15))

Example output

           setosa versicolor  virginica
  [1,] 0.90000000 0.01960784 0.01960784
  [2,] 0.90000000 0.01960784 0.01960784
  [3,] 0.90000000 0.01960784 0.01960784
  [4,] 0.90000000 0.01960784 0.01960784
  [5,] 0.90000000 0.01960784 0.01960784
  [6,] 0.90000000 0.01960784 0.01960784
  [7,] 0.90000000 0.01960784 0.01960784
  [8,] 0.90000000 0.01960784 0.01960784
  [9,] 0.90000000 0.01960784 0.01960784
 [10,] 0.90000000 0.01960784 0.01960784
 [11,] 0.90000000 0.01960784 0.01960784
 [12,] 0.90000000 0.01960784 0.01960784
 [13,] 0.90000000 0.01960784 0.01960784
 [14,] 0.90000000 0.01960784 0.01960784
 [15,] 0.90000000 0.01960784 0.01960784
 [16,] 0.90000000 0.01960784 0.01960784
 [17,] 0.90000000 0.01960784 0.01960784
 [18,] 0.90000000 0.01960784 0.01960784
 [19,] 0.90000000 0.01960784 0.01960784
 [20,] 1.00000000 0.01960784 0.01960784
 [21,] 0.90000000 0.01960784 0.01960784
 [22,] 0.90000000 0.01960784 0.01960784
 [23,] 0.90000000 0.01960784 0.01960784
 [24,] 0.90000000 0.01960784 0.01960784
 [25,] 1.00000000 0.01960784 0.01960784
 [26,] 0.90000000 0.01960784 0.01960784
 [27,] 0.90000000 0.01960784 0.01960784
 [28,] 0.90000000 0.01960784 0.01960784
 [29,] 0.90000000 0.01960784 0.01960784
 [30,] 0.90000000 0.01960784 0.01960784
 [31,] 0.90000000 0.01960784 0.01960784
 [32,] 1.00000000 0.01960784 0.01960784
 [33,] 0.90000000 0.01960784 0.01960784
 [34,] 0.90000000 0.01960784 0.01960784
 [35,] 0.90000000 0.01960784 0.01960784
 [36,] 0.90000000 0.01960784 0.01960784
 [37,] 1.00000000 0.01960784 0.01960784
 [38,] 0.90000000 0.01960784 0.01960784
 [39,] 0.90000000 0.01960784 0.01960784
 [40,] 0.90000000 0.01960784 0.01960784
 [41,] 0.90000000 0.01960784 0.01960784
 [42,] 0.90000000 0.01960784 0.01960784
 [43,] 0.90000000 0.01960784 0.01960784
 [44,] 0.90000000 0.01960784 0.01960784
 [45,] 1.00000000 0.01960784 0.01960784
 [46,] 0.90000000 0.01960784 0.01960784
 [47,] 0.90000000 0.01960784 0.01960784
 [48,] 0.90000000 0.01960784 0.01960784
 [49,] 0.90000000 0.01960784 0.01960784
 [50,] 0.90000000 0.01960784 0.01960784
 [51,] 0.01960784 0.30000000 0.03921569
 [52,] 0.01960784 0.38000000 0.03921569
 [53,] 0.01960784 0.14000000 0.03921569
 [54,] 0.01960784 0.96000000 0.01960784
 [55,] 0.01960784 0.30000000 0.03921569
 [56,] 0.01960784 0.96000000 0.01960784
 [57,] 0.01960784 0.30000000 0.03921569
 [58,] 0.01960784 0.96000000 0.01960784
 [59,] 0.01960784 0.96000000 0.01960784
 [60,] 0.01960784 0.96000000 0.01960784
 [61,] 0.01960784 0.96000000 0.01960784
 [62,] 0.01960784 0.96000000 0.01960784
 [63,] 0.01960784 0.96000000 0.01960784
 [64,] 0.01960784 0.14000000 0.03921569
 [65,] 0.01960784 0.96000000 0.01960784
 [66,] 0.01960784 0.96000000 0.01960784
 [67,] 0.01960784 0.96000000 0.01960784
 [68,] 0.01960784 0.96000000 0.01960784
 [69,] 0.01960784 0.14000000 0.03921569
 [70,] 0.01960784 0.96000000 0.01960784
 [71,] 0.01960784 0.08000000 0.03921569
 [72,] 0.01960784 1.00000000 0.01960784
 [73,] 0.01960784 0.08000000 0.05882353
 [74,] 0.01960784 0.30000000 0.03921569
 [75,] 0.01960784 0.96000000 0.01960784
 [76,] 0.01960784 0.96000000 0.01960784
 [77,] 0.01960784 0.30000000 0.03921569
 [78,] 0.01960784 0.08000000 0.05882353
 [79,] 0.01960784 0.30000000 0.03921569
 [80,] 0.01960784 0.96000000 0.01960784
 [81,] 0.01960784 0.96000000 0.01960784
 [82,] 0.01960784 0.96000000 0.01960784
 [83,] 0.01960784 0.96000000 0.01960784
 [84,] 0.01960784 0.02000000 0.23529412
 [85,] 0.01960784 0.38000000 0.01960784
 [86,] 0.01960784 0.30000000 0.03921569
 [87,] 0.01960784 0.38000000 0.01960784
 [88,] 0.01960784 0.38000000 0.01960784
 [89,] 0.01960784 0.96000000 0.01960784
 [90,] 0.01960784 0.96000000 0.01960784
 [91,] 0.01960784 0.96000000 0.01960784
 [92,] 0.01960784 0.16000000 0.03921569
 [93,] 0.01960784 0.96000000 0.01960784
 [94,] 0.01960784 0.96000000 0.01960784
 [95,] 0.01960784 0.96000000 0.01960784
 [96,] 0.01960784 0.96000000 0.01960784
 [97,] 0.01960784 0.96000000 0.01960784
 [98,] 0.01960784 1.00000000 0.01960784
 [99,] 0.01960784 0.96000000 0.01960784
[100,] 0.01960784 0.96000000 0.01960784
[101,] 0.01960784 0.01960784 1.00000000
[102,] 0.01960784 0.01960784 0.32000000
[103,] 0.01960784 0.01960784 1.00000000
[104,] 0.01960784 0.01960784 0.44000000
[105,] 0.01960784 0.01960784 1.00000000
[106,] 0.01960784 0.01960784 1.00000000
[107,] 0.01960784 0.31372549 0.02000000
[108,] 0.01960784 0.01960784 1.00000000
[109,] 0.01960784 0.01960784 1.00000000
[110,] 0.01960784 0.01960784 1.00000000
[111,] 0.01960784 0.03921569 0.32000000
[112,] 0.01960784 0.01960784 0.32000000
[113,] 0.01960784 0.01960784 1.00000000
[114,] 0.01960784 0.03921569 0.20000000
[115,] 0.01960784 0.01960784 0.44000000
[116,] 0.01960784 0.01960784 1.00000000
[117,] 0.01960784 0.01960784 0.44000000
[118,] 0.01960784 0.01960784 1.00000000
[119,] 0.01960784 0.01960784 1.00000000
[120,] 0.01960784 0.03921569 0.12000000
[121,] 0.01960784 0.01960784 1.00000000
[122,] 0.01960784 0.03921569 0.14000000
[123,] 0.01960784 0.01960784 1.00000000
[124,] 0.01960784 0.03921569 0.16000000
[125,] 0.01960784 0.01960784 1.00000000
[126,] 0.01960784 0.01960784 1.00000000
[127,] 0.01960784 0.03921569 0.12000000
[128,] 0.01960784 0.03921569 0.12000000
[129,] 0.01960784 0.01960784 1.00000000
[130,] 0.01960784 0.01960784 1.00000000
[131,] 0.01960784 0.01960784 1.00000000
[132,] 0.01960784 0.01960784 1.00000000
[133,] 0.01960784 0.01960784 1.00000000
[134,] 0.01960784 0.03921569 0.12000000
[135,] 0.01960784 0.03921569 0.32000000
[136,] 0.01960784 0.01960784 1.00000000
[137,] 0.01960784 0.01960784 1.00000000
[138,] 0.01960784 0.01960784 0.44000000
[139,] 0.01960784 0.07843137 0.04000000
[140,] 0.01960784 0.01960784 1.00000000
[141,] 0.01960784 0.01960784 1.00000000
[142,] 0.01960784 0.01960784 0.44000000
[143,] 0.01960784 0.01960784 0.32000000
[144,] 0.01960784 0.01960784 1.00000000
[145,] 0.01960784 0.01960784 1.00000000
[146,] 0.01960784 0.01960784 1.00000000
[147,] 0.01960784 0.01960784 0.32000000
[148,] 0.01960784 0.01960784 0.44000000
[149,] 0.01960784 0.01960784 1.00000000
[150,] 0.01960784 0.03921569 0.20000000
attr(,"opt.k")
       [,1] [,2] [,3]
  [1,]   15   15   15
  [2,]   15   15   15
  [3,]   15   15   15
  [4,]   15   15   15
  [5,]   15   15   15
  [6,]   15   15   15
  [7,]   15   15   15
  [8,]   15   15   15
  [9,]   15   15   15
 [10,]   15   15   15
 [11,]   15   15   15
 [12,]   15   15   15
 [13,]   15   15   15
 [14,]   15   15   15
 [15,]   15   15   15
 [16,]   15   15   15
 [17,]   15   15   15
 [18,]   15   15   15
 [19,]   15   15   15
 [20,]   15   15   15
 [21,]   15   15   15
 [22,]   15   15   15
 [23,]   15   15   15
 [24,]   15   15   15
 [25,]   15   15   15
 [26,]   15   15   15
 [27,]   15   15   15
 [28,]   15   15   15
 [29,]   15   15   15
 [30,]   15   15   15
 [31,]   15   15   15
 [32,]   15   15   15
 [33,]   15   15   15
 [34,]   15   15   15
 [35,]   15   15   15
 [36,]   15   15   15
 [37,]   15   15   15
 [38,]   15   15   15
 [39,]   15   15   15
 [40,]   15   15   15
 [41,]   15   15   15
 [42,]   15   15   15
 [43,]   15   15   15
 [44,]   15   15   15
 [45,]   15   15   15
 [46,]   15   15   15
 [47,]   15   15   15
 [48,]   15   15   15
 [49,]   15   15   15
 [50,]   15   15   15
 [51,]   15   15   15
 [52,]   15   15   15
 [53,]   15   15   15
 [54,]   15   15   15
 [55,]   15   15   15
 [56,]   15   15   15
 [57,]   15   15   15
 [58,]   15   15   15
 [59,]   15   15   15
 [60,]   15   15   15
 [61,]   15   15   15
 [62,]   15   15   15
 [63,]   15   15   15
 [64,]   15   15   15
 [65,]   15   15   15
 [66,]   15   15   15
 [67,]   15   15   15
 [68,]   15   15   15
 [69,]   15   15   15
 [70,]   15   15   15
 [71,]   15   15   15
 [72,]   15   15   15
 [73,]   15   15   15
 [74,]   15   15   15
 [75,]   15   15   15
 [76,]   15   15   15
 [77,]   15   15   15
 [78,]   15   15   15
 [79,]   15   15   15
 [80,]   15   15   15
 [81,]   15   15   15
 [82,]   15   15   15
 [83,]   15   15   15
 [84,]   15   15   15
 [85,]   15   15   15
 [86,]   15   15   15
 [87,]   15   15   15
 [88,]   15   15   15
 [89,]   15   15   15
 [90,]   15   15   15
 [91,]   15   15   15
 [92,]   15   15   15
 [93,]   15   15   15
 [94,]   15   15   15
 [95,]   15   15   15
 [96,]   15   15   15
 [97,]   15   15   15
 [98,]   15   15   15
 [99,]   15   15   15
[100,]   15   15   15
[101,]   15   15   15
[102,]   15   15   15
[103,]   15   15   15
[104,]   15   15   15
[105,]   15   15   15
[106,]   15   15   15
[107,]   15   15   15
[108,]   15   15   15
[109,]   15   15   15
[110,]   15   15   15
[111,]   15   15   15
[112,]   15   15   15
[113,]   15   15   15
[114,]   15   15   15
[115,]   15   15   15
[116,]   15   15   15
[117,]   15   15   15
[118,]   15   15   15
[119,]   15   15   15
[120,]   15   15   15
[121,]   15   15   15
[122,]   15   15   15
[123,]   15   15   15
[124,]   15   15   15
[125,]   15   15   15
[126,]   15   15   15
[127,]   15   15   15
[128,]   15   15   15
[129,]   15   15   15
[130,]   15   15   15
[131,]   15   15   15
[132,]   15   15   15
[133,]   15   15   15
[134,]   15   15   15
[135,]   15   15   15
[136,]   15   15   15
[137,]   15   15   15
[138,]   15   15   15
[139,]   15   15   15
[140,]   15   15   15
[141,]   15   15   15
[142,]   15   15   15
[143,]   15   15   15
[144,]   15   15   15
[145,]   15   15   15
[146,]   15   15   15
[147,]   15   15   15
[148,]   15   15   15
[149,]   15   15   15
[150,]   15   15   15

pvclass documentation built on May 1, 2019, 10:17 p.m.