<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/25388941?origin\x3dhttps://wildthoughtsfaq.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>
MWave 468x60

Lakaw is a journey is a step is a move. I love to travel around the world and this is my travel and travel gadget site. Welcome and Enjoy!

0 comments | Thursday, July 03, 2008

Multivariate Statistics. SAS program code for Discriminant Analysis for Two Groups. SAS software has a procedure "PROC DISCRIM" for performing Discriminant Analysis. The procedure can create a linear discriminant function for a given dataset. The linear discriminant function can be used to classify new observations to one of the two available populations.

Discriminant analysis is sometimes know as classification analysis. It can be used to build rules that can classify new observations into two or more labeled classes. The emphasis is on deriving a rule that can be used to optimally assign new observations to the labeled classes.

Suppose there are two populations, each of them has p variables and follows a multivariate normal distribution. Suppose a new observation vector is known to come from either population 1 or population 2. A rule is needed that can be used to predict from which of the two populations the new observation vector is most likely to have come. The most commonly used discriminant rule for two populations is the linear discriminant function rule.

Run the sample SAS program for Discriminant Analysis below:
****

dm log 'clear';
dm output 'clear';
options nodate;
data Twogroups;
input Groups X1 X2 X3 X4 X5 X6 @@;
datalines;
1 242.0 23.2 25.4 30.0 38.4 13.4
1 290.0 24.0 26.3 31.2 40.0 13.8
1 340.0 23.9 26.5 31.1 39.8 15.1
1 363.0 26.3 29.0 33.5 38.0 13.3
1 500.0 26.8 29.7 34.5 41.1 15.3
1 390.0 27.6 30.0 35.0 36.2 13.4
1 98.0 17.5 18.8 21.2 26.3 13.7
1 340.0 23.9 26.5 31.1 39.8 15.1
1 450.0 27.6 30.0 35.1 39.9 13.8
1 500.0 28.5 30.7 36.2 39.3 13.7
1 475.0 28.4 31.0 36.2 39.4 14.1
1 500.0 28.7 31.0 36.2 39.7 13.3
2 40.0 12.9 14.1 16.2 25.6 14.0
2 69.0 16.5 18.2 20.3 26.1 13.9
2 78.0 17.5 18.8 21.2 26.3 13.7
2 187.0 18.2 19.8 22.2 25.3 14.3
2 150.0 20.4 22.0 24.7 23.5 15.2
2 145.0 20.5 22.0 24.3 27.3 14.6
2 160.0 20.5 22.5 25.3 27.8 15.1
2 140.0 21.0 22.5 25.0 26.2 13.3
2 160.0 21.1 22.5 25.0 25.6 15.2
2 169.0 22.0 24.0 27.2 27.7 14.1
;
proc discrim data=Twogroups list crosslist;
class Groups;
title 'Discriminant Analysis for Two Groups';
run;
quit;

****

Leave me a comment if you have questions.

Acknowledgments goes to Weiming Ke, PhD (SDSU, Department of Mathematics and Statistics).

Labels:

Continue Reading >>>

0 comments | Friday, May 30, 2008

The sample SAS program codes for basic statistics given below would compute the mean, median, variance, standard deviation, stem-and-leaf plot, box plot, and normal probability plot for each given variable.

A given dataset is use as an example.

*****
dm log 'clear';
dm output 'clear';

data Example;
input ID X1 X2 X3 X4;
datalines;
1 16 27 32 35
2 19 10 35 38
3 17 28 33 36
4 18 22 31 33
5 22 18 34 38
;
proc univariate data=Example plot;
var X1-X4 ;
title 'Summary Statistics';
run;
quit;

2. Correlation coefficients between each pair of the variables can be obtained by using the following procedure:

proc corr data=Example;
var X1-X4 ;
title2 'Correlation Coefficients';
run;
quit;

3. Three-dimension and two-dimension scatter plots of the data can be obtained by using the following procedures:

dm log 'clear';
dm output 'clear';

data Ex;
input ID X1 X2 X3;
datalines;
1 27 32 35
2 10 35 38
3 28 33 36
4 22 31 43
5 29 38 34
6 14 39 41
7 25 36 37
8 23 30 39
;
proc g3d data=Ex;
scatter x1*x2=x3;
title '3-D scatter plot';
run;

proc gplot data=Ex;
plot x2*x1;
plot x3*x1;
plot x3*x2;
title '2-D scatter plot';
run;
quit;

3-D and 2-D scatter plots can be used to display the data.

The 2-D scatter plot can be used to check the correlation between two variables. An apparent trend of the 2-D scatter plot indicates a strong correlation between two variables.
*****

Thanks to SDSU Math Department.

Labels:

Continue Reading >>>

2 comments | Friday, May 02, 2008

Here is a SAS program code for the Factor Analysis function. Please leave me a comment if you need Factor Analysis results interpretation, I might interpret the results for you, for free :-)

