Régionales 2015/RCode : Différence entre versions

De WikiUpLib
Aller à : navigation, rechercher
(Page créée avec « <code> #=============================================================================== # (c) V. Andres 2015-2016 http://uplib.fr - R.2.13.1 # source('F:/wd/iteLast/ut... »)
 
 
Ligne 1 : Ligne 1 :
  
<code>
+
<pre>
 
#===============================================================================
 
#===============================================================================
 
# (c)  V. Andres 2015-2016 http://uplib.fr - R.2.13.1
 
# (c)  V. Andres 2015-2016 http://uplib.fr - R.2.13.1
Ligne 58 : Ligne 58 :
 
#write.table(CircoTable, NewFile, sep='\t', quote=F); #, row.names=F, col.names=F);
 
#write.table(CircoTable, NewFile, sep='\t', quote=F); #, row.names=F, col.names=F);
 
}
 
}
</code>
+
</pre>

Version actuelle datée du 23 décembre 2015 à 11:58

#===============================================================================
# (c)  V. Andres 2015-2016 http://uplib.fr - R.2.13.1
# 

source('F:/wd/iteLast/utils/stat.r');

#===============================================================================
# Fonction utilisateur
# input : fichier des résultats par circonscriptions bruts, tel que fournis par le ministère
# output: des corrélations

SomeCors = function(mdd=NA)
{
CircoFile = 'I:/RUplib/Elections/circonscriptions.csv';
info = NULL;
info[1] = paste(date(), CircoFile);
cat(info[1], '\n');

CircoTable = read.table(CircoFile, header=TRUE, sep=',', as.is=T, row.names=1, check.names=F);
#print(colnames(CircoTable)[60:80]);

CircoTable = CircoTable[2:nrow(CircoTable),];      #2° ligne contient encore des noms de colonnes (abrégés)
#CircoTable = CircoTable[2:(nrow(CircoTable)-17),]; #17 derniers departements outre-mer sans candidats FN
info[2] = paste('dim(CircoTable)=',dim(CircoTable)[1],dim(CircoTable)[2]);
cat(info[2], '\n');

TheCols = matrix(0, nrow=nrow(CircoTable), ncol=7);
colnames(TheCols) = c('LUG','LUD','LFN','Abs','Blancs','Nuls','B+N');

TheCols[,'LUG']    = as.numeric(CircoTable[,"Voix Nuance Liste LUG"])/as.numeric(CircoTable[,"Inscrits"]);
TheCols[,'LUD']    = as.numeric(CircoTable[,"Voix Nuance Liste LUD"])/as.numeric(CircoTable[,"Inscrits"]);
TheCols[,'LFN']    = as.numeric(CircoTable[,"Voix Nuance Liste LFN"])/as.numeric(CircoTable[,"Inscrits"]);
TheCols[,'Abs']    = as.numeric(CircoTable[,"% Abs/Ins"])/100.00;
TheCols[,'Blancs'] = as.numeric(CircoTable[,"% Blancs/Ins"])/100.00;
TheCols[,'Nuls']   = as.numeric(CircoTable[,"% Nuls/Ins"])/100.00;
TheCols[,'B+N']     = (TheCols[,'Blancs'] + TheCols[,'Nuls'])/2;

cormat = cor(TheCols[,1:3], TheCols[,4:7]);
print(round(cormat,2));

cormat = cor(TheCols, TheCols);
print(round(cormat,2));

info[3] = paste('critical cor value for',nrow(TheCols),'points and alpha=0.01 : ', round(critcc(nrow(TheCols),alpha=0.01),2));
cat(info[3], '\n');

plot(TheCols[,'B+N'],TheCols[,'LFN'], main=CircoFile, xlab='',ylab='', type='n');
points(TheCols[,'B+N'],TheCols[,'LFN'], main=CircoFile, xlab='',ylab='', pch='+');
title(xlab='(Blancs+Nuls)/Inscrits', ylab='FN/Inscrits');
texte = paste('Uplib.fr :',Sys.Date(),':', nrow(TheCols), 'points (circonscriptions), cor=',round(cormat['LFN','B+N'],2));
mtext(texte, col='blue');
maxx = max(TheCols[,'B+N']);
maxy = max(TheCols[,'LFN']);
text(0.7*maxx, 0, pos=4, 'Régionales déc. 2015', offset=0, cex=0.7);

#write.table(CircoTable, NewFile, sep='\t', quote=F); #, row.names=F, col.names=F);
}