Statistiques, M2-IAD:MI5

Documents pareils
Transcription:

Statistiques, M2-IAD:MI5 Francois.Kauffmann@unicaen.fr 5 octobre 2011 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 1 / 63

Première partie I Le Graphisme Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 2 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 3 / 63

SAS/Graph : la procédure de graphisme Ce module permet de tracer des graphes haute résolution en pouvant utiliser plusieurs types de sorties graphiques : Les procédures les plus utilisées : tracé de ligne, points, textes. gchart diagramme en bâtons gmap tracer de cartes insight graphisme par menu définition des options graphiques combiner plusieurs sorties graphiques redirection des sorties vers un fichier graphique Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 4 / 63

Graphisme : plot et /* plot et */ %include i:\users\francois\tex\stat\sas\exemples\data-table-classe.sas ; proc plot data=class; plot height*weight; title Trace texte hauteur en fonction du poids ; run; /* */ proc data=class; plot height*weight; title Trace hauteur en fonction du poids ; run; /* et en fonction du sexe */ proc data=class; plot height*weight=sex; title Trace hauteur en fonction du poids ; run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 5 / 63

Graphisme : plot Trace texte hauteur en fonction du poids 15:58 Monday, January 12, 2004 1 Plot of hauteur*poids. Legend: A = 1 obs, B = 2 obs, etc. hauteur 75 A 70 A A B 65 A A A A A A A 60 A A A A A A 55 A 50 3 100 120 140 40 60 80 160 poids Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 6 / 63

h a u t e u r 8 0 Graphisme : 7 0 6 0 5 0 5 0 6 0 7 0 8 0 9 0 1 0 0 1 1 0 1 2 0 1 3 0 1 4 0 1 5 0 p o i d s Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 7 / 63

Graphisme : gchart /* diagramme en batons */ proc gchart data=classe gout=graphique; vbar hauteur; title Histogramme des hauteurs ; run; /* vbar y subgroup=x histo supperposés*/ Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 8 / 63

F R E Q U E N C Y 6 5 Graphisme : gchart 4 3 2 1 0 5 2. 5 5 7. 5 6 2. 5 6 7. 5 7 2. 5 h a u t e u r M I D P O I N T Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 9 / 63

/* gmap*/ data dpts; do id=1 to 100; val=2*id; output; end; run; proc gmap map=maps.france data=dpts; id id; choro val; title Trace de carte ; run; quit; Graphisme : gmap Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 10 / 63

Graphisme : gmap Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 11 / 63

/* plot scatterplot */ proc plot data=classe vpercent=33 hpercent=33 nolegend ; plot (age hauteur poids ) * (age hauteur poids ) = sexe; run; Graphisme : scatterplot /* insight SAS/Insight Statements*/ PROC INSIGHT DATA=user.classe; SCATTER age hauteur poids*age hauteur poids; title Scatterplot ; run;quit; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 12 / 63

1 1 a g e Graphisme : scatterplot 1 6 7 2. 0 h a u t e u r 5 1. 3 1 5 0. 0 p o i d s 5 0. 5 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 13 / 63

/* g3d */ data chapeau; do x=-5 to 5 by 0.25; do y=-5 to 5 by 0.25; z=sin(sqrt(x*x+y*y)); output; end; end; run; proc g3d data=chapeau gout=graphique ; plot y*x=z; title Exemple de trace 3d chapeau ; run; quit; Graphisme : g3d Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 14 / 63

Graphisme : g3d Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 15 / 63

Graphisme : Le but de cette procédure est de traduire, de réunir différents graphiques d un même catalogue. /* */ filename psdir "I:\users\Francois\TEX\stat\SAS\ps"; hsize=20cm vsize=20cm gsfname=psdir device=pslepsfc; proc igout=graphique nofs; replay _ALL_; run; quit; /* reset */ reset=all; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 16 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 17 / 63

Les instructions globales quit ferme les fichiers graphiques options des procédures graphiques title[n] titre des graphiques legend[n] légendes footnote[n] pied de page des graphiques axis[n] définition d un axe d affichage symbol[n] définition d un type trait ou points Remarque : 1 n 10 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 18 / 63

