Question: l am trying to run this code in R but am receiving errors with the ClassProp and clusplot functions. I have tried researching online, but
l am trying to run this code in R but am receiving errors with the ClassProp and clusplot functions. I have tried researching online, but I am a new R user and do not understand what I am doing wrong or what should change in order to make the lengths of partitioning vectors match and have the correct length. Can someone please explain and show what the updated code should be for it to run correctly?
Code:
libraryMixSim
libraryMASS
librarycluster
librarymclust
datairis
#Create a true.id variable based on Species variable from the data.
idtrue asfactoriris$Species
#Form a data set based on the first columns, ie without the Species variable.
X iris:
#aHierarchical Clustering with Single Linkage
d distX
Hsingle hclustd method "single"
idsingle cutreeHsingle,
#Calculating ACCURACY
ClassPropidtrue, idsingle
#bHierarchical Clustering with Complete Linkage
d distX
Hcomplete hclustd method "complete"
idcomplete cutreeHcomplete,
# Calculating ACCURACY
ClassPropidtrue, idcomplete
#cKmeans
d distX
idtrue rep: each
idkmeans kmeansX$clust
#Calculating ACCURACY
ClassPropidtrue, idkmeans
kmeansmodel kmeansX centers nstart
#dModelbased clustering from package mclust
mclustmodel MclustX G $class
#Create a plot using function clusplot from package cluster
clusplotX Hsingle, lines color TRUE, plotchar FALSE, main "Hierarchical Single Linkage
clusplotX Hcomplete, lines color TRUE, plotchar FALSE, main "Hierarchical Complete Linkage
clusplotX kmeansmodel, lines color TRUE, plotchar FALSE, main Kmeans"
clusplotX mclustmodel, lines color TRUE, plotchar FALSE, main "Modelbased Clustering"
Errors:
ClassPropidtrue, idsingle
Error in ClassPropidtrue, idsingle :
NAs in foreign function call arg
In addition: Warning messages:
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid ClassPropidtrue, idcomplete
Error in ClassPropidtrue, idcomplete :
NAs in foreign function call arg
In addition: Warning messages:
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid factor level, NA generated factor level, NA generated
ClassPropidtrue, idcomplete
Error in ClassPropidtrue, idcomplete :
NAs in foreign function call arg
In addition: Warning messages:
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid factor level, NA generated
: In factortmp ind, value :
invalid factor level, NA generated
ClassPropidtrue, idkmeans
Error in ClassPropidtrue, idkmeans :
Lengths of partitioning vectors do not match...
#Create a plot using function clusplot from package cluster
clusplotX Hsingle, lines color TRUE, plotchar FALSE, main "Hierarchical Single Linkage
Error in clusplot.defaultX Hsingle, lines color TRUE, plotchar FALSE, :
The clustering vector is of incorrect length
clusplotX Hcomplete, lines color TRUE, plotchar FALSE, main "Hierarchical Complete Linkage
Error in clusplot.defaultX Hcomplete, lines color TRUE, plotchar FALSE, :
The clustering vector is of incorrect length
clusplotX kmeansmodel, lines color TRUE, plotchar FALSE, main Kmeans"
Error in clusplot.defaultX kmeansmodel, lines color TRUE, plotchar FALSE, :
The clustering vector is of incorrect length
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
