/* generazione di un campione da una distribuzione normale con media e varianza date */ data normvar; keep x w; n=10000; scale=7; mx=100; do i=1 to n; x=rannor(1)*scale+mx; w=4*x-300; output; end; run; *proc print data=normvar; *run; /* verifica della normalità, istogramma con bins prefissati, */ proc univariate data=normvar normal plot mu0=100; var x w; histogram x / midpercents endpoints = 70 to 130 by 5; run; /* Plot della distribuzione normale teorica */ proc univariate data=normvar mu0=100; histogram x / normal(percents=2.5 20 40 60 80 95 97.5 midpercents mu=100 sigma=7) endpoints = 70 to 130 by 5; *le opzioni di normal richiedono i percentili osservati e stimati con i parametri dati; inset n='Sample size' std='Std Dev' (5.2) normal(ksdpval); *ksdpval: kolmogorov-smirnov edf test pvalue; qqplot x / normal(mu=100 sigma=7) square ctext=red; run; /* Plot della cdf normale teorica */ proc univariate data=normvar noprint; cdf x / normal(mu=100 sigma=7); * cdf x / normal; inset n mean (5.2) std (5.2); run; /* Confidence interval per media sotto l'assunzione di normalità */ proc univariate data=normvar cibasic(alpha=0.05) loccount mu0=100 ; var x ; run; proc format; value classix low-95='<95' 95-103='95-103' 103-high='>103'; value classiw low-70='<70' 70-high='>70'; run; proc freq data=normvar; format x classix. w classiw.; tables x w; run; /* probnorm(x)=probability that an observation from the standard normal distribution is less than or equal to x */ data _null_; file print; x=probnorm(1.96); put x; y= probnorm(1.645); put y; run; data _null_; file print; p103_95=probnorm((103-100)/7)-probnorm((95-100)/7); * prob(9570); put p70; run; /* la funzione quantile determina il quantile di una distribuzione teorica quando si specifica la CDF Returns the quantile from a distribution when you specify the left probability (CDF) */ /* QUANTILE('DISTRNAME', probability, parameter1, …, parameterk) */ data _null_; file print; y=quantile('NORMAL', 0.975); z=quantile('NORMAL', 0.95); put y z; run; data _null_; file print; x95=quantile('NORMAL', 0.95,100,7); x05=quantile('NORMAL', 0.05,100,7); x50=quantile('NORMAL', 0.50,100,7); put x95 x05 x50; run;