Cette instruction permet de définir les options graphiques de SAS.. La syntaxe de l instruction est : par1=val1 par2=val2...; Pour ré initialiser un paramètre : par1=; Pour tout réinitialiser : reset=all; Pour voir un paramètre graphique on peut utiliser : proc option=nom_option;run; Pour voir toutes les options graphiques : proc ;run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 19 / 63

device=(win,gif,png,pslepsfc,psepsf) gsfname=fichier display nodisplay body=rep htex=n ctext=(red,...) ftext=(swiss,...) ftitle=(swiss,...) reset=all rotate=(landscape,portrait) border noborder path=rep périphérique de sortie nom du ou des fichiers de sorties sortie écran pas de sortie écran répertoire racine en cas de sortie html hauteur de la fonte couleur de la fonte police du texte police du titre paramètres par defaut paysage ou portrait bord dans l image pas de bord racine des répertoires en sortie html Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 20 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 21 / 63

Les types de traits Ils sont définis par l intermédiaire d une variable globale symbol[n].ce symbole sera utilisé comme type de trait par le premier tracé d une fonction symbol[n] symbole numéro n ci=(red,...) couleur de la ligne c=(blue,...) couleur des symboles v=(square,...) symbole dessiné height=n hauteur du symbole interpol=join interpolation affine l=(1,2...,46) 2 à 46 pointillé w=(1,...) ; épaisseur du trait symbol[n] ; réinitialisation (sans option) Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 22 / 63

symbol1 width=1 v=square interpol=join color=red ci=blue; PROC GPLOT DATA=SINUS; PLOT Y*X=1; /* symbol1 utilisé */ TITLE Graphe de y=xsin(2x);test symbol ; run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 23 / 63

Y 4 3 Graphisme : symbol 2 1 0-1 - 2-3 0 1 2 3 4 5 X Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 24 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 25 / 63

Les définitions d axes Ils sont définis par l intermédiaire d une variable globale axe[n]. axis[n] axe numéro n width=n épaisseur du trait order=xinf to xsup by pas tirets sur l axe order=(x1... xn) place tirets label=(angle=90 rotate=0 texte ) tracé de légende minor=(none,...) tirets intermédiaires color=(red,...) couleur de l axe Attention dans order= les espaces entre les points sur la figure sont égaux : (0,1,1000)! Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 26 / 63

axis1 width=5 order=(0 2.5 5) label=(angle=0 rotate=0) minor=none color=purple; PROC GPLOT DATA=SINUS; PLOT Y*X/haxis=axis1; TITLE Graphe de y=xsin(2x);test axis ; run; PROC GPLOT DATA=SINUS; PLOT Y*X/ haxis=0 to 5 by 2.5 vaxis=-4 to 4 by 2; TITLE Graphe de y=xsin(2x);test axis ; run; Axis Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 27 / 63

Y 4 3 Graphisme : axis 2 1 0-1 - 2-3 0. 0 2. 5 5. 0 X Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 28 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 29 / 63

Procédure Les options principales de la procédure sont : proc data=lib.x nom de la table utilisée gout=lib.catalogue ; nom du catalogue de sortie instruction 1 ;... instruction n ; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 30 / 63

Gplot :instuction plot L instruction de la procédure est principalement l instruction plot (et aussi bubble). Cette instruction permet de dessiner y en fonction de x avec le trait défini par le symbole n. On trace des points qui sont fonctions de la variable mentionnée après le signe = : plot y1*x1[=n var] trait symbole n y2*x2[=n var]... / début des options de plot option1... ; fin de l instruction plot Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 31 / 63

overlay annotate=lib.x descrition= titre name=toto cframe=salmon caxis=red ctext=green vaxis=axis1 haxis=axis2 href=y0 vref=x0 legend=legend[n] autovref Gplot : options de plot superposition table d annotation titre ds fen resultat nom de l elt dans le catalogue couleur du fond couleur des axes couleur du texte axe vertical défini par axis1 axe horizontal défini par axis2 trait horizontal y=y0 trait vertical x=x0 légende pour le tracé met une ligne hori sur chaque barre de l axe vert Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 32 / 63

/*hauteur(poids) sexe */ proc data=classe; plot hauteur*poids=sexe/ cframe=yellow /* fond */ href=100 /* trait vertical x=100*/ vref=70 /* trait horizontal y=70*/ description="essai"; run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 33 / 63

