1

Using an unclustered input data frame (fci), an APResult is created from apcluster() as epxected:

> apclr2q02 <- apcluster(negDistMat(r=2), fci)
> show(apclr2q02)

APResult object

Number of samples     =  1045 
Number of iterations  =  826 
Input preference      =  -22.6498 
Sum of similarities   =  -1603.52 
Sum of preferences    =  -1336.338 
Net similarity        =  -2939.858 
Number of clusters    =  59 

The online documentation says that aggExCluster() can accept either data to be clustered as input, or a previous clustering result (ExClust or APResult). Running aggExCluster on the unclustered data (fci), the code works as expected:

> aglomr2 <- aggExCluster(negDistMat(r=2), fci)
> aglomr2

AggExResult object

Number of samples          =  1045 
Maximum number of clusters =  1045 

The result can be plotted in dendogram format and all is well; however, using the APResult obtained above (apclr2q02) as input, the following error is returned:

> aglomr2 <- aggExCluster(negDistMat(r=2), apclr2q02)
Error in as.vector(data) : 
  no method for coercing this S4 class to a vector

Any suggestions about what I might be doing wrong with the APResult object as input?

Dennis
  • 51
  • 1
  • 4

1 Answers1

0

If you want to use aggExCluster() on top of a previous clustering result given as an 'ExClust' or 'APResult' object, these objects need to be passed as argument 'x' and, additionally, the similarity matrix needs to be available. Here is a self-contained code snippet on the basis of your example (note that the object 'apres' returned from apcluster() includes the similarity matrix):

cl1 <- cbind(rnorm(50,0.2,0.05),rnorm(50,0.8,0.06))
cl2 <- cbind(rnorm(50,0.7,0.08),rnorm(50,0.3,0.05))
x <- rbind(cl1,cl2)

apres <- apcluster(negDistMat(r=2), x, q=0.7)
aggExCluster(x=apres)

In case that you start from a similarity matrix, you can either include it in the 'APResult' object, i.e.

sim <- negDistMat(r=2, x)
apres <- apcluster(sim, q=0.7, includeSim=TRUE)
aggExCluster(x=apres)

(if apcluster() is called on a similarity matrix, the matrix is not included in the result object by default, which can be overridden with 'includeSim=TRUE')

Alternatively, you can also specify the similarity matrix via the argument 's':

sim <- negDistMat(r=2, x)
apres <- apcluster(sim, q=0.7)
aggExCluster(x=apres, s=sim)

Calling aggExCluster() with a similarity function and an 'APResult' object will not work because the 'APResult' does not include the original data, so aggExCluster() is unable to compute the similarity matrix that is necessary for clustering. Instead, if aggExCluster() is called with argument 's' being a similarity function, it expects the argument 'x' to contain the raw data and will therefore try to convert it to a subsettable object. That is why you get this error message.

UBod
  • 825
  • 7
  • 11