Dear list,

I have two dissimilarity matrices, one for a training data set which I then
clustered using PAM. The second is a diss matrix for a validation data set
(an independent field sample). I have been trying to use knn to distinguish
distances between the validation data set and the 6 mediods of the training
data defined by using PAM.

I continue to get error messages in regards to either the lengths of
matrices being different or that the dimensions of my data are incorrect.
Here are the two steps I am using.

I define my training data set:
#read in the data file
comm.data = read.csv(comm.data.file,as.is=T); rownames(comm.data) =
comm.data[,1]
comm.dist = dist(comm.data[-1])
#define the fish community clusters
clust.data = pam(comm.dist, 6, diss = TRUE, keep.diss = TRUE)
#plot(clust.data)
#print(clust.data)
#define the community groupings
comm.groups =
data.frame(GridID=names(clust.data$clustering),Class=clust.data$clustering)
write.matrix(comm.dist, file = "train.dist.csv", sep = ",")

Then
#bring in the validation species data set
comm.data2 = read.csv(comm.data.file2); rownames(comm.data2) =
comm.data2[,1] #define the row names as the site id's
#bind validation data to training species data set
test.data = rbind(comm.data[clust.data$medoids,],comm.data2)
#get the distance matrix for the validation data
test.dist = dist(test.data[-1])
test.dist.matrix = as.matrix(test.dist, rownames.force = TRUE)
write.matrix(test.dist.matrix, file = "tested.dist.csv", sep = ",")
knn1 = knn(test.dist.matrix[7:25,], clust.data$mediods,
factor(c("1","2","3","4","5","6")), k = 3)

Perhaps I am incorrect in thinking that I can use knn to distinguish
distances between the training data mediods and the validation data, but I
have seen similar statements produced on the R help before.

All suggestions welcomed and thank you in advance for your time.

Kind Regards

Steph





 O__  ---- Stephanie Januchowski     ARC COE for Coral Reef Studies
 c/ /'_ --- James Cook University  Townsville Queensland 4811
(*) \(*) -- P: 0747816024     E: stephanie.januchow...@jcu.edu.au
~~~~~~~~~~

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to