[R] Pseudo F statistics with index.G1

Allan Engelhardt allane at cybaea.com
Tue Jul 6 15:30:42 CEST 2010


Always use set.seed in your examples.

Running your code after set.seed(1) works fine but gives the error after 
set.seed(2).  The problem in the latter case being that there is only 
one value 7 in C and you need two or more for the index.G1 code to make 
sense.

Hope this helps a little

Allan

Example:

>  set.seed(1)
>  mat<- diag(1,27,27)
>  f<- runif(sum(26:1),0,1)
>  mat[lower.tri(mat)]<- f
>  mat<- t(mat)
>  mat[lower.tri(mat)]<- f
>
>  # Cluster with Agnes
>  A<- agnes(mat,diss=T,method="average")
>  C<- cutree(A,k=7)   # Value of k = the number of clusters
>  F<- index.G1(mat,C)
>  table(C)
C
1 2 3 4 5 6 7
6 3 5 2 3 4 4
>  set.seed(2)
>  mat<- diag(1,27,27)
>  f<- runif(sum(26:1),0,1)
>  mat[lower.tri(mat)]<- f
>  mat<- t(mat)
>  mat[lower.tri(mat)]<- f
>
>  # Cluster with Agnes
>  A<- agnes(mat,diss=T,method="average")
>  C<- cutree(A,k=7)   # Value of k = the number of clusters
>  F<- index.G1(mat,C)
Error in apply(x[cl == i, ], 2, mean) :
   dim(X) must have a positive length
>  table(C)
C
1 2 3 4 5 6 7
8 4 5 3 4 2 1



On 06/07/10 09:32, Kennedy wrote:
> Hello,
>
> I have done some clustering with Agnes and want to calculate the pseudo F
> statistics using index.G1. It works for a low number of clusters but when i
> increase the number of clusters i eventually get the following message:
>
> Error in apply(x[cl == i, ], 2, mean) :
>    dim(X) must have a positive length
>
> The following code produces an example comparable to the data i am
> clustering:
>
> library(cluster)
> library(ade4)
> library(R2HTML)
> library(e1071)
> library(class)
> library(rgl)
> library(MASS)
> library(clusterSim)
>
> # Create a symmetric matrix with ones on the diagonal
> mat<- diag(1,27,27)
> f<- runif(sum(26:1),0,1)
> mat[lower.tri(mat)]<- f
> mat<- t(mat)
> mat[lower.tri(mat)]<- f
>
> # Cluster with Agnes
> A<- agnes(mat,diss=T,method="average")
> C<- cutree(A,k=7)   # Value of k = the number of clusters
> F<- index.G1(mat,C)
>
> The code above works for k=2:6 but then the error message appears.
>
>
> Sincerely
>
> Henrik
>



More information about the R-help mailing list