Skip to content

Kohonen Package

5 messages · Brock Tibert, Peter Ehlers, Gavin Simpson

#
Hi All,

I am still learning R, but making, IMO, great strides.  I learned about Kohonen/Self-Organizing Maps in class and I would like to try to replicate some of the things we have seen in class.

Below is my code.  I am trying to create a u-matrix.  In the documentation on page 9 it appears the type of plot, dist.neighbours should do the trick, however, I am getting an error:
(Error in match.arg(type) : 'arg' should be one of "codes", "changes", "counts", "mapping", "property", "quality")

Since I am new to R, I figure I am missing something obvious.  Any help you can provide will be greatly appreciated!

Thanks in advance,

Brock
library(kohonen)

data("wines")
wines.sc <- scale(wines)

som <- som(wines.sc, grid=somgrid(5, 5, "hexagonal"))
plot(som)
plot(som, type="dist.neighbours" )
#
I haven't used pkg:kohonen, so this is just guessing:

1. are you using an old version of the package?

2. don't call the output of function som() 'som'. As
people around here might say: would you call your
iguana 'iguana'?

3. have you used str() on your object to check what
it really contains? I would guess that it should be
of class som and have a component 'distances'.

If none of that helps then it's beyond me.

  -Peter Ehlers
Brock Tibert wrote:
#
On Sat, 2009-11-28 at 17:16 -0700, Peter Ehlers wrote:
I deleted the original email, so I'll reply here instead. The example
provided by the OP works for me with on R 2.10-patched and:
[1] "2.0.5"

Looking at the CHANGES file in the package, "dist.neighbours" was added
in version 2.0.5, so I suspect the OP was using an older version, but
reading a newer version of the help as a PDF.
Indeed:

##install.packages("fortunes") ## uncomment if not installed
require("fortunes")
fortune("dog")

HTH

G
#
Many thanks, Peter, Gavin.  That is exactly what it was...and old version.  I was running R 2.7 (needed it to integrate with SPSS 17). 

I know I am a pain, but one last question.  Is it possible to overlay a value label onto the maps?  In some of the SOMs we have worked through in class, we saw examples that overlay the observation's label onto the map so we could see where each observation fell.  

Again, many, many, many thanks.  In just working through this one example, I have learned a ton about R.

- Brock
--- On Sun, 11/29/09, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:

            
#
This turns out to be easy. What you need are the
locations where to put the labels and those are given in
the som object. Using your code:

mysom <- som(wines.sc, grid=somgrid(5, 5, "hexagonal"))
plot(mysom, type="dist.neighbours" )

# check what's contained in mysom:
str(mysom)

# we need the $grid$pts matrix of (x,y)-locations:
text(mysom$grid$pts, labels=letters)

# Your labels are too long to fit easily,
# so abbreviate:
mylabels <- abbreviate(colnames(wines), minlength=3)
plot(mysom, type="dist.neighbours" )
text(mysom$grid$pts, labels=mylabels)

  -Peter Ehlers
Brock Tibert wrote: