Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %macro grubbs(dataset ,var ,id,alpha =0.05);
- ods select none;
- proc means data=&dataset mean var n;
- var &var;
- output out=out mean=mean var=var n=n;
- run;
- data outliers;
- set &dataset(keep=&id &var);
- if _n_=1 then set out;
- /* statistic */u = abs((&var - mean) / sqrt(var));
- /* critical value */t = quantile ("t", &alpha / (2*n), n-2);
- c = (n-1) * sqrt(t**2 / (n * (t**2 + n - 2)));
- /* check if this is an outlier */if(u > c) then outlier = "yes";
- else outlier = "no";
- /* p-value */u_inv = u*sqrt((n-2)*n) / sqrt(1 - (u**2-(n-2))*n);
- p_value = min (2*n*(1-cdf("t", u_inv , n-2)), 1);
- keep &id p_value u c outlier;
- run;
- proc sort data=outliers;
- by descending u;
- run;
- ods select all;
- title1 "Grubbs test";
- title2 "Variable: &var";
- proc print data=outliers(obs =1) label noobs;
- var &id p_value u c outlier;
- label &id="id" p_value ="p-value" u=" statistic (|u|)"c=" critical value"outlier ="is outlier ?";
- run;
- title;
- %mend;
- /* ================ EXAMPLE ============================*/
- libname SASDATA "/folders/myfolders ";
- data IVFTransformed;
- set SASDATA.IVF;
- TTP_transformed = SQRT(TTP);
- run;
- %grubbs(dataset=IVFTransformed,var=TTP_transformed,id=ID,alpha=0.05);
- /* ================= CHECK FOR ASSUMPTIONS ============== */
- /*If the data is normal distributed */
- PROC UNIVARIATE DATA=IVF4monthTTP NORMAL;
- VAR TTP_transformed;
- PROBPLOT TTP_transformed /NORMAL(MU=est SIGMA=est);
- RUN;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement