1 #############################################################
2 makesimi<-function(dm){
4 m<-matrix(0,ncol(dm),ncol(dm))
5 rownames(m)<-colnames(a)
6 colnames(m)<-colnames(a)
8 for (col in 1:(ncol(a)-1)){
9 for (colc in (col+1):ncol(a)){
10 ta<-table(a[,col],a[,colc])
11 if (ncol(ta)==1 & colnames(ta)[1]=='0') {
12 ta<-cbind(ta,'1'=c(0,0))
13 } else if (ncol(ta)==1 & colnames(ta)[1]=='1') {
14 ta<-cbind('0'=c(0,0),t)
15 } else if (nrow(ta)==1 & rownames(ta)[1]=='0'){
16 ta<-rbind(ta,'1'=c(0,0))
17 } else if (nrow(ta)==1 & rownames(ta)[1]=='1') {
18 ta<-rbind('0'=c(0,0),ta)
20 #m[colc,col]<-length(which((a[,col]==1) & (a[,colc]==1)))
22 m[col,colc]<-m[colc,col]
25 out<-list(mat=m,eff=eff)
28 makejac<-function(dm){
30 m<-matrix(0,ncol(dm),ncol(dm))
31 rownames(m)<-colnames(a)
32 colnames(m)<-colnames(a)
34 for (col in 1:(ncol(a)-1)){
35 for (colc in (col+1):ncol(a)){
36 ta<-table(a[,col],a[,colc])
37 if (ncol(ta)==1 & colnames(ta)[1]=='0') {
38 ta<-cbind(ta,'1'=c(0,0))
39 } else if (ncol(ta)==1 & colnames(ta)[1]=='1') {
40 ta<-cbind('0'=c(0,0),t)
41 } else if (nrow(ta)==1 & rownames(ta)[1]=='0'){
42 ta<-rbind(ta,'1'=c(0,0))
43 } else if (nrow(ta)==1 & rownames(ta)[1]=='1') {
44 ta<-rbind('0'=c(0,0),ta)
46 m[colc,col]<-(ta[2,2]/(ta[1,2]+ta[2,1]+ta[2,2]))*100
47 #m[colc,col]<-(length(which((a[,col]==1) & (a[,colc]==1)))/(eff[col]+eff[colc]-length(which((a[,col]==1) & (a[,colc]==1)))))*100
48 m[col,colc]<-m[colc,col]
51 out<-list(mat=m,eff=eff)
54 makesimipond<-function(dm) {
56 m<-matrix(0,ncol(dm),ncol(dm))
57 rownames(m)<-colnames(dm)
58 colnames(m)<-colnames(dm)
63 for (col in 1:(ncol(a)-1)){
64 for (colc in (col+1):ncol(a)){
65 m[colc,col]<-length(which((a[,col]>1) & (a[,colc]>1)))
66 m[col,colc]<-m[colc,col]
69 out<-list(mat=m,eff=eff)
72 BuildProf01<-function(x,classes) {
74 #classes : classes de chaque lignes de x
75 dm<-cbind(x,cl=classes)
76 clnb=length(summary(as.data.frame(as.character(classes)),max=100))
78 print(summary(as.data.frame(as.character(classes)),max=100))
79 mat<-matrix(0,ncol(x),clnb)
81 rownames(mat)<-colnames(x)
83 dtmp<-dm[which(dm$cl==i),]
84 for (j in 1:(ncol(dtmp)-1)) {
85 #print(rownames(dtmp[j,]))
86 mat[j,i]<-sum(dtmp[,j])
91 ###################################################################
93 source('/home/pierre/workspace/iramuteq/Rscripts/chdfunct.R')
94 #info<-read.csv2(file('/home/pierre/fac/etudiant/crepin/simi/info01.csv',encoding='latin1'),row.names=1)
96 #biblio<-read.csv2(file('/home/pierre/fac/etudiant/crepin/simi/biblio01.csv',encoding='latin1'),row.names=1)
98 #rechdoc<-read.csv2(file('/home/pierre/fac/etudiant/crepin/simi/recherdoc01.csv',encoding='latin1'),row.names=1)
101 ######################@@
103 #########################
104 #chaud<-read.csv2('/home/pierre/fac/etudiant/sab/Chaudronnier_pour_MV01.csv',row.names=1)
105 ##cchaud<-ncol(chaud)
106 #op<-read.csv2('/home/pierre/fac/etudiant/sab/ocn_pour_mv01.csv',row.names=1)
108 #soud<-read.csv2('/home/pierre/fac/etudiant/sab/soudeur_pour_mv01.csv',row.names=1)
110 #indus<-read.csv2('/home/pierre/fac/etudiant/sab/metier_indus01.csv',row.names=1)
111 ##cmindus<-ncol(mindus)
112 #infor<-read.csv2('/home/pierre/fac/etudiant/sab/Informaticien_pour_MV01.csv',row.names=1)
113 ##cinfor<-ncol(infor)
114 #trav<-read.csv2('/home/pierre/fac/etudiant/sab/travail_pour_mv01.csv',row.names=1)
116 #tot<-cbind(chaud,op)
117 #tot<-cbind(tot,soud)
118 #tot<-cbind(tot,indus)
120 #list_data<-list('a'=chaud, 'b'=soud,'c'=infor,'d'=trav)
121 #tot<-cbind(chaud,op)
123 ##tot<-cbind(tot,infor)
124 ##tot<-cbind(tot,trav)
125 #mv<-read.csv2('/home/pierre/fac/etudiant/sab/chaud_soud_opn_metierindus01.csv')
127 #grp<-read.csv2('/home/pierre/fac/etudiant/sab/grp2.csv')
133 #################################################
135 #ag<-read.csv2('/home/pierre/workspace/iramuteq/corpus/tableau_agir2_recod_alc_entree_pourpassage_temp_AlcesteQuest_1/Act01.csv')
137 #load('/home/pierre/workspace/iramuteq/corpus/tableau_agir2_recod_alc_entree_pourpassage_temp_AlcesteQuest_1/RData.RData')
139 ###############################################################
141 #tot<-read.csv2('/home/pierre/fac/etudiant/crepin/simi/simitot01.csv')
142 #grp<-vector(mode='integer',length=ncol(tot))
146 #prof<-BuildProf01(tot,grp[,1])
147 ##prof<-prof[-nrow(prof),]
148 #outp<-AsLexico(prof)
149 #chistabletot<-outp[[2]]
151 ###################################################################
154 #tot<-read.csv2('/home/pierre/fac/etudiant/netto/simi-27-03-09/prof_inf_ecole_priv01.csv')
155 #tot<-tot[,-ncol(tot)]
156 #grp<-vector(mode='integer',length=nrow(tot))
159 #prof<-BuildProf01(tot,grp)
162 #outp<-AsLexico(prof)
163 #chistabletot<-outp[[2]]
165 #tot<-read.csv2('/home/pierre/fac/etudiant/netto/simi-27-03-09/etu_inf_pro_priv01.csv')
166 #print(tot[,ncol(tot)])
167 #tot<-tot[,-ncol(tot)]
168 #grp<-vector(mode='integer',length=nrow(tot))
171 #prof<-BuildProf01(tot,grp)
172 #outp<-AsLexico(prof)
173 #chistabletot<-outp[[2]]
175 #tot<-read.csv2('/home/pierre/fac/etudiant/netto/simi-27-03-09/prof_etu_inf_pro01.csv')
176 #print(tot[,ncol(tot)])
177 #tot<-tot[,-ncol(tot)]
178 #grp<-vector(mode='integer',length=nrow(tot))
181 #prof<-BuildProf01(tot,grp)
182 #outp<-AsLexico(prof)
183 #chistabletot<-outp[[2]]
185 #######################################################
187 #tot<-read.csv2('/home/pierre/workspace/iramuteq/corpus/grpiedal2008_01.csv')
188 #print(tot[,ncol(tot)])
189 #grp<-vector(mode='integer',length=ncol(tot))
192 #prof<-BuildProf01(tot,grp)
193 #outp<-AsLexico(prof)
194 #chistabletot<-outp[[2]]
196 #ministre<-read.csv2('/home/pierre/workspace/iramuteq/corpus/Ministres_AFCUCI_3/TableCont.csv',header=TRUE)
197 #eff<-colSums(ministre)
198 #ministre<-ministre[,-which(eff<100)]
200 ##ministre<-(ministre/colSums(ministre))*1000
201 #print(ncol(ministre))
204 #chistabletot<-outp[[2]]
205 #ministre<-read.csv2('/home/pierre/workspace/iramuteq/corpus/Ministres_Alceste_1/TableUc1.csv',header=TRUE)
206 #load('/home/pierre/workspace/iramuteq/corpus/Ministres_Alceste_1/RData.RData')
207 #ministre<-ministre[,-which(eff<200)]
208 #uce<-read.csv2('/home/pierre/workspace/iramuteq/corpus/Ministres_Alceste_1/listeUCE1.csv')
209 #uc<-matrix(0,nrow(ministre),1)
213 #for (i in 1:nrow(uce)) {
214 # uc[[as.integer(uce[i,2])+1]]<-n1[i,ncol(n1)]
216 #print(nrow(ministre))
218 #prof<-BuildProf01(ag,n1[,ncol(n1)])
219 #outp<-AsLexico(prof)
220 #chistabletot<-outp[[2]]
222 #######################
224 #########################
225 #priv<-read.csv2('/home/pierre/workspace/iramuteq/corpus/simi/info_priv01.csv')
226 #pro<-read.csv2('/home/pierre/workspace/iramuteq/corpus/simi/info_pro01.csv')
228 #tot<-cbind(priv,pro)
229 #tot<-read.csv2('/home/pierre/workspace/iramuteq/corpus/simi/priv_pro_ens01.csv')
234 #grp<-vector(mode='integer',length=nrow(tot))
236 #grp[246:nrow(tot)]<-2
238 #prof<-BuildProf01(tot,grp)
242 #outp<-AsLexico(prof)
243 #chistabletot<-outp[[2]]
246 #l<-vector(mode='integer',length=nrow(prof))
247 #for (line in 1:nrow(prof)) {
248 # l[line]<-as.integer(which.max(prof[line,1:2]))
251 #chistabletot<-chistabletot[1:ncol(ministre),]
252 #print(nrow(chistabletot))
253 #sc<-colSums(as.matrix(ministre))
257 #ministre<-ministre[,outc]
258 #print(ncol(ministre))
259 #prof<-BuildProf01(ministre,grp)
260 #outp<-AsLexico(prof)
261 #chistabletot<-outp[[2]]
262 #chistabletot<-chistabletot[outc,]
263 #print(nrow(chistabletot))
264 #ave<-read.csv2('/home/pierre/workspace/iramuteq/corpus/Avenir_Alceste_1/TableUc1.csv',header=TRUE)
265 #load('/home/pierre/workspace/iramuteq/corpus/Avenir_Alceste_1/RData.RData')
266 #chistabletot<-chistabletot[1:cag,]
269 #grp<-as.character(grp[,1])
270 #titre<-c("chaudronnier","soudeur","informaticien","travail")
272 #split.screen(c(2,2))
273 #for (tab in list_data) {
281 #####################################################################
282 #suede enfance en danger
283 tot<-read.csv2('/home/pierre/fac/suede/resultats/cat_asso1_01.csv',row.names=1)
285 #prof<-BuildProf01(tab,grp[,1])
286 #outp<-AsLexico(prof)
287 #chistabletot<-outp[[2]]
289 #print('liste des classes')
290 #listclasse<-vector(mode='integer',length=ncol(tab))
291 #for (line in 1:nrow(chistabletot)) {
292 # if (max(chistabletot[line,])>0) {
293 # listclasse[line]<-as.vector(which.max(chistabletot[line,]))
295 # listclasse[line]<-3
299 #classes<-classes[1:cag]
301 #tot<-cbind(info,biblio)
302 #tot<-cbind(tot,rechdoc)
303 listclasse<-vector(mode='integer',length=ncol(dt))
304 for (line in 1:nrow(chistabletot)) {
305 if ((max(chistabletot[line,])>3.84) || (min(prof[line,])==0)) {
306 if (max(chistabletot[line,])>3.84) {
307 listclasse[line]<-as.vector(which.max(chistabletot[line,]))
309 if (min(prof[line,])==0) {
311 listclasse[line]<-as.vector(which.max(prof[line,]))
318 print('matrice de similitude')
319 mindus<-makesimi(tot)
323 #mateff<-makesimipond(ministre)
324 #mateff<-makesimi(tot)
325 #mateff<-makejac(tot)
328 #m<-as.matrix(dist(t(ministre),method='binary',upper=TRUE, diag=TRUE))
329 #m<-as.matrix(simil(ministre), method='Jaccard', upper=TRUE, diag=TRUE, by_rows=FALSE)
332 #print(length(colnames(ministre)))
333 #colnames(m)<-colnames(ministre)
334 #rownames(m)<-colnames(ministre)
335 #eff<-colSums(ministre)
336 #mateffp<-makesimi(ministre)
337 #mateffp<-makesimipond(ministre)
341 #matave<-makesimi(ministre)
347 #append(rain,'black')
348 rain<-c("green","red","white")#"yellow","pink","black")#green","blue","red","black")
349 vcol<-vector(mode='integer',length=length(eff))
350 vcolb<-vector(mode='integer',length=length(eff))
351 #classes<-classes[1:93]
353 #for (i in 1:length(eff)){
354 # vcol[i]<-rain[as.integer(classes[i])]
357 #ll<-which(effp>=0.5)
358 #for (i in which(effp>=0.5)) {
365 #print('length(vcol)')
367 #vcol[1:cchaud]<-rain[1]
368 #vcol[(cchaud+1):(cchaud+cop)]<-rain[2]
369 #vcol[(cchaud+cop+1):length(eff)]<-rain[3]
371 print('premier graph')
374 g1<-graph.adjacency(m,mode="lower",weighted=TRUE)
376 #maxtree<-maxgraph(g1)
377 #plot(maxtree, layout=layout.circle)
378 #lo<-layout.circle(g1)
380 weori<-get.edge.attribute(g1,'weight')
381 #tdel<-which(weori<3)
382 we<-(weori/max(weori))*4
383 print('arbre maximum')
386 g3<-minimum.spanning.tree(g1)
387 E(g3)$weight<-1/E(g3)$weight
392 wee<-(E(g3)$weight/max(E(g3)$weight))*10
395 #lo<-layout.kamada.kawai(g3,dim=3)
396 lo<-layout.fruchterman.reingold(g3,dim=3)
399 #lo<-layout.sphere(g3)
401 vsize<-vector(mode='integer',length=nrow(lo))
405 #g2<-delete.edges(g2,tdel-1)
410 #plot(g1,vertex.label=colnames(m),edge.width=get.edge.attribute(g1,'weight'),layout=layout.circle,vertex.shape='none')
411 #igraph.par('print.edge.attributes',TRUE)
412 #plot(g2,vertex.label=colnames(m),vertex.size=vsize,vertex.color=vcol,edge.width=we,layout=lo)#,vertex.shape='none')#,edge.label=weori)
413 #rglplot(g3,vertex.label=colnames(m),edge.width=we,vertex.size=vsize,vertex.label.color=vcol,layout=lo,vertex.shape='none')#,edge.label=weori)
415 tkplot(g3,vertex.label=colnames(m),edge.width=wee,vertex.size=wev,vertex.label.color="black",layout=lo)#,vcolb vertex.label.dist=1)#,vertex.shape='none')#,edge.label=weori)
417 #rgl.bg(sphere=FALSE,color=c("black","white"))
418 #vertex.color=vcol,vertex.label.color=vcol,edge.label=weori,
419 #rgl.viewpoint(zoom=0.6)
420 #movie3d(spin3d(axis=c(0,1,0),rpm=6),10,dir='/home/pierre/workspace/iramuteq/corpus/',movie="vero_cooc_explo",clean=TRUE,convert=TRUE,fps=20)
421 #tkplot(g1,vertex.label=colnames(m),layout=layout.circle,vertex.shape='rectangle')
422 #rglplot(g1,vertex.label=colnames(m),layout=layout.circle)
432 dm<-read.csv2('classe_mod.csv',row.names=1,header = FALSE)
434 #------------------------------------------------------
436 chimax<-as.matrix(apply(chistabletot,1,max))
437 chimax<-as.matrix(chimax[,1][1:nrow(dm)])
438 chimax<-cbind(chimax,1:nrow(dm))
439 order_chi<-as.matrix(chimax[order(chimax[,1],decreasing = TRUE),])
440 elim<-which(rownames(dm) == 'faire')
442 dm<-dm[chimax[,2][1:300],]
443 #-------------------------------------------------------
445 distm<-dist(dm,diag=TRUE)
446 distm<-as.matrix(distm)
447 g1<-graph.adjacency(distm,mode='lower',weighted=TRUE)
448 g1<-minimum.spanning.tree(g1)
449 lo<-layout.kamada.kawai(g1,dim=3)
450 mc<-rainbow(ncol(chistabletot))
451 chistabletot<-chistabletot[-elim,]
454 cc<-append(cc,which.max(chistabletot[i,]))
457 mass<-rowSums(dm)/100
458 rglplot(g1,vertex.label = rownames(dm),vertex.label.color=cc,vertex.color=cc,vertex.size = mass, layout=lo)
463 dm<-read.csv2('enseignant_simi_opi.csv',row.names=1,na.string='')
464 mat<-matrix(0,ncol=ncol(dm),nrow=ncol(dm))
465 for (i in 1:(ncol(dm)-1)) {
466 for (j in (i+1):ncol(dm)){
467 tab<-table(dm[,i],dm[,j])
469 mat[i,j]<-chi$statistic
470 mat[j,i]<-chi$statistic
473 mat<-ifelse(mat>3.84,mat,0)
474 mat<-ifelse(is.na(mat),0,mat)
475 mat<-ifelse(is.infinite(mat),0,mat)
478 if (!is.integer(tovire)){
483 if (!is.integer(tovire)) cn<-cn[-tovire]
484 g1<-graph.adjacency(mat,mode='lower',weighted=TRUE)
485 lo<-layout.fruchterman.reingold(g1,dim=2)
487 plot(g1,vertex.label=cn,vertex.size=0.1,edge.width=wei,edge.label=round(wei,2),layout=lo)
491 levels.n<-mj$levels.n
492 levelnames<-mj$levelnames
495 for (j in 1:ncol(dm)) {
496 for (i in 1:levels.n[j]) {
498 print(paste(cn[j],'\\.',sep=''))
499 levelnames[count]<-gsub(paste(cn[j],'\\.',sep=''),'',levelnames[count])