R Under development (unstable) (2024-10-01 r87205 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(WeightedCluster) Loading required package: TraMineR TraMineR stable version 2.2-10 (Built: 2024-10-02) Website: http://traminer.unige.ch Please type 'citation("TraMineR")' for citation information. Loading required package: cluster This is WeightedCluster stable version 1.8-0 (Built: 2024-10-02) To get the manuals, please run: vignette("WeightedCluster") ## Complete manual in English vignette("WeightedClusterFR") ## Complete manual in French vignette("WeightedClusterPreview") ## Short preview in English To cite WeightedCluster in publications please use: Studer, Matthias (2013). WeightedCluster Library Manual: A practical guide to creating typologies of trajectories in the social sciences with R. LIVES Working Papers, 24. doi: 10.12682/lives.2296-1658.2013.24 > data(mvad) > library(RUnit) > > ## Aggregating state sequence > aggMvad <- wcAggregateCases(mvad[1:10, 17:86], weights=mvad$weight[1:10]) > > ## Creating state sequence object > mvad.seq <- seqdef(mvad[aggMvad$aggIndex, 17:86], weights=aggMvad$aggWeights) [>] 6 distinct states appear in the data: 1 = FE 2 = HE 3 = employment 4 = joblessness 5 = school 6 = training [>] state coding: [alphabet] [label] [long label] 1 FE FE FE 2 HE HE HE 3 employment employment employment 4 joblessness joblessness joblessness 5 school school school 6 training training training [>] sum of weights: 15.16 - min/max: 0.33/3.6 [>] 10 sequences in the data set [>] min/max sequence length: 70/70 > ## Computing Hamming distance between sequence > diss <- seqdist(mvad.seq, method="HAM") [>] 10 sequences with 6 distinct states [>] creating a 'sm' with a single substitution cost of 1 [>] creating 6x6 substitution-cost matrix using 1 as constant value [>] 10 distinct sequences [>] min/max sequence lengths: 70/70 [>] computing distances using the HAM metric [>] elapsed time: 0.05 secs > clust4 <- wcKMedoids(diss, k=4, weights=aggMvad$aggWeights, cluster.only=TRUE) > dissd <- seqdist(mvad.seq, method="HAM", full.matrix=FALSE) [>] 10 sequences with 6 distinct states [>] creating a 'sm' with a single substitution cost of 1 [>] creating 6x6 substitution-cost matrix using 1 as constant value [>] 10 distinct sequences [>] min/max sequence lengths: 70/70 [>] computing distances using the HAM metric [>] elapsed time: 0.07 secs > clust4d <- wcKMedoids(dissd, k=4, weights=aggMvad$aggWeights, cluster.only=TRUE) > #clust4d <- wcKMedoids(diss, k=4, weights=aggMvad$aggWeights,debuglevel=11) > checkEquals(clust4, clust4d) [1] TRUE > > > > > ## Compute the silhouette of each observation > clust1 <- rep(1, nrow(mvad.seq)) > checkException(qual <- wcClusterQuality(diss, clust1, weights=aggMvad$aggWeights)) Error in wcClusterQualityInternal(diss = diss, clustering = clustering, : [!] The clustering should have at least two different values. [1] TRUE > > ## Compute the silhouette of each observation > checkException(sil <- wcSilhouetteObs(diss, clust1, weights=aggMvad$aggWeights)) Error in wcSilhouetteObs(diss, clust1, weights = aggMvad$aggWeights) : [!] The clustering should have at least two different values. [1] TRUE > > qual1 <- wcClusterQuality(diss, clust4, weights=aggMvad$aggWeights) > qual2 <- wcClusterQuality(dissd, clust4, weights=aggMvad$aggWeights) > checkEquals(qual1, qual2) [1] TRUE > > sil1 <- wcSilhouetteObs(diss, clust4, weights=aggMvad$aggWeights) > sil2 <- wcSilhouetteObs(dissd, clust4, weights=aggMvad$aggWeights) > checkEquals(sil1, sil2) [1] TRUE > > proc.time() user system elapsed 1.90 0.40 2.26