Multivariate Statistik - Aufgabe 7 - Clusteranalyse
From StatWiki
Contents |
Gelerntes zu Clusteranalyse
Daten sollten standardisiert werden (siehe #Beispiel 4)
Hierarchical Clustering in R mit agnes oder hclust.
Ward kann bei Hoch korrelierten Daten unsinn machen.
Der Bannerplot zeigt die Distanz zwischen den Beobachtungen an (Wenig weiss = Viel Rot = sehr nahe = sehr ähnlich)
Agglomerative Coefficient = Verhältniss Rot/Weiss (Hoch ist gut)
pam macht robustes k-means Clustering und bei plot(pam(...)) zeigt der Silhouette an wie gut eine Beobachtung zu dem Cluster passt (nahe bei 1 gut, unter 0 = passt gar nicht)
Beispiel 1
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Daten
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
pdf(rpdf) library(cluster) clusplot(clara(d1,3,metric="manhattan")) #
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE) Error in loadNamespace(name) : there is no package called 'distrEx' Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
pdf(rpdf) library(cluster) clusplot(clara(d1,2,metric="manhattan")) #
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE) Error in loadNamespace(name) : there is no package called 'distrEx' Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Beispiel 2
de:Distanzfunktion#City-Block-.2C_Taxi-_bzw._Manhattan-Distanz ist definiert als
Distanzmatrix zu den obigen Daten.
library(cluster) clara(d1,3,metric="manhattan")$diss #
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Bottom-Up Clustering / Agglomerierendes Verfahren
- Zu Beginn ist jeder Datenpunkt seine eigene Partition.
- Es werden jene beiden Partition fusioniert, deren Distanz (für Complete Linkage: maximale Distanz zweier Elemente aus den beiden Partitionen) minimal ist.
- Man wiederhole Punkt 2, bis nur mehr eine Partition existiert.
Der minimal Abstand in jeder Iteration wird als Heterogenitätskoeffizient.
Beispiel 3
Welche Länder haben ähnliche Konsumgewohnheiten?
Daten
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Beispiel 3 - Complete
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Beispiel 3 - Single
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Beispiel 3 - Ward
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Beispiel 3 - Zentroid
Wie geht das mit agnes?
Beispiel 4
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Aufgrund der obigen Plots entscheide ich mich für 4 Cluster.
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Die Zentren der Cluster.
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Innere Stadt sind hauptsächlich nicht Wähler. Meidling, Floridsdorf, Donaustadt sind klassische SPÖ Bezirke. Hernals, Döbling sind klassische ÖVP Bezirke. In Wieden, Mariahilf sind die Grünen sehr stark.
Alles in allem wenig überraschend, bis auf die Innere Stadt (zumindest für mich).
Mit absoluten Stimmenanzahlen schauts eigentlich sehr anders aus. Die Grösse der Bezirke spielt sehr stark mit rein.
> sys.load.image("/var/www/localhost/htdocs/StatWiki/Rfiles/true", TRUE)
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
Alternativ könnte man noch mit Mahalanobis Distanz (passend weil Daten hoch korreliert) und pam arbeiten.
plot(agnes(d3p, metric="mahalanobis",method="average"))
plot(pam(d3p,5,metric="mahalanobis"),labels=3)
Beispiel 5
Beispiel 6
Error in loadNamespace(name) : there is no package called 'distrEx'
Calls: sys.load.image ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
