Analiza korespondencji



R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

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.

[Previously saved workspace restored]

> dane=read.csv2("Analiza_korespondencji.csv")
> dane
Sklep Powod
1 Ach P1
2 Alb P1
3 Bdr P1
4 Crr P1
5 Gnt P1
6 Hyp P1
7 inn P2
8 LDP P3
9 Rel P1
10 Ach P1
11 Ach P7
12 Ach P7
13 Alb P1
14 Alb P4
15 Crr P4
16 Crr P7
17 Ach P1
18 Ach P2
19 Gnt P7
20 Ach P1
21 Gnt P7
22 Gnt P7
23 Bdr P1
24 Crr P1
25 Crr P2
26 Gnt P7
27 Gnt P1
28 Gnt P1
29 Gnt P1
30 Gnt P2
31 Hyp P7
32 inn P7
33 Rel P1
34 Rel P1
35 Rel P1
36 Rel P1
37 Rel P1
38 Rel P1
39 Rel P2
40 Ach P4
41 Ach P3
42 Ach P3
43 Ach P3
44 Alb P3
45 Alb P3
46 Alb P3
47 Alb P3
48 Bdr P3
49 Bdr P3
50 Bdr P3
51 Bdr P3
52 Bdr P3
53 Gnt P3
54 Gnt P3
55 Gnt P3
56 Gnt P3
57 Hyp P3
58 inn P3
59 inn P3
60 inn P3
61 inn P3
62 inn P3
63 inn P3
64 inn P3
65 inn P3
66 inn P3
67 Rel P3
68 Rel P3
69 Rel P3
70 Rel P3
71 Rel P3
72 Rel P3
73 Rel P3
74 Rel P3
75 Gnt P4
76 Gnt P4
77 Gnt P4
78 inn P4
79 inn P4
80 inn P4
81 inn P4
82 Rel P4
83 Rel P4
84 Rel P4
85 Rel P4
86 Ach P5
87 Ach P5
88 Ach P5
89 Ach P5
90 Bdr P5
91 Bdr P5
92 Bdr P5
93 Bdr P5
94 Bdr P5
95 Bdr P5
96 Bdr P5
97 Bdr P5
98 Bdr P5
99 Bdr P5
100 Bdr P5
101 Bdr P5
102 Bdr P5
103 Bdr P5
104 Bdr P5
105 Bdr P5
106 Bdr P5
107 Bdr P5
108 Bdr P5
109 Bdr P5
110 Bdr P5
111 Gnt P5
112 Hyp P5
113 inn P5
114 LDP P5
115 LDP P5
116 LDP P5
117 LDP P5
118 LDP P5
119 LDP P5
120 LDP P5
121 Rel P5
122 Rel P5
123 Ach P6
124 Ach P6
125 Ach P6
126 Ach P6
127 Ach P6
128 Ach P6
129 Ach P6
130 Ach P6
131 Ach P6
132 Ach P6
133 Ach P6
134 Ach P6
135 Alb P6
136 Bdr P6
137 Crr P6
138 Crr P6
139 Crr P6
140 Gnt P6
141 Gnt P6
142 Gnt P6
143 Gnt P6
144 Gnt P6
145 Hyp P6
146 Hyp P6
147 Hyp P6
148 LDP P6
149 Rel P6
150 Rel P6
151 Rel P6
152 Rel P6
153 Rel P6
154 Rel P6
155 Rel P6
156 Rel P6
157 Rel P6
158 Rel P6
159 Rel P6
160 inn P6
161 inn P7
162 Rel P6
> attach(dane)
> names(dane)
[1] "Sklep" "Powod"
> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Loading required package: MASS
Loading required package: grid
Loading required package: colorspace
> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.9
Warning: package 'vcd' is in use and will not be installed
> library(vcd)
> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> utils:::menuInstallPkgs()
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.9
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
no packages were specified
> utils:::menuInstallPkgs()
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.9
trying URL 'http://r.meteo.uni.wroc.pl/bin/windows/contrib/2.9/ca_0.33.zip'
Content type 'application/zip' length 134759 bytes (131 Kb)
opened URL
downloaded 131 Kb

package 'ca' successfully unpacked and MD5 sums checked

The downloaded packages are in
C:\Documents and Settings\student\Ustawienia lokalne\Temp\RtmpfjjeDa\downloaded_packages
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
cannot create file 'C:\PROGRA~1\R\R-29~1.2/doc/html/packages.html', reason 'Permission denied'
> library(ca)
Loading required package: rgl
> tab=xtabs(~Sklep+Powod,data=dane)
> tab
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 4 1 3 1 4 12 2
Alb 2 0 4 1 0 1 0
Bdr 2 0 5 0 21 1 0
Crr 2 1 0 1 0 3 1
Gnt 4 1 4 3 1 5 4
Hyp 1 0 1 0 1 3 1
inn 0 1 9 4 1 1 2
LDP 0 0 1 0 7 1 0
Rel 7 1 8 4 2 12 0
> chisq.test(tab)

Pearson's Chi-squared test

data: tab
X-squared = 122.4509, df = 48, p-value = 1.974e-08

Warning message:
In chisq.test(tab) : Chi-squared approximation may be incorrect
> w=assocstats(tab)
> w
X^2 df P(> X^2)
Likelihood Ratio 126.40 48 5.5958e-09
Pearson 122.45 48 1.9740e-08

Phi-Coefficient : 0.869
Contingency Coeff.: 0.656
Cramer's V : 0.355
> #sprawdzalismy czy zmienne sa niezALEZNE
> N=sum(tab)
> N
[1] 162
> P=round(((1/N)*tab),4)
> P
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 0.0247 0.0062 0.0185 0.0062 0.0247 0.0741 0.0123
Alb 0.0123 0.0000 0.0247 0.0062 0.0000 0.0062 0.0000
Bdr 0.0123 0.0000 0.0309 0.0000 0.1296 0.0062 0.0000
Crr 0.0123 0.0062 0.0000 0.0062 0.0000 0.0185 0.0062
Gnt 0.0247 0.0062 0.0247 0.0185 0.0062 0.0309 0.0247
Hyp 0.0062 0.0000 0.0062 0.0000 0.0062 0.0185 0.0062
inn 0.0000 0.0062 0.0556 0.0247 0.0062 0.0062 0.0123
LDP 0.0000 0.0000 0.0062 0.0000 0.0432 0.0062 0.0000
Rel 0.0432 0.0062 0.0494 0.0247 0.0123 0.0741 0.0000
> print(P)
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 0.0247 0.0062 0.0185 0.0062 0.0247 0.0741 0.0123
Alb 0.0123 0.0000 0.0247 0.0062 0.0000 0.0062 0.0000
Bdr 0.0123 0.0000 0.0309 0.0000 0.1296 0.0062 0.0000
Crr 0.0123 0.0062 0.0000 0.0062 0.0000 0.0185 0.0062
Gnt 0.0247 0.0062 0.0247 0.0185 0.0062 0.0309 0.0247
Hyp 0.0062 0.0000 0.0062 0.0000 0.0062 0.0185 0.0062
inn 0.0000 0.0062 0.0556 0.0247 0.0062 0.0062 0.0123
LDP 0.0000 0.0000 0.0062 0.0000 0.0432 0.0062 0.0000
Rel 0.0432 0.0062 0.0494 0.0247 0.0123 0.0741 0.0000
> max(P)
[1] 0.1296
> #masy wierszy
> masa_w=round(ca(tab)$rowmass,4)
> masa_w
[1] 0.1667 0.0494 0.1790 0.0494 0.1358 0.0432 0.1111 0.0556 0.2099
> #masa kolumn
> masa_k=round(ca(tab)$colmass,4)
> masa_k
[1] 0.1358 0.0309 0.2160 0.0864 0.2284 0.2407 0.0617
> profile_w=round(P/masa_k,4)
> profile_w
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 0.1819 0.0287 0.0810 0.1005 0.7994 0.8576 0.0511
Alb 0.3981 0.0000 0.1026 0.0457 0.0000 0.0271 0.0000
Bdr 0.0569 0.0000 0.5008 0.0000 1.5000 0.0258 0.0000
Crr 0.1424 0.0258 0.0000 0.0287 0.0000 0.2998 0.2006
Gnt 0.1081 0.1005 0.7994 0.2141 0.0258 0.2275 0.1144
Hyp 0.0258 0.0000 0.0287 0.0000 0.1005 0.5987 0.0718
inn 0.0000 0.2006 0.6435 0.1026 0.0457 0.0287 0.0539
LDP 0.0000 0.0000 0.0271 0.0000 1.3981 0.0718 0.0000
Rel 1.3981 0.0718 0.2052 0.1819 0.0569 0.3244 0.0000
> profile_w=round(P/masa_w,4)
> profile_k=round(P/masa_k,4)
> profile_w
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 0.1482 0.0372 0.1110 0.0372 0.1482 0.4445 0.0738
Alb 0.2490 0.0000 0.5000 0.1255 0.0000 0.1255 0.0000
Bdr 0.0687 0.0000 0.1726 0.0000 0.7240 0.0346 0.0000
Crr 0.2490 0.1255 0.0000 0.1255 0.0000 0.3745 0.1255
Gnt 0.1819 0.0457 0.1819 0.1362 0.0457 0.2275 0.1819
Hyp 0.1435 0.0000 0.1435 0.0000 0.1435 0.4282 0.1435
inn 0.0000 0.0558 0.5005 0.2223 0.0558 0.0558 0.1107
LDP 0.0000 0.0000 0.1115 0.0000 0.7770 0.1115 0.0000
Rel 0.2058 0.0295 0.2354 0.1177 0.0586 0.3530 0.0000
> profile_k
Powod
Sklep P1 P2 P3 P4 P5 P6 P7
Ach 0.1819 0.0287 0.0810 0.1005 0.7994 0.8576 0.0511
Alb 0.3981 0.0000 0.1026 0.0457 0.0000 0.0271 0.0000
Bdr 0.0569 0.0000 0.5008 0.0000 1.5000 0.0258 0.0000
Crr 0.1424 0.0258 0.0000 0.0287 0.0000 0.2998 0.2006
Gnt 0.1081 0.1005 0.7994 0.2141 0.0258 0.2275 0.1144
Hyp 0.0258 0.0000 0.0287 0.0000 0.1005 0.5987 0.0718
inn 0.0000 0.2006 0.6435 0.1026 0.0457 0.0287 0.0539
LDP 0.0000 0.0000 0.0271 0.0000 1.3981 0.0718 0.0000
Rel 1.3981 0.0718 0.2052 0.1819 0.0569 0.3244 0.0000
> wynik=summary(ca(tab))
> wynik