h a u t e u r 8 0 Graphisme : 7 0 6 0 5 0 5 0 6 0 7 0 8 0 9 0 1 0 0 1 1 0 1 2 0 1 3 0 1 4 0 1 5 0 p o i d s s e x e F M Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 34 / 63

Graphisme : :overlay L option OVERLAY de l instruction plot permet de superposer plusieurs tracé de courbes sur une même figure. %include I:\users\francois\tex\stat\SAS\exemples\data-table-classe.sas ; proc data=class; plot height*age= H weight*age= W / OVERLAY vaxis=50 TO 150 by 50 haxis=10 TO 15 by 1; run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 35 / 63

h e i g h t 1 5 0 Graphisme : :overlay W W W W 1 0 0 W W W W W W W W H H H H H H H H H H H H 5 0 W 1 0 1 1 1 2 1 3 1 4 1 5 a g e Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 36 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 37 / 63

Table d annotation La table d annotation permet d ajouter à un graphisme du texte,des traits.chaque ligne de cette table correspond à une instuction graphique, les autres valeurs sont les arguments de cette instruction. function move bar draw symbol label fonction appelée x abscisse y ordonnée xsys 2 unité définie par l axe des x ysys 2 unité définie par l axe des y color couleur line type de trait text chaine à afficher Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 38 / 63

: : annotate data boussole; length c $5; x=1;y=0;c="est";output; x=0;y=1;c="nord";output; x=-1;y=0;c="ouest";output; x=0;y=-1;c="sud";output; data annotate; length function $6 text $10 color $10; set boussole(rename=(x=x1 y=y1)); xsys= 2 ;ysys= 2 ; function= move ;x=0;y=0;output; function= draw ;x=x1;y=y1;color= red ;line=3;output; function= label ;x=x1;y=y1;text=c;color= red ;output; function= symbol ;x=x1;y=y1;color= blue ;text= CIRCLE ;size=5;output; keep function xsys ysys x y text color line size; proc data=boussole; plot y*x/annotate=annotate; run; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 39 / 63

y 1 Graphisme : : annotate N o r d O0 u e s t E s t - 1 S u d - 1 0 1 x Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 40 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 41 / 63

Manipulation des sorties de SAS On veut avoir des sorties de résultats ou graphiques sous différents rtf rich text format pdf texte d image ps,gif,png format Web html Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 42 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 43 / 63

Ouput delivery system Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 44 / 63

: global statement L instruction globale output delivery system, permet de traduire de rediriger des sorties textes et graphiques de SAS, dans des spécifiques. texte la sortie standard de la fenêtre de log est dite au format listing. On peut avoir aussi des sorties dans des fichiers au format rtf ou html. graphique on peut avoir des fichiers au format postscript,gif,... correspondant au objets graphiques de catalogues. Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 44 / 63

/* sortie log vers fichier texte */ Ods : sortie texte listing file="i:\users\francois\tex\stat\sas\html\sinus.txt"; proc print data=sinus(obs=10);run; listing close; /* réouverture sortie texte dans log */ listing; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 45 / 63

Ods :sortie texte The SAS System 15:26 Monday, January 19, 2004 13 Obs X Y 1 0.00 0.00000 2 0.05 0.00499 3 0.10 0.01987 4 0.15 0.04433 5 0.20 0.07788 6 0.25 0.11986 7 0.30 0.16939 8 0.35 0.22548 9 0.40 0.28694 10 0.45 0.35250 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 46 / 63

/* sortie vers fichier pdf */ Ods : sortie pdf pdf file="i:\users\francois\tex\stat\sas\html\sinus.pdf"; proc print data=sinus(obs=10);run; pdf close; quit; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 47 / 63

/* sortie vers fichier rtf */ Ods : sortie rtf rtf file="i:\users\francois\tex\stat\sas\html\sinus.rtf"; proc print data=sinus(obs=10);run; rtf close; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 48 / 63

/* attention bug dans SAS v8.2 SAS.CFG 1- option -PATH mettre la ligne sasaext0/dbcs/sasexe apres /sasroot/core/sasexe 2- options -NODBCS au lieu de DBCS */ data test; x=1;y="bonjour ";output; x=2;y="au revoir";output; run; Ods : sortie html /* sortie print -> html */ html body="i:\users\francois\tex\stat\sas\html\test.htm"; proc print data=test;run; html close; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 49 / 63

