Design Resources Server |
|
||||||||||||||
IASRI | |||||||||||||||
Home |
Analysis Using SAS For ease of understanding, recode the treatments as follows:
Data
Input: {Here we call the replications as blk, Treatment as: trt and yield as yld. It may, however, be noted that one can retain the same name or can code in any other fashion}. Prepare a SAS data file using /*Creating
the SAS Data set based on the data from a block design*/ data
test; input
blk trt yld; cards; 1
1
8.9 1
2
10.65 1
3
10.6 1
4
9.15 1
5
13.0 1
6
9.8 2
1
9.3 2
2
10.5 2
3
11.25 2
4
8.9 2
5
9.91 2
6
9.95 3
1
9.2 3
2
10.1 3
3
10.25 3
4
9.3 3
5
10.14 3
6
9.95 4
1
9.1 4
2
11.05 4
3
11.50 4
4
10.3 4
5
8.85 4
6
10.2 ; options
mprint mlogic; /***********************************************************************************/ /*From
here, the testing Assumptions and analysis is started/ /************************************************************************************/ options
nodate nonumber mprint mlogic; *option
for deactivate the print date and page number; /****************************************************************************/ /*
Macro start is here, The Macros are called whenever needed
*/ %macro
start; %global
loop deg var opt brln test1; /*
Making global variable */ %let
loop = 1; %start1(test);/*
Calling start1 macro with parameter SAS data set Name i.e.
the nae given the Data section*/ %let
loop = 2; %anal(test);
/*Calling
anal macro for anlysis of data set*/ proc
iml; mm
= &norm; print
mm; run; %if
&norm = NNR or &test1 < 0.05 %then
%do;
%box(test);%start1(data1); /*
calling Box macro for transformation*/ %if
&norm = NNR or &test1 < 0.05 %then
%skilling;%else
%anal(data1);%end; %mend
start; /*End
of Macro start*/ /*************************************************************************************/ /*************************************************************************/ /*
Macro Start1 is started. in this macro we perform the
testing assumption and Accordingly
go for appropriate analysis */ %macro
start1(par); proc
iml; use test; read all into temp;nc = ncol(temp);nc =
char(nc);print nc; call
symput('deg',nc);
/*
puting no. of variable of data set in deg variable*/ %if
° = 2
%then
%let
var = trt; %else
%let
var = blk trt; /*making
the class variable for GLM*/ %t1(&par);
/*
calling the macro t1 with parameter par*/ proc
iml; use nor; read all into pn; /*performing
normality test*/ title
"Shapiro
Wilk's Test for Normality of Data"; Probability
= pn; if
probability >= 0.05
then Interpretation = "Data
is Normal at 5% level of Significance"; else
Interpretation = "Data
is Non-Normal at 5% level of Significance"; print
probability,Interpretation;/* printing the value of normality test*/ title
'
'
; %if
&norm = NR %then
%bart; %else
%levene; %mend
start1; /*
End of macro start1 */ /**************************************************************************/ /***********************************************************************************/ /*Macro
t1 is written for the testing the normality of data. */ %macro
t1(ts); %global
norm; *Declaring a global variable norm which store
normality status of data; proc
glm data = &ts noprint;
/*
Here, we call PROC glm to get the residuals of data class
&var;
based
on the design
*/ model
yld = &var; output
out = err r = ss;
run;
proc
means data = err noprint; /*Calling
PROC means to compute variance of residuals
*/ class
trt; output
out = mn var(ss)=
var; run; proc
univariate data = err normal noprint;/*Performing test for normality of residuals*/ var
ss;output out=nor probn=pnor;run; proc
iml;use nor; read all into pn; /*
Using the global variable norm to store normality */ if
pn > 0.05
then call symput('norm','NR');/*status
of data -- NR for Normal and NNR for */ else
call symput('norm','NNR'); mm
= &nnr; print
mm;/*Non-normal
*/ %mend
t1; /*
End of macro t1 */ /**************************************************************************************/ /*************************************************************************************/ /*
Macro Bart is written for the testing the homogeneity of
variances */ %macro
Bart; /*%global
evar;*/ title
"Bartlett's
Test for Homogeneity of Variances"; proc
iml;use mn; read all into m1; /*
use variances of residual variance putting it in m1
variable*/ a
=m1[2:nrow(m1),ncol(m1)-1:ncol(m1)];/*from
m1 we extracting variances and number of observations */ v
=0;ct
= 0;nchi
= 0;St
= 0; do
i = 1
to nrow(a);
/* computing pooled variance */ St
= St + (a[i,1]-1)*a[i,2]; v =
v + (a[i,1]-1); ct
= ct + 1/(a[i,1]-1); end;S
= St/v; dchi
= (1
+ (1/(3*(nrow(a)-1)))*(ct-(1/v)));
/*computing
denominator of Bartlett's chi-square statistic*/ do
i = 1
to nrow(a);nchi = nchi + (a[i,1]-1)*(log(S/a[i,2]));
end; chi
= nchi/dchi; if
chi < 0
then chi = 0; probability
= 1
- probchi(chi,(nrow(a)-1));/*computinf
chi value and prob.*/ df
= (nrow(a)-1);print
probability chi df S; /*
printing chi value, prob and degee of freedom*/ if
probability >= 0.05
then Interpretation = "Data
is Homogeneous at 5% level of Significance"; else
Interpretation = "Data
is Heterogeneous at 5% level of Significance"; print
Interpretation; /*
testing and printing interpretation/ pb
= char(probability); call
symput('test1',pb); /*putting probability to a variable
test1 for further use*/ title
'
'; %mend
bart; /*
End of macro Bart */ /***********************************************************************************/ /*****************************************************************************/ /*
Macro Levene for testing the homogeneity of variances when
data is non normal*/
%macro
levene; title
'
Levene Test for Homogeneity of variances'; proc
means data = err noprint; /*
computing median of the residuals*/ output
out = media mean = mn; class
trt;var ss;run; proc
sort data = err; /*
Sorting the residual by treatment*/ by
trt;run; proc
iml; use media; read all into lev; /*
Reading the residuals in a matrix*/ md
= lev[2:nrow(lev),]; use
err;read all into error; s
= 1; do
i = 1
to nrow(error); if
error[i,2] = s then di = di//(error[i,ncol(error)]-md[s,ncol(md)]); else
do; s = s + 1; i = i-1;end; end; if
"&opt"
= "mean"
then trt = error[,2]||di##2; else
trt = error[,2]||abs(di); create
res from trt[colname = {trt di}];append from trt; quit; proc
glm data = res outstat = problev noprint; class
trt; model
di = trt; run; proc
iml;use problev; read all into pl; Probability
= pl[2,ncol(pl)]; if
probability >= 0.05
then Interpretation = "Data
is Homogeneous at 5% level of Significance"; else
Interpretation = "Data
is Heterogeneous at 5% level of Significance"; print
probability, Interpretation; pb
= char(probability); call
symput('test1',pb); title
'
'; %mend
levene; /*
End of macro Levene */ /************************************************************************/ /**********************************************************************************/ /*
Macro Box for transformation of observations*/ %macro
Box(gh); proc
iml; use
&gh; read all into box; /*using
the SAS data set*/ z1
= any(box=0);
/*checking
for null observation*/ if
z1 = 1
then box=box[,1:ncol(box)-1]||(box[,ncol(box)]+
0.01);/*adding
0.01 to each observation*/ gm
= 0;s
= 1/nrow(box); do
i = 1
to nrow(box);gm = gm + log(box[i,ncol(box)]);end; gm=gm*(s);gm
= exp(gm); /*computing
Geometric mean*/ if
° = 2
then x = design(box[,1]);/*making
design matrix*/ else
x = design(box[,1])||design(box[,2]); i
= -1000;sse
=0; sp
= 9999999999999999999999999999; do
j = -10
to 10
by 0.01; if
i = 0 then ny = gm#(log(box[,ncol(box)])); /*transforming
observations*/ else
ny = ((box[,ncol(box)]##(i/100))-1)/((i/100)*(gm**((i/100)-1))); bh
= ginv(x`*x)*x`*ny; /*computing parameters*/ err
= ny - x*bh; err
= err##2; sse = err[+]; /*computing Error sum of squares*/ if
sp > sse then lamda = i/100;
/*testing minimum
SSE for Lambda value */ sp
= sse;se = se//sse; /*making
the array of all SSE*/ l
=l//(i/100);i = i+1; end; mn
= min(se); /*taking
minimum value of SSE */ print
lamda; /*printing
Lambda*/ t2
= box[,1:ncol(box)-1]||box[,ncol(box)]##lamda;
/*
Transforming the data */ create
data1 from t2[colname ={&var yld}];append from t2; /* Creating a SAS data Set*/ %mend
box; /*
End of Macro Box*/ /**********************************************************************************/ /**********************************************************************************/ /*
Macro anal for analysis of experimental data. */ %macro
anal(dat);/*
dat is name of dataset*/ title
"
"; proc
glm data = &dat; /*
data = mane which is in dat variable **/ class
&var; /*input variable is assigned in var*/ model
yld = &var; run; %mend
anal; /*
end of macro anal */ /*****************************************************************************/ /******************************************************************************/ /*Macro
skillings is for the performing Skillings and Mack
non-parametric test*/
%macro
skilling; title
'Skilling
Macs Non-parametric procedure for testing equality of means';
%if
° = 3
%then
%do;
/*
checking for design */ proc
rank data = test out = er; /*Arranging
the yield
observation in ascending order*/ by
blk;var yld;run;
/* by Block variable */ proc
iml;use er; read all into s; /*Using
sorted variable */ RT
= j(max(S[,1]),max(S[,2]),.);T
= j(max(S[,1]),max(S[,2]),.); ST
= j(max(S[,1]),max(S[,2]),1);
/*
Creating 3 matrix according to need */ do
i = 1
to nrow(s);RT[s[i,1],s[i,2]]=s[i,3];T[s[i,1],s[i,2]]=s[i,2];end; DO
I = 1
TO nrow(rt);do j = 1
to ncol(rt);if t[i,j] = .
then st[i,j] = 0;end;end; k
= st[,+];Ai = 0; do
j = 1
to ncol(rt);do i = 1
to nrow(rt); if
rt[i,j] <> .
then Ai = Ai + (((12/(k[i]+1))**(1/2))*((rt[i,j]-(k[i]+1)/2)));end; As
= as//ai;ai = 0;end; ds
= 0;sigma
= j(ncol(t),ncol(t),0); do
i = 1
to ncol(t); do j = 1
to ncol(t);do p = 1
to nrow(t); ti
= any(t[p,]=i);tt = any(t[p,]=j); if
ti = 1
&& tt = 1
then sigma[i,j] = sigma[i,j]+1; end;end;end; sigma
= sigma#-1; do
i = 1
to ncol(t);sigma[i,i] = (sigma[i,+]-sigma[i,i])#-1;end; df=round(trace(ginv(sigma)*sigma));stat
= as`*ginv(sigma)*as; prob
= 1
- probchi(stat,df); print
stat prob df ; quit;%end; %else
%do; proc
npar1way wilcoxon data=test;
/*
performing Krushkal Walis test*/
class trt;
var yld; run;
%end; %mend
skilling; /*end
of macro skilling */ /*****************************************************************************/ /************************************************************************************/ %start;
Home Descriptive Statistics Tests of Significance Correlation and Regression Completely Randomised Design RCB Design Incomplete Block Design Resolvable Block Design Augmented Design Latin Square Design Factorial RCB Design Partially Confounded Design Factorial Experiment with Extra Treatments Split Plot Design Strip Plot Design Response Surface Design Cross Over Design Analysis of Covariance Diagnostics and Remedial Measures Principal Component Analysis Cluster Analysis Groups of Experiments Non-Linear Models
Copyright Disclaimer How to Quote this page Report Error Comments/suggestions |
||||||||||||||
Descriptive Statistics | |||||||||||||||
Tests of Significance | |||||||||||||||
Correlation and Regression | |||||||||||||||
Completely Randomised Design | |||||||||||||||
RCB Design | |||||||||||||||
Incomplete Block Design | |||||||||||||||
Resolvable Block Design | |||||||||||||||
Augmented Design | |||||||||||||||
Latin Square Design | |||||||||||||||
Factorial RCB Design | |||||||||||||||
Partially Confounded Design | |||||||||||||||
Factorial Experiment with Extra Treatments | |||||||||||||||
Split Plot Design | |||||||||||||||
Strip Plot Design | |||||||||||||||
Response Surface Design | |||||||||||||||
Cross Over Design | |||||||||||||||
Analysis of Covariance | |||||||||||||||
Diagnostics and Remedial Measures | |||||||||||||||
Principal Component Analysis | |||||||||||||||
Cluster Analysis | |||||||||||||||
Groups of Experiments | |||||||||||||||
Non-Linear Models | |||||||||||||||
Contact Us | |||||||||||||||
Other
Designed Experiments (Under Development) |
|||||||||||||||
For
exposure on SAS, SPSS, Please see Module I of Electronic Book II: Advances in Data Analytical Techniques available at Design Resource Server(www.iasri.res.in/design) |
|||||||||||||||