Principal inertias (eigenvalues):

dim value % cum% scree plot
1 0.478566 63.3 63.3 *************************
2 0.165270 21.9 85.2 *********
3 0.070426 9.3 94.5 ****
4 0.021350 2.8 97.3 *
5 0.017907 2.4 99.7 *
6 0.002350 0.3 100.0
-------- -----
Total: 0.755870 100.0


Rows:
name mass qlt inr k=1 cor ctr k=2 cor ctr
1 | Ach | 167 898 63 | -217 165 16 | -457 732 210 |
2 | Alb | 49 535 56 | -420 205 18 | 534 331 85 |
3 | Bdr | 179 995 349 | 1209 993 547 | 60 2 4 |
4 | Crr | 49 687 64 | -672 459 47 | -474 228 67 |
5 | Gnt | 136 566 79 | -497 564 70 | 32 2 1 |
6 | Hyp | 43 531 24 | -214 107 4 | -425 423 47 |
7 | inn | 111 939 155 | -379 136 33 | 920 803 570 |
8 | LDP | 56 983 129 | 1312 979 200 | -76 3 2 |
9 | Rel | 210 545 80 | -383 508 64 | -104 37 14 |

Columns:
name mass qlt inr k=1 cor ctr k=2 cor ctr
1 | P1 | 136 613 63 | -363 373 37 | -291 241 70 |
2 | P2 | 31 433 37 | -621 431 25 | -40 2 0 |
3 | P3 | 216 886 113 | -151 57 10 | 573 828 429 |
4 | P4 | 86 911 80 | -604 522 66 | 522 389 142 |
5 | P5 | 228 997 470 | 1245 995 739 | -51 2 4 |
6 | P6 | 241 923 137 | -394 359 78 | -493 563 354 |
7 | P7 | 62 286 99 | -588 285 45 | 39 1 1 |

