4
$\begingroup$

I am trying to determine significant differences between groups of data using a k-nearest neighbor randomization test in R. This test basically looks for similarity amongst homogenous groups and separates them out using random clustering. In the literature, this test is called a "K-nearest neighbor (kNN) randomization test," however, I'm not certain if it called by other names elsewhere.

For my specific data, I have isotopic ratios given for various prey items. I have already grouped together ecologically similar prey item types, and now want to see if those groups differ from one another in their isotopic signature. This is where the kNN test would come in.

Thanks for all of your answers - I'm new to this site, so I'll address your inquiries as applicable in the comments section.

$\endgroup$
6
  • 2
    $\begingroup$ kmeans() (you can find it by typping ?? folowed by the name of what you want as in ??kmean) $\endgroup$
    – user603
    Sep 21, 2010 at 17:36
  • $\begingroup$ Another useful way to find functions is the apropos function. $\endgroup$
    – Shane
    Sep 21, 2010 at 17:38
  • 3
    $\begingroup$ @kwak: why not post your comment as an answer? $\endgroup$
    – Shane
    Sep 21, 2010 at 17:38
  • $\begingroup$ @all:> i propose to change the title of the post, so as to make it easier to find for someone looking for the R implementation of other procedures (beside k-means). $\endgroup$
    – user603
    Sep 21, 2010 at 21:11
  • $\begingroup$ @kwak Yes, I think it's better to change the title because k-means vs. kNN seems ambiguous. $\endgroup$
    – chl
    Sep 21, 2010 at 22:07

4 Answers 4

9
$\begingroup$

You appear to have confused "cluster analysis" with "classification". The former is where you don't know the groupings and wish to determine them from the training data to hand. Classification is where you know the groups and want to predict them.

There are a few packages in R that do this. For example, look at the results of this R Site Search for suitable packages.

Alternatively, perhaps you are looking for a multivariate analysis of variance? In which case lm() and aov() would be worth looking at for a start. This presumes you want to "model" your data as a function of the group variable?

$\endgroup$
3
  • $\begingroup$ I believe the k nearest-neighbors test is a multivariate analysis. Perhaps I have confused cluster analysis with classification, but I don't think either apply in this situation. I already have categorized the variables into groups, and now want to see if these groups statistically differ from one another. This test is different that an ANOVA or linear model. Any suggestions? Thanks. $\endgroup$
    – Sharon
    Sep 21, 2010 at 23:03
  • $\begingroup$ @Sharon I'm a little bit puzzled about the term 'randomization test' (the only paper I found using this keyword, j.mp/9OCB9I, seems rather to focus on power considerations) -- I rest on my idea that you could use cross-validation to assess the classification accuracy in your data, e.g. leave-one-out or k-fold CV for this purpose (available in kknn and class packages). Now, I don't know on which basis your classes were defined, but it is generally meaningless to use ANOVA to test if the groups differ on the variables that were used to define class membership. $\endgroup$
    – chl
    Sep 22, 2010 at 7:30
  • $\begingroup$ @Sharon; can you explain your data a bit better (I'm a (sort of) ecologist and use isotopes all the time so you can be quite technical if it helps)? $\endgroup$ Sep 22, 2010 at 11:54
5
$\begingroup$

kmeans() (you can find it by typing ?? followed by the name of what you want as in ??kmean). In general, a good trick is to first look it up on a R specific search engine

$\endgroup$
1
  • 4
    $\begingroup$ You can also do RSiteSearch("k-means") $\endgroup$
    – nico
    Sep 21, 2010 at 20:42
5
$\begingroup$

I am not sure to understand your question since you talk about k-means, which is basically an unsupervised method (i.e. where classes are not known a priori), while at the same time you are saying that you already identified groups of individuals. So I would suggest to look at classification methods, or other supervised methods where class membership is known and the objective is to find a weighted combination of your variables that minimize your classification error rate (this is just an example). For instance, LDA does a good job (see the CRAN task view on Multivariate Statistics), but look also at the machine learning community (widely represented on the stats.stackexchange) for other methods.

Now since you also talked of k-nearest neighbor, I wonder if you are not introducing a confusion between k-means and kNN. In this case, the corresponding R function is knn() in the class package (it includes cross-validation), or see the kknn package.

$\endgroup$
0
$\begingroup$

I wouldnt cluster or classify the data at all. Since youve got ratio scaled data (isotopes) my method of choice would be PCA (Principal Component Analysis). By colouring your points in the PCA diagram according to your "eco-type" you could see their dispersal within the isotope ratio variation. Further, you will see the influence of each parameter (isotope ratios) in the biplot - the result will contain much more information than a classification.

$\endgroup$
1
  • $\begingroup$ I sense the user is looking for a statistical test to determine the fit. PCA falls a bit short on that. I think LDA as suggested by @chl is the way to go here. $\endgroup$ May 16, 2012 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.