Factor analysis is a data reduction technique. It is used to simplify complex and diverse relationships that exist among a set of observed variables by uncovering common factors. It provides an insight into the underlying structure of the data. The common factor models express each observable variable in terms of unobservable common factors that link together the seemingly unrelated variables.

The purpose of a factor analysis is to develop a new set of uncorrelated variables, called underlying factors, or common factors, with the hope that these new variables will give a better understanding of the data being analyzed. These new variables can then be used in future analyses of the data.

SAS software has a procedure "PROC FACTOR" for performing Factor Analysis. The procedure can also create a new set of data that contains the values of the factor scores. This new dataset can be used for later data analysis.

--------
Run the SAS program for Factor Analysis in the following example and explain the results such as how to choose the appropriate number of common factors and report the communalities. The Factor Pattern in the SAS output contains the values of the factor loadings. They are used for solving the factor equations to get the factor scores.

*****

dm log 'clear';
dm output 'clear';
options nodate;

data FA;
input ID X1 X2 X3 X4 X5 X6 X7 X8 ;
datalines;
1 6 7 2 5 8 7 8 8
2 9 10 5 8 10 9 9 10
3 7 8 3 6 9 8 9 7
4 5 6 8 5 6 5 9 2
5 6 8 8 8 4 4 9 5
6 7 7 7 6 8 7 10 5
7 9 9 8 8 8 8 8 8
8 9 9 9 8 9 9 8 8
9 9 9 7 8 8 8 8 5
10 4 7 10 2 10 10 7 10
11 4 7 10 0 10 8 3 9
12 4 7 10 4 10 10 7 8
13 6 9 8 10 5 4 9 4
14 8 9 8 9 6 3 5 1
15 4 8 8 7 5 4 10 2
16 6 9 6 7 8 9 8 9
17 8 7 7 7 9 5 8 6
18 6 8 8 4 8 8 6 4
19 6 7 8 4 7 8 5 4
20 4 8 7 8 8 9 10 5
;
PROC factor DATA=FA METHOD=Principal scree;
VAR X1--X8;
TITLE'Factor Analysis';
TITLE2'Scree Plot of Eigenvalues';
RUN;

PROC factor DATA=FA METHOD=Principal nfactors=3 score OUT=scores;
VAR X1--X8;
TITLE2'Computing the Values of the First Three Factor Scores';
RUN;

PROC PRINT DATA=scores;
VAR ID factor1 factor2 factor3;
TITLE2 'Displaying the Values of the First Three Factor Scores';
run;
quit;

*****

Labels:

Continue Reading >>>

4 comments

Principal Components Analysis (PCA) - SAS statistics code.

The basic objective of a PCA is to discover new variables called principal components, which are in decreasing order of importance, so that

1. They are uncorrelated.
2. The first principal component accounts for as much of the variability in the data as possible.
3. Each succeeding component accounts for as much of the remaining variability as possible.

Here is a SAS program for Principal Components Analysis (PCA). You can run the code with the given data below and interpret the results.

******
dm log 'clear';
dm output 'clear';
options nodate;

data PCA;
input X1 X2 X3 X4 X5 X6 X7 X8;
datalines;
6 7 2 5 8 7 8 8

9 10 5 8 10 9 9 10

7 8 3 6 9 8 9 7

5 6 8 5 6 5 9 2

6 8 8 8 4 4 9 5

7 7 7 6 8 7 10 5

9 9 8 8 8 8 8 8

9 9 9 8 9 9 8 8

9 9 7 8 8 8 8 5

4 7 10 2 10 10 7 10

4 7 10 0 10 8 3 9

4 7 10 4 10 10 7 8

6 9 8 10 5 4 9 4

8 9 8 9 6 3 8 2

4 8 8 7 5 4 10 2
6 9 5 7 8 9 8 9

8 7 7 7 9 5 8 6

6 8 8 4 8 8 6 4

6 7 8 4 7 8 5 4

4 8 7 8 8 9 10 5

;

PROC PRINCOMP DATA=PCA OUT=PCSCORES COVARIANCE;
VAR X1--X8;
title 'Principal Component Analysis';
RUN;


PROC FACTOR DATA=PCA scree;
VAR X1--X8;

TITLE2'Scree Plot of Eigenvalues';
RUN;

PROC PRINT DATA=PCSCORES;
VAR PRIN1 PRIN2 PRIN3;
TITLE2 'VALUES OF THE FIRST THREE PRINCIPAL COMPONENT SCORES';
RUN;


proc univariate data=pcscores plot;
var prin1 prin2;
TITLE2 'Univariate Analysis on the first two Principal Components';

run;

proc gplot DATA=PCSCORES;
plot prin2*prin1;
TITLE2 'A Scatter Plot of the First Two Principal Component Scores';

run;

quit;

*****
If you would like to have the SAS interpretation of PCA, please leave me a comment.

Labels:

Continue Reading >>>

Related Posts with Thumbnails