> #value - inercje
> plot(wynik)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
> plot(ca(tab),what=c("all","all"),mass=TRUE)
> plot(ca(tab),what=c("all","all"),mass=TRUE,contrib="relatives",labels=2)
> F<-ca(tab)$rowcoord
> G<-ca(tab)$colcoord
> F2<-cbind(F)[,c(1,2)}
Error: unexpected '}' in "F2<-cbind(F)[,c(1,2)}"
> F2<-cbind(F)[,c(1,2)]
> G2<-cbind(G)[,c(1,2)]
> #polaczenie wspolrzednych w jeden zbior
> wymiar1<-append(F2[,1],G2[,1])
> wymiar2<-append(F2[,2],G2[,2])
> r<-cbind(wymiar1,wymiar2)
> #wyznaczanie kwadratowej odleglosci euklidesowej
> odl<-dist(r,method="euclidean")^2
> #dendogram za pomoca metody warda
> dend<-hclust(odl,method="ward")
> plot(dend,ylab="odleglosc")
> rn<-dimnames(tab)[[1]]
> cn<-dimnames(tab)[[2]]
> rownames(F)<-c(rn)
> rownames(G)<-c(cn)
> plot(dend,ylab="odleglosc")
> F2<-cbind(F)[,c(1,2)]
> G2<-cbind(G)[,c(1,2)]
> wymiar1<-append(F2[,1],G2[,1])
> wymiar2<-append(F2[,2],G2[,2])
> r<-cbind(wymiar1,wymiar2)
> odl<-dist(r,method="euclidean")^2
> dend<-hclust(odl,method="ward")
> plot(dend,ylab="odleglosc")
>


Wyszukiwarka

Podobne podstrony:
Analiza korespondecji i jej zastosowania w naukach społecznych
Analiza Matematyczna 2 Zadania
analiza
ANALIZA KOMPUTEROWA SYSTEMÓW POMIAROWYCH — MSE
Analiza stat ścianki szczelnej
Analiza 1
Analiza?N Ocena dzialan na rzecz?zpieczenstwa energetycznego dostawy gazu listopad 09
Analizowanie działania układów mikroprocesorowych
Analiza samobójstw w materiale sekcyjnym Zakładu Medycyny Sądowej AMB w latach 1990 2003
Analiza ekonomiczna spółki Centrum Klima S A
roprm ćwiczenie 6 PROGRAMOWANIE ROBOTA Z UWZGLĘDNIENIEM ANALIZY OBRAZU ARLANG
Finanse Finanse zakładów ubezpieczeń Analiza sytuacji ekonom finansowa (50 str )
analiza algorytmow
ANALIZA GRAFOLOGICZNA(1)
Analiza zależności dwóch cech statystycznych ilościowych
Przyczynek do analizy polozenia
17 Iskra Joanna Analiza wartości hemoglobiny glikowanej Hb

więcej podobnych podstron