Ods : graphique sortie html /* sortie print graphique -> html */ filename output i:\users\francois\tex\stat\sas\html ; device=html /* driver html */ gsfname=output /* répertoire de sortie fichiers graphiques*/ transparency /* image gif en mode transparent */ noborder /* pas de bordure */ ; title "pages html et graphique"; html path=output /* repertoire de sortie fichiers html */ body="index.htm" /* nom du fichier racine */ ; title1 "inclusion d un graphique"; proc data=sinus; plot y*x; run; title1 "inclusion d un résultat"; proc means data=classe; run; html close; quit; device=win; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 50 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 51 / 63

/* sortie graphique ps */ : graphique sortie ps filename fichier "i:\users\francois\tex\stat\sas\html\sinus.ps"; device=pslepsfc gsfname=fichier; proc data=sinus; plot y*x/ description="essai Ps"; run; quit; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 52 / 63

/* sortie graphique png */ : graphique sortie png filename fichier "i:\users\francois\tex\stat\sas\html\sinus.png"; device=png gsfname=fichier; proc data=sinus; plot y*x/ description="essai Png"; run; quit; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 53 / 63

/* sortie graphique gif */ : graphique sortie gif filename fichier "i:\users\francois\tex\stat\sas\html\test.gif"; device=gif gsfname=fichier; proc data=sinus; plot y*x/ description="essai Gif"; run; quit; /* fermeture des fichiers */ Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 54 / 63

Les options graphiques Les symboles Les axes La procédure GPLOT Les tables d annotation graphiques Formats graphiques La procédure Paragraphe Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 55 / 63

Le but de cette procédure est de traduire ou réunir différents graphiques d un même catalogue. /* */ filename psdir "I:\users\Francois\TEX\stat\SAS\ps"; hsize=20cm vsize=20cm gsfname=psdir device=pslepsfc; proc igout=graphique nofs; replay _ALL_; run; quit; /* reset */ reset=all; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 56 / 63

/* */ filename psdir "I:\users\Francois\TEX\stat\SAS\ps"; hsize=20cm vsize=20cm gsfname=psdir device=pslepsfc; proc igout=user.gseg nofs; replay _LAST_; run; quit; reset=all; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 57 / 63

/* découper écran en 3 parties */ data table; do x=0 to 10 by.01; y1=x*sin(x); y2=x**2*sin(x); output; end; run; symbol1 interpol=join; symbol2 interpol=join; symbol3 interpol=join; proc gout=figures; plot y1*x /name= y1_x ; plot y2*x /name= y2_x ; plot y2*y1 /name= y2_y1 ; run; filename fichier "I:\users\francois\tex\stat\SAS\ps\gr--template.eps"; gsfname=fichier device=pslepsfc; proc igout=figures nofs tc=sashelp.templt template=h3; treplay 1: y1_x 2: y2_x 3: y2_y1 ; run; quit; reset=all; Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 58 / 63

8 7 6 5 4 3 2 1 0 x 0 x 0 Graphisme y 1 y 2 7 0 6 0 5 0 4 0 y 2 7 0 6 0 5 0 4 0 3 0 3 0 2 0 2 0 1 0 1 0-1 - 1 0-1 0-2 - 2 0-2 0-3 - 3 0-3 0-4 - 4 0-4 0-5 - 5 0-5 0-6 - 6 0 0 1 2 3 4 5 6 7 8 9 1 0 0 1 2 3 4 5 6 7 8 9 1 0-6 0-6 - 5-4 - 3-2 - 1 0 1 2 3 4 5 6 7 8 y 1 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 59 / 63

Index Deuxième partie II Index Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 60 / 63

Index Index I device gif, 55 png, 54 ps, 53 all, 57 last, 58 Graphisme annotate exemple, 39 axis, 26 exemple, 27 g3d exemple, 14 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 61 / 63

Index gchart exemple, 8 gmap exemple, 10, 19 exemple, 16 option, 20 overlay, 35 exemple, 16 template, 59 scatterplot exemple, 12 symbol, 22 exemple, 23 Index II Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 62 / 63

Index Index III exemples graphique, 51 html, 50 listing, 46 pdf, 48 rtf, 49 Francois.Kauffmann@unicaen.fr Statistiques, M2-IAD:MI5 5 octobre 2011 63 / 63