12.07.2015 Views

Introduction to Multivariate Methods

Introduction to Multivariate Methods

Introduction to Multivariate Methods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10<strong>Multivariate</strong> <strong>Methods</strong>• “<strong>Introduction</strong> <strong>to</strong> <strong>Multivariate</strong> <strong>Methods</strong>” on page 10-2• “Multidimensional Scaling” on page 10-3• “Procrustes Analysis” on page 10-14• “Feature Selection” on page 10-23• “Feature Transformation” on page 10-28


10 <strong>Multivariate</strong> <strong>Methods</strong><strong>Introduction</strong> <strong>to</strong> <strong>Multivariate</strong> <strong>Methods</strong>Large, high-dimensional data sets are common in the modern eraof computer-based instrumentation and electronic data s<strong>to</strong>rage.High-dimensional data present many challenges for statistical visualization,analysis, and modeling.Data visualization, of course, is impossible beyond a few dimensions. As aresult, pattern recognition, data preprocessing, and model selection mustrely heavily on numerical methods.A fundamental challenge in high-dimensional data analysis is the so-calledcurse of dimensionality. Observations in a high-dimensional space arenecessarily sparser and less representative than those in a low-dimensionalspace. In higher dimensions, data over-represent the edges of a samplingdistribution, because regions of higher-dimensional space contain the majorityof their volume near the surface. (A d-dimensional spherical shell has avolume, relative <strong>to</strong> the <strong>to</strong>tal volume of the sphere, that approaches 1 as dapproaches infinity.) In high dimensions, typical data points at the interior ofa distribution are sampled less frequently.Often, many of the dimensions in a data set—the measured features—arenot useful in producing a model. Features may be irrelevant or redundant.Regression and classification algorithms may require large amounts ofs<strong>to</strong>rageandcomputationtime<strong>to</strong>process raw data, and even if the algorithmsare successful the resulting models may contain an incomprehensible numberof terms.Because of these challenges, multivariate statistical methods often begin withsome type of dimension reduction, in which data are approximated by pointsin a lower-dimensional space. Dimension reduction is the goal of the methodspresented in this chapter. Dimension reduction often leads <strong>to</strong> simpler modelsand fewer measured variables, with consequent benefits when measurementsare expensive and visualization is important.10-2


Multidimensional ScalingMultidimensional ScalingIn this section...“<strong>Introduction</strong> <strong>to</strong> Multidimensional Scaling” on page 10-3“Classical Multidimensional Scaling” on page 10-3“Nonclassical Multidimensional Scaling” on page 10-8“Nonmetric Multidimensional Scaling” on page 10-10<strong>Introduction</strong> <strong>to</strong> Multidimensional ScalingOne of the most important goals in visualizing data is <strong>to</strong> get a sense of hownear or far points are from each other. Often, you can do this with a scatterplot. However, for some analyses, the data that you have might not be inthe form of points at all, but rather in the form of pairwise similarities ordissimilarities between cases, observations, or subjects. There are no points<strong>to</strong> plot.Even if your data are in the form of points rather than pairwise distances,a scatter plot of those data might not be useful. For some kinds of data,the relevant way <strong>to</strong> measure how near two points are might not be theirEuclidean distance. While scatter plots of the raw data make it easy <strong>to</strong>compare Euclidean distances, they are not always useful when comparingother kinds of inter-point distances, city block distance for example, or evenmore general dissimilarities. Also, with a large number of variables, it is verydifficult <strong>to</strong> visualize distances unless the data can be represented in a smallnumber of dimensions. Some sort of dimension reduction is usually necessary.Multidimensional scaling (MDS) is a set of methods that address all theseproblems. MDS allows you <strong>to</strong> visualize how near points are <strong>to</strong> each otherfor many kinds of distance or dissimilarity metrics and can produce arepresentation of your data in a small number of dimensions. MDS does notrequire raw data, but only a matrix of pairwise distances or dissimilarities.Classical Multidimensional Scaling• “<strong>Introduction</strong> <strong>to</strong> Classical Multidimensional Scaling” on page 10-410-3


10 <strong>Multivariate</strong> <strong>Methods</strong>• “Example: Multidimensional Scaling” on page 10-6<strong>Introduction</strong> <strong>to</strong> Classical Multidimensional ScalingThe function cmdscale performs classical (metric) multidimensional scaling,also known as principal coordinates analysis. cmdscale takesasaninputamatrix of inter-point distances and creates a configuration of points. Ideally,those points are in two or three dimensions, and the Euclidean distancesbetween them reproduce the original distance matrix. Thus, a scatter plo<strong>to</strong>f the points created by cmdscale provides a visual representation of theoriginal distances.As a very simple example, you can reconstruct a set of points from only theirinter-point distances. First, create some four dimensional points with a smallcomponent in their fourth coordinate, and reduce them <strong>to</strong> distances.X = [ normrnd(0,1,10,3), normrnd(0,.1,10,1) ];D = pdist(X,'euclidean');Next, use cmdscale <strong>to</strong> find a configuration with those inter-point distances.cmdscale accepts distances as either a square matrix, or, as in this example,in the vec<strong>to</strong>r upper-triangular form produced by pdist.[Y,eigvals] = cmdscale(D);cmdscale produces two outputs. The first output, Y, is a matrix containing thereconstructed points. The second output, eigvals, is a vec<strong>to</strong>r containing thesorted eigenvalues of what is often referred <strong>to</strong> as the “scalar product matrix,”which, in the simplest case, is equal <strong>to</strong> Y*Y'. The relative magnitudes of thoseeigenvalues indicate the relative contribution of the corresponding columns ofY in reproducing the original distance matrix D with the reconstructed points.format short g[eigvals eigvals/max(abs(eigvals))]ans =12.623 14.3699 0.346181.9307 0.152950.025884 0.00205051.7192e-015 1.3619e-0166.8727e-016 5.4445e-01710-4


Multidimensional Scaling4.4367e-017 3.5147e-018-9.2731e-016 -7.3461e-017-1.327e-015 -1.0513e-016-1.9232e-015 -1.5236e-016If eigvals contains only positive and zero (within round-off error) eigenvalues,the columns of Y corresponding <strong>to</strong> the positive eigenvalues provide an exactreconstruction of D, in the sense that their inter-point Euclidean distances,computed using pdist, for example, are identical (within round-off) <strong>to</strong> thevalues in D.maxerr4 = max(abs(D - pdist(Y))) % exact reconstructionmaxerr4 =2.6645e-015If two or three of the eigenvalues in eigvals are much larger than the rest,then the distance matrix based on the corresponding columns of Y nearlyreproduces the original distance matrix D. In this sense, those columnsform a lower-dimensional representation that adequately describes thedata. However it is not always possible <strong>to</strong> find a good low-dimensionalreconstruction.% good reconstruction in 3Dmaxerr3 = max(abs(D - pdist(Y(:,1:3))))maxerr3 =0.029728% poor reconstruction in 2Dmaxerr2 = max(abs(D - pdist(Y(:,1:2))))maxerr2 =0.91641The reconstruction in three dimensions reproduces D very well, but thereconstruction in two dimensions has errors that are of the same order ofmagnitude as the largest values in D.max(max(D))ans =3.468610-5


10 <strong>Multivariate</strong> <strong>Methods</strong>Often, eigvals contains some negative eigenvalues, indicating that thedistances in D cannot be reproduced exactly. That is, there might not be anyconfiguration of points whose inter-point Euclidean distances are given byD. If the largest negative eigenvalue is small in magnitude relative <strong>to</strong> thelargest positive eigenvalues, then the configuration returned by cmdscalemight still reproduce D well.Example: Multidimensional ScalingGiven only the distances between 10 US cities, cmdscale can construct a mapof those cities. First, create the distance matrix and pass it <strong>to</strong> cmdscale.In this example,D is a full distance matrix: it is square and symmetric, haspositive entries off the diagonal, and has zeros on the diagonal.cities = ...{'Atl','Chi','Den','Hou','LA','Mia','NYC','SF','Sea','WDC'};D = [ 0 587 1212 701 1936 604 748 2139 2182 543;587 0 920 940 1745 1188 713 1858 1737 597;1212 920 0 879 831 1726 1631 949 1021 1494;701 940 879 0 1374 968 1420 1645 1891 1220;1936 1745 831 1374 0 2339 2451 347 959 2300;604 1188 1726 968 2339 0 1092 2594 2734 923;748 713 1631 1420 2451 1092 0 2571 2408 205;2139 1858 949 1645 347 2594 2571 0 678 2442;2182 1737 1021 1891 959 2734 2408 678 0 2329;543 597 1494 1220 2300 923 205 2442 2329 0];[Y,eigvals] = cmdscale(D);Next, look at the eigenvalues returned by cmdscale. Some of these arenegative, indicating that the original distances are not Euclidean. This isbecause of the curvature of the earth.format short g[eigvals eigvals/max(abs(eigvals))]ans =9.5821e+006 11.6868e+006 0.176048157.3 0.00085131432.9 0.00014954508.67 5.3085e-00525.143 2.624e-00610-6


Multidimensional Scaling5.3394e-010 5.5722e-017-897.7 -9.3685e-005-5467.6 -0.0005706-35479 -0.0037026However, in this case, the two largest positive eigenvalues are much largerin magnitude than the remaining eigenvalues. So, despite the negativeeigenvalues, the first two coordinates of Y are sufficient for a reasonablereproduction of D.Dtriu = D(find(tril(ones(10),-1)))';maxrelerr = max(abs(Dtriu-pdist(Y(:,1:2))))./max(Dtriu)maxrelerr =0.0075371Here is a plot of the reconstructed city locations as a map. The orientation ofthe reconstruction is arbitrary. In this case, it happens <strong>to</strong> be close <strong>to</strong>, althoughnot exactly, the correct orientation.plot(Y(:,1),Y(:,2),'.')text(Y(:,1)+25,Y(:,2),cities)xlabel('Miles')ylabel('Miles')10-7


10 <strong>Multivariate</strong> <strong>Methods</strong>Nonclassical Multidimensional ScalingThe function mdscale performs nonclassical multidimensional scaling. Aswith cmdcale, youusemdscale either <strong>to</strong> visualize dissimilarity data for whichno “locations” exist, or <strong>to</strong> visualize high-dimensional data by reducing itsdimensionality. Both functions take a matrix of dissimilarities as an inputand produce a configuration of points. However, mdscale offers a choice ofdifferent criteria <strong>to</strong> construct the configuration, and allows missing data andweights.For example, the cereal data include measurements on 10 variables describingbreakfast cereals. You can use mdscale <strong>to</strong> visualize these data in twodimensions. First, load the data. For clarity, this example code selects asubset of 22 of the observations.load cereal.matX = [Calories Protein Fat Sodium Fiber ...Carbo Sugars Shelf Potass Vitamins];10-8


Multidimensional Scaling% Take a subset from a single manufacturermfg1 = strcmp('G',cellstr(Mfg));X = X(mfg1,:);size(X)ans =22 10Then use pdist <strong>to</strong> transform the 10-dimensional data in<strong>to</strong> dissimilarities.The output from pdist is a symmetric dissimilarity matrix, s<strong>to</strong>red as a vec<strong>to</strong>rcontaining only the (23*22/2) elements in its upper triangle.dissimilarities = pdist(zscore(X),'cityblock');size(dissimilarities)ans =1 231This example code first standardizes the cereal data, and then uses city blockdistance as a dissimilarity. The choice of transformation <strong>to</strong> dissimilarities isapplication-dependent, and the choice here is only for simplicity. In someapplications, the original data are already in the form of dissimilarities.Next, use mdscale <strong>to</strong> perform metric MDS. Unlike cmdscale, youmustspecify the desired number of dimensions, and the method <strong>to</strong> use <strong>to</strong> constructthe output configuration. For this example, use two dimensions. The metricSTRESS criterion is a common method for computing the output; for otherchoices, see the mdscale reference page in the online documentation. Thesecond output from mdscale is the value of that criterion evaluated for theoutput configuration. It measures the how well the inter-point distances ofthe output configuration approximate the original input dissimilarities:[Y,stress] =...mdscale(dissimilarities,2,'criterion','metricstress');stressstress =0.1856A scatterplot of the output from mdscale represents the original10-dimensional data in two dimensions, and you can use the gname function <strong>to</strong>label selected points:plot(Y(:,1),Y(:,2),'o','LineWidth',2);10-9


10 <strong>Multivariate</strong> <strong>Methods</strong>gname(Name(mfg1))Nonmetric Multidimensional ScalingMetric multidimensional scaling creates a configuration of points whoseinter-point distances approximate the given dissimilarities. This is sometimes<strong>to</strong>o strict a requirement, and non-metric scaling is designed <strong>to</strong> relax it a bit.Instead of trying <strong>to</strong> approximate the dissimilarities themselves, non-metricscaling approximates a nonlinear, but mono<strong>to</strong>nic, transformation of them.Because of the mono<strong>to</strong>nicity, larger or smaller distances on a plot of theoutput will correspond <strong>to</strong> larger or smaller dissimilarities, respectively.However, the nonlinearity implies that mdscale only attempts <strong>to</strong> preserve the10-10


Multidimensional Scalingordering of dissimilarities. Thus, there may be contractions or expansions ofdistances at different scales.You use mdscale <strong>to</strong> perform nonmetric MDS in much the same way as formetric scaling. The nonmetric STRESS criterion is a common method forcomputing the output; for more choices, see the mdscale reference page inthe online documentation. As with metric scaling, the second output frommdscale is the value of that criterion evaluated for the output configuration.For nonmetric scaling, however, it measures the how well the inter-pointdistances of the output configuration approximate the disparities. Thedisparities are returned in the third output. They are the transformed valuesof the original dissimilarities:[Y,stress,disparities] = ...mdscale(dissimilarities,2,'criterion','stress');stressstress =0.1562To check the fit of the output configuration <strong>to</strong> the dissimilarities, and <strong>to</strong>understand the disparities, it helps <strong>to</strong> make a Shepard plot:distances = pdist(Y);[dum,ord] = sortrows([disparities(:) dissimilarities(:)]);plot(dissimilarities,distances,'bo', ...dissimilarities(ord),disparities(ord),'r.-', ...[0 25],[0 25],'k-')xlabel('Dissimilarities')ylabel('Distances/Disparities')legend({'Distances' 'Disparities' '1:1 Line'},...'Location','NorthWest');10-11


10 <strong>Multivariate</strong> <strong>Methods</strong>This plot shows that mdscale has found a configuration of points in twodimensions whose inter-point distances approximates the disparities, whichin turn are a nonlinear transformation of the original dissimilarities. Theconcave shape of the disparities as a function of the dissimilarities indicatesthat fit tends <strong>to</strong> contract small distances relative <strong>to</strong> the correspondingdissimilarities. This may be perfectly acceptable in practice.mdscale uses an iterative algorithm <strong>to</strong> find the output configuration, andthe results can often depend on the starting point. By default, mdscaleuses cmdscale <strong>to</strong> construct an initial configuration, and this choice oftenleads <strong>to</strong> a globally best solution. However, it is possible for mdscale <strong>to</strong>s<strong>to</strong>p at a configuration that is a local minimum of the criterion. Such10-12


Multidimensional Scalingcases can be diagnosed and often overcome by running mdscale multipletimes with different starting points. You can do this using the 'start'and 'replicates' parameters. The following code runs five replicates ofMDS, each starting at a different randomly-chosen initial configuration.The criterion value is printed out for each replication; mdscale returns theconfiguration with the best fit.opts = statset('Display','final');[Y,stress] =...mdscale(dissimilarities,2,'criterion','stress',...'start','random','replicates',5,'Options',opts);35 iterations, Final stress criterion = 0.15620931 iterations, Final stress criterion = 0.15620948 iterations, Final stress criterion = 0.17120933 iterations, Final stress criterion = 0.17534132 iterations, Final stress criterion = 0.185881Notice that mdscale finds several different local solutions, some of whichdo not have as low a stress value as the solution found with the cmdscalestarting point.10-13


10 <strong>Multivariate</strong> <strong>Methods</strong>Procrustes AnalysisIn this section...“Comparing Landmark Data” on page 10-14“Data Input” on page 10-14“Preprocessing Data for Accurate Results” on page 10-15“Example: Comparing Handwritten Shapes” on page 10-16Comparing Landmark DataThe procrustes function analyzes the distribution of a set of shapes usingProcrustes analysis. This analysis method matches landmark data (geometriclocations representing significant features in a given shape) <strong>to</strong> calculate thebest shape-preserving Euclidian transformations. These transformationsminimize the differences in location between compared landmark data.Procrustes analysis is also useful in conjunction with multidimensionalscaling. In “Example: Multidimensional Scaling” on page 10-6 there is anobservation that the orientation of the reconstructed points is arbitrary. Twodifferent applications of multidimensional scaling could produce reconstructedpoints that are very similar in principle, but that look different because theyhave different orientations. The procrustes function transforms one set ofpoints <strong>to</strong> make them more comparable <strong>to</strong> the other.Data InputThe procrustes function takes two matrices as input:• The target shape matrix X has dimension n × p, wheren is the numberof landmarks in the shape and p is the number of measurements perlandmark.• The comparison shape matrix Y has dimension n × q with q ≤ p. Ifthereare fewer measurements per landmark for the comparison shape thanthe target shape (q < p), the function adds columns of zeros <strong>to</strong> Y, yieldingan n × p matrix.The equation <strong>to</strong> obtain the transformed shape, Z, is10-14


Procrustes AnalysisZ = bYT + c(10-1)where:• b is a scaling fac<strong>to</strong>r that stretches (b >1)orshrinks(b


10 <strong>Multivariate</strong> <strong>Methods</strong>Example: Comparing Handwritten ShapesIn this example, use Procrustes analysis <strong>to</strong> compare two handwritten numberthrees. Visually and analytically explore the effects of forcing size andreflection changes as follows:• “Step 1: Load and Display the Original Data” on page 10-16• “Step 2: Calculate the Best Transformation” on page 10-17• “Step 3: ExaminetheSimilarityoftheTwoShapes”onpage10-18• “Step 4: Restrict the Form of the Transformations” on page 10-20Step 1: Load and Display the Original DataInput landmark data for two handwritten number threes:A = [11 39;17 42;25 42;25 40;23 36;19 35;30 34;35 29;...30 20;18 19];B = [15 31;20 37;30 40;29 35;25 29;29 31;31 31;35 20;...29 10;25 18];Create X and Y from A and B, moving B <strong>to</strong>theside<strong>to</strong>makeeachshapemorevisible:X = A;Y = B + repmat([25 0], 10,1);Plot the shapes, using letters <strong>to</strong> designate the landmark points. Lines in thefigure join the points <strong>to</strong> indicate the drawing path of each shape.plot(X(:,1), X(:,2),'r-', Y(:,1), Y(:,2),'b-');text(X(:,1), X(:,2),('abcdefghij')')text(Y(:,1), Y(:,2),('abcdefghij')')legend('X = Target','Y = Comparison','location','SE')set(gca,'YLim',[0 55],'XLim',[0 65]);10-16


Procrustes AnalysisStep 2: Calculate the Best TransformationUse Procrustes analysis <strong>to</strong> find the transformation that minimizes distancesbetween landmark data points.Call procrustes as follows:[d, Z, tr] = procrustes(X,Y);The outputs of the function are:• d – A standardized dissimilarity measure.)• Z – A matrix of the transformed landmarks.• tr – A structure array of the computed transformation with fields T, b, andc which correspond <strong>to</strong> the transformation equation, Equation 10-1.10-17


10 <strong>Multivariate</strong> <strong>Methods</strong>Visualize the transformed shape, Z, using a dashed blue line:plot(X(:,1), X(:,2),'r-', Y(:,1), Y(:,2),'b-',...Z(:,1),Z(:,2),'b:');text(X(:,1), X(:,2),('abcdefghij')')text(Y(:,1), Y(:,2),('abcdefghij')')text(Z(:,1), Z(:,2),('abcdefghij')')legend('X = Target','Y = Comparison',...'Z = Transformed','location','SW')set(gca,'YLim',[0 55],'XLim',[0 65]);Step 3: Examine the Similarity of the Two ShapesUse two different numerical values <strong>to</strong> assess the similarity of the target shapeand the transformed shape.10-18


Procrustes AnalysisDissimilarity Measure d. The dissimilarity measure d gives a numberbetween 0 and 1 describing the difference between the target shape and thetransformed shape. Values near 0 imply more similar shapes, while valuesnear 1 imply dissimilarity. For this example:d =0.1502The small value of d in this case shows that the two shapes are similar.procrustes calculates d by comparing the sum of squared deviations betweenthe set of points with the sum of squared deviations of the original points fromtheir column means:numera<strong>to</strong>r = sum(sum((X-Z).^2))numera<strong>to</strong>r =166.5321denomina<strong>to</strong>r = sum(sum(bsxfun(@minus,X,mean(X)).^2))denomina<strong>to</strong>r =1.1085e+003ratio = numera<strong>to</strong>r/denomina<strong>to</strong>rratio =0.1502Note The resulting measure d is independent of the scale of the size ofthe shapes and takes in<strong>to</strong> account only the similarity of landmark data.“Examining the Scaling Measure b” on page 10-19 shows how <strong>to</strong> examine thesize similarity of the shapes.Examining the Scaling Measure b. The target and comparison threes inthe previous figure visually show that the two numbers are of a similar size.The closeness of calculated value of the scaling fac<strong>to</strong>r b <strong>to</strong> 1 supports thisobservation as well:10-19


10 <strong>Multivariate</strong> <strong>Methods</strong>tr.bans =0.9291The sizes of the target and comparison shapes appear similar. This visualimpression is reinforced by the value of b = 0.93, which implies that the besttransformation results in shrinking the comparison shape by a fac<strong>to</strong>r .93(only 7%).Step 4: Restrict the Form of the TransformationsExplore the effects of manually adjusting the scaling and reflectioncoefficients.Fixing the Scaling Fac<strong>to</strong>r b =1. Force b <strong>to</strong> equal 1 (set 'Scaling' <strong>to</strong>false) <strong>to</strong> examine the amount of dissimilarity in size of the target andtransformed figures:ds = procrustes(X,Y,'Scaling',false)ds =0.1552In this case, setting 'Scaling' <strong>to</strong> false increases the calculated value ofd only 0.0049, which further supports the similarity in the size of the twonumber threes. A larger increase in d would have indicated a greater sizediscrepancy.Forcing a Reflection in the Transformation. This example requires only arotation, not a reflection, <strong>to</strong> align the shapes. You can show this by observingthat the determinant of the matrix T is 1 in this analysis:det(tr.T)ans =1.0000Ifyouneedareflectioninthetransformation, the determinant of T is -1. Youcan force a reflection in<strong>to</strong> the transformation as follows:[dr,Zr,trr] = procrustes(X,Y,'Reflection',true);drdr =10-20


Procrustes Analysis0.8130The d value increases dramatically, indicating that a forced reflection leads<strong>to</strong> a poor transformation of the landmark points. A plot of the transformedshape shows a similar result:• The landmark data points are now further away from their targetcounterparts.• The transformed three is now an undesirable mirror image of the targetthree.plot(X(:,1), X(:,2),'r-', Y(:,1), Y(:,2),'b-',...Zr(:,1),Zr(:,2),'b:');text(X(:,1), X(:,2),('abcdefghij')')text(Y(:,1), Y(:,2),('abcdefghij')')text(Zr(:,1), Zr(:,2),('abcdefghij')')legend('X = Target','Y = Comparison',...'Z = Transformed','location','SW')set(gca,'YLim',[0 55],'XLim',[0 65]);10-21


10 <strong>Multivariate</strong> <strong>Methods</strong>It appears that the shapes might be better matched if you flipped thetransformed shape upside down. Flipping the shapes would make thetransformation even worse, however, because the landmark data pointswould be further away from their target counterparts. From this example,it is clear that manually adjusting the scaling and reflection parameters isgenerally not optimal.10-22


Feature SelectionFeature SelectionIn this section...“<strong>Introduction</strong> <strong>to</strong> Feature Selection” on page 10-23“Sequential Feature Selection” on page 10-23<strong>Introduction</strong> <strong>to</strong> Feature SelectionFeature selection reduces the dimensionality of data by selecting only a subse<strong>to</strong>f measured features (predic<strong>to</strong>r variables) <strong>to</strong> create a model. Selection criteriausually involve the minimization of a specific measure of predictive error formodels fit <strong>to</strong> different subsets. Algorithms search for a subset of predic<strong>to</strong>rsthat optimally model measured responses, subject <strong>to</strong> constraints such asrequired or excluded features and the size of the subset.Feature selection is preferable <strong>to</strong> feature transformation when the originalunits and meaning of features are important and the modeling goal is <strong>to</strong>identify an influential subset. When categorical features are present, andnumerical transformations are inappropriate, feature selection becomes theprimary means of dimension reduction.Sequential Feature Selection• “<strong>Introduction</strong> <strong>to</strong> Sequential Feature Selection” on page 10-23• “Example: Sequential Feature Selection” on page 10-24<strong>Introduction</strong> <strong>to</strong> Sequential Feature SelectionA common method of feature selection is sequential feature selection. Thismethod has two components:• An objective function, called the criterion, which the method seeks <strong>to</strong>minimize over all feasible feature subsets. Common criteria are meansquared error (for regression models) and misclassification rate (forclassification models).• A sequential search algorithm, which adds or removes features from acandidate subset while evaluating the criterion. Since an exhaustive10-23


10 <strong>Multivariate</strong> <strong>Methods</strong>comparison of the criterion value at all 2 n subsets of an n-feature data setis typically infeasible (depending on the size of n and the cost of objectivecalls), sequential searches move in only one direction, always growing oralways shrinking the candidate set.Themethodhastwovariants:• Sequential forward selection (SFS), in which features are sequentiallyadded<strong>to</strong>anemptycandidatesetuntiltheadditionoffurtherfeaturesdoesnot decrease the criterion.• Sequential backward selection (SBS), in which features are sequentiallyremoved from a full candidate set until the removal of further featuresincrease the criterion.Stepwise regression is a sequential feature selection technique designedspecifically for least-squares fitting. The functions stepwise and stepwisefitmake use of optimizations that are only possible with least-squares criteria.Unlike generalized sequential feature selection, stepwise regression mayremove features that have been added or add features that have been removed.The Statistics Toolbox function sequentialfs carries out sequential featureselection. Input arguments include predic<strong>to</strong>r and response data and a functionhandle <strong>to</strong> a file implementing the criterion function. Optional inputs allowyou <strong>to</strong> specify SFS or SBS, required or excludedfeatures,andthesizeofthefeature subset. The function calls cvpartition and crossval <strong>to</strong> evaluate thecriterion at different candidate sets.Example: Sequential Feature SelectionFor example, consider a data set with 100 observations of 10 predic<strong>to</strong>rs.The following generates random data from a logistic model, with a binomialdistribution of responses at each set of values for the predic<strong>to</strong>rs. Somecoefficients are set <strong>to</strong> zero so that not all of the predic<strong>to</strong>rs affect the response:n = 100;m = 10;X = rand(n,m);b = [1 0 0 2 .5 0 0 0.1 0 1];Xb = X*b';p = 1./(1+exp(-Xb));10-24


Feature SelectionN = 50;y = binornd(N,p);The glmfit function fits a logistic model <strong>to</strong> the data:Y = [y N*ones(size(y))];[b0,dev0,stats0] = glmfit(X,Y,'binomial');% Display coefficient estimates and their standard errors:model0 = [b0 stats0.se]model0 =0.3115 0.25960.9614 0.1656-0.1100 0.1651-0.2165 0.16831.9519 0.18090.5683 0.2018-0.0062 0.17400.0651 0.1641-0.1034 0.16850.0017 0.18150.7979 0.1806% Display the deviance of the fit:dev0dev0 =101.2594This is the full model, using all of the features (and an initial constant term).Sequential feature selection searches for a subset of the features in the fullmodel with comparative predictive power.First, you must specify a criterion for selecting the features. The followingfunction, which calls glmfit and returns the deviance of the fit (ageneralization of the residual sum of squares) is a useful criterion in this case:function dev = critfun(X,Y)[b,dev] = glmfit(X,Y,'binomial');You should create this function as a file on the MATLAB path.10-25


10 <strong>Multivariate</strong> <strong>Methods</strong>The function sequentialfs performs feature selection, calling the criterionfunction via a function handle:maxdev = chi2inv(.95,1);opt = statset('display','iter',...'TolFun',maxdev,...'TolTypeFun','abs');inmodel = sequentialfs(@critfun,X,Y,...'cv','none',...'nullmodel',true,...'options',opt,...'direction','forward');Start forward sequential feature selection:Initial columns included: noneColumns that can not be included: noneStep 1, used initial columns, criterion value 309.118Step 2, added column 4, criterion value 180.732Step 3, added column 1, criterion value 138.862Step 4, added column 10, criterion value 114.238Step 5, added column 5, criterion value 103.503Final columns included: 1 4 5 10The iterative display shows a decrease in the criterion value as each newfeature is added <strong>to</strong> the model. The final result is a reduced model with onlyfour of the original ten features: columns 1, 4, 5, and10 of X. These featuresare indicated in the logical vec<strong>to</strong>r inmodel returned by sequentialfs.The deviance of the reduced model is higher than for the full model, butthe addition of any other single feature would not decrease the criterionby more than the absolute <strong>to</strong>lerance, maxdev, set in the options structure.Adding a feature with no effect reduces the deviance by an amount that hasa chi-square distribution with one degree of freedom. Adding a significantfeature results in a larger change. By setting maxdev <strong>to</strong> chi2inv(.95,1), youinstruct sequentialfs <strong>to</strong> continue adding features so long as the change indeviance is more than would be expected by random chance.The reduced model (also with an initial constant term) is:[b,dev,stats] = glmfit(X(:,inmodel),Y,'binomial');10-26


Feature Selection% Display coefficient estimates and their standard errors:model = [b stats.se]model =0.0784 0.16421.0040 0.15921.9459 0.17890.6134 0.18720.8245 0.173010-27


10 <strong>Multivariate</strong> <strong>Methods</strong>Feature TransformationIn this section...“<strong>Introduction</strong> <strong>to</strong> Feature Transformation” on page 10-28“Nonnegative Matrix Fac<strong>to</strong>rization” on page 10-28“Principal Component Analysis (PCA)” on page 10-31“Fac<strong>to</strong>r Analysis” on page 10-45<strong>Introduction</strong> <strong>to</strong> Feature TransformationFeature transformation is a group of methods that create new features(predic<strong>to</strong>r variables). The methods are useful for dimension reduction whenthe transformed features have a descriptive power that is more easily orderedthan the original features. In this case, less descriptive features can bedropped from consideration when building models.Feature transformation methods are contrasted with the methods presentedin “Feature Selection” on page 10-23, where dimension reduction is achievedby computing an optimal subset of predictive features measured in theoriginal data.The methods presented in this section share some common methodology.Their goals, however, are essentially different:• Nonnegative matrix fac<strong>to</strong>rization is used when model terms must representnonnegative quantities, such as physical quantities.• Principal component analysis is used <strong>to</strong> summarize data in fewerdimensions, for example, <strong>to</strong> visualize it.• Fac<strong>to</strong>r analysis is used <strong>to</strong> build explana<strong>to</strong>ry models of data correlations.Nonnegative Matrix Fac<strong>to</strong>rization• “<strong>Introduction</strong> <strong>to</strong> Nonnegative Matrix Fac<strong>to</strong>rization” on page 10-29• “Example: Nonnegative Matrix Fac<strong>to</strong>rization” on page 10-2910-28


Feature Transformation<strong>Introduction</strong> <strong>to</strong> Nonnegative Matrix Fac<strong>to</strong>rizationNonnegative matrix fac<strong>to</strong>rization (NMF) is a dimension-reduction techniquebased on a low-rank approximation of the feature space. Besides providinga reduction in the number of features, NMF guarantees that the featuresare nonnegative, producing additive models that respect, for example, thenonnegativity of physical quantities.Given a nonnegative m-by-n matrix X and a positive integer k


10 <strong>Multivariate</strong> <strong>Methods</strong>'algorithm','mult');rep iteration rms resid |delta x|1 10 358.296 0.001905542 10 78.3556 0.0003517473 10 230.962 0.01728394 10 326.347 0.007395525 10 361.547 0.00705539Final root mean square residual = 78.3556The 'mult' algorithm is sensitive <strong>to</strong> initial values, which makes it a goodchoice when using 'replicates' <strong>to</strong> find W and H from multiple randomstarting values.Now perform the fac<strong>to</strong>rization using an alternating least-squares algorithm,which converges faster and more consistently. Run 100 times more iterations,beginning from the initial W0 and H0 identified above:opt = statset('Maxiter',1000,'Display','final');[W,H] = nnmf(X,2,'w0',W0,'h0',H0,...'options',opt,...'algorithm','als');rep iteration rms resid |delta x|1 3 77.5315 3.52673e-005Final root mean square residual = 77.5315The two columns of W are the transformed predic<strong>to</strong>rs. The two rows of H givethe relative contributions of each of the five predic<strong>to</strong>rs in X <strong>to</strong> the predic<strong>to</strong>rsin W:HH =0.0835 0.0190 0.1782 0.0072 0.98020.0558 0.0250 0.9969 0.0085 0.0497The fifth predic<strong>to</strong>r in X (weight 0.9802) strongly influences the first predic<strong>to</strong>rin W. The third predic<strong>to</strong>r in X (weight 0.9969) strongly influences the secondpredic<strong>to</strong>r in W.Visualize the relative contributions of the predic<strong>to</strong>rs in X with a biplot,showing the data and original variables in the column space of W:10-30


Feature Transformationbiplot(H','scores',W,'varlabels',{'','','v3','','v5'});axis([0 1.1 0 1.1])xlabel('Column 1')ylabel('Column 2')Principal Component Analysis (PCA)• “<strong>Introduction</strong> <strong>to</strong> Principal ComponentAnalysis(PCA)”onpage10-31• “Example: Principal Component Analysis” on page 10-33<strong>Introduction</strong> <strong>to</strong> Principal Component Analysis (PCA)One of the difficulties inherent in multivariate statistics is the problem ofvisualizing data that has many variables. The MATLAB function plotdisplays a graph of the relationship between two variables. The plot3and surf commands display different three-dimensional views. But when10-31


10 <strong>Multivariate</strong> <strong>Methods</strong>there are more than three variables, it is more difficult <strong>to</strong> visualize theirrelationships.Fortunately, in data sets with many variables, groups of variables oftenmove <strong>to</strong>gether. One reason for this is that more than one variable might bemeasuring the same driving principle governing the behavior of the system.In many systems there are only a few such driving forces. But an abundanceof instrumentation enables you <strong>to</strong> measure dozens of system variables. Whenthis happens, you can take advantage of this redundancy of information.You can simplify the problem by replacing a group of variables with a singlenew variable.Principal component analysis is a quantitatively rigorous method for achievingthis simplification. The method generates a new set of variables, calledprincipal components. Each principal component is a linear combination ofthe original variables. All the principal components are orthogonal <strong>to</strong> eachother, so there is no redundant information. The principal components as awhole form an orthogonal basis for the space of the data.There are an infinite number of ways <strong>to</strong> construct an orthogonal basis forseveral columns of data. What is so special about the principal componentbasis?The first principal component is a single axis in space. When you projecteach observation on that axis, the resulting values form a new variable. Andthe variance of this variable is the maximum among all possible choices ofthe first axis.The second principal component is another axis in space, perpendicular <strong>to</strong>the first. Projecting the observations on this axis generates another newvariable. The variance of this variable is the maximum among all possiblechoices of this second axis.Thefullse<strong>to</strong>fprincipalcomponentsisaslargeastheoriginalse<strong>to</strong>fvariables.But it is commonplace for the sum of the variances of the first few principalcomponents <strong>to</strong> exceed 80% of the <strong>to</strong>tal variance of the original data. Byexamining plots of these few new variables, researchers often develop adeeper understanding of the driving forces that generated the original data.10-32


Feature TransformationYou can use the function princomp <strong>to</strong> find the principal components. To useprincomp, you need <strong>to</strong> have the actual measured data you want <strong>to</strong> analyze.However, if you lack the actual data, but have the sample covariance orcorrelation matrix for the data, you can still use the function pcacov <strong>to</strong>perform a principal components analysis.Seethereferencepageforpcacovfor a description of its inputs and outputs.Example: Principal Component Analysis• “Computing Components” on page 10-33• “Component Coefficients” on page 10-36• “Component Scores” on page 10-36• “Component Variances” on page 10-40• “Hotelling’s T2” on page 10-42• “Visualizing the Results” on page 10-42Computing Components. Consider a sample application that uses ninedifferent indices of the quality of life in 329 U.S. cities. These are climate,housing, health, crime, transportation, education, arts, recreation, andeconomics. For each index, higher is better. For example, a higher indexfor crime means a lower crime rate.Start by loading the data in cities.mat.load citieswhosName Size Bytes Classcategories 9x14 252 char arraynames 329x43 28294 char arrayratings 329x9 23688 double arrayThe whos command generates a table of information about all the variablesin the workspace.The cities data set contains three variables:• categories, a string matrix containing the names of the indices10-33


10 <strong>Multivariate</strong> <strong>Methods</strong>• names, a string matrix containing the 329 city names• ratings, the data matrix with 329 rows and 9columnsThe categories variable has the following values:categoriescategories =climatehousinghealthcrimetransportationeducationartsrecreationeconomicsThe first five rows of names arefirst5 = names(1:5,:)first5 =Abilene, TXAkron, OHAlbany, GAAlbany-Troy, NYAlbuquerque, NMTo get a quick impression of the ratings data, make a box plot.boxplot(ratings,'orientation','horizontal','labels',categories)This command generates the plot below. Note that there is substantiallymore variability in the ratings of the arts and housing than in the ratingsof crime and climate.10-34


Feature TransformationOrdinarily you might also graph pairs of the original variables, but there are36two-variable plots. Perhaps principal components analysis can reduce thenumber of variables you need <strong>to</strong> consider.Sometimes it makes sense <strong>to</strong> compute principal components for raw data. Thisis appropriate when all the variables are in the same units. Standardizing thedata is often preferable when the variables are in different units or when thevariance of the different columns is substantial (as in this case).You can standardize the data by dividing each column by its standarddeviation.stdr = std(ratings);sr = ratings./repmat(stdr,329,1);Now you are ready <strong>to</strong> find the principal components.10-35


10 <strong>Multivariate</strong> <strong>Methods</strong>[coefs,scores,variances,t2] = princomp(sr);The following sections explain the four outputs from princomp.Component Coefficients. The first output of the princomp function, coefs,contains the coefficients of the linear combinations of the original variablesthat generate the principal components. The coefficients are also known asloadings.The first three principal component coefficient vec<strong>to</strong>rs are:c3 = coefs(:,1:3)c3 =0.2064 0.2178 -0.69000.3565 0.2506 -0.20820.4602 -0.2995 -0.00730.2813 0.3553 0.18510.3512 -0.1796 0.14640.2753 -0.4834 0.22970.4631 -0.1948 -0.02650.3279 0.3845 -0.05090.1354 0.4713 0.6073The largest coefficients in the first column (first principal component) arethe third and seventh elements, corresponding <strong>to</strong> the variables health andarts. All the coefficients of the first principal component have the same sign,making it a weighted average of all the original variables.The principal components are unit length and orthogonal:I = c3'*c3I =1.0000 -0.0000 -0.0000-0.0000 1.0000 -0.0000-0.0000 -0.0000 1.0000Component Scores. The second output, scores, contains the coordinatesof the original data in the new coordinate system defined by the principalcomponents. This output is the same size as the input data matrix.10-36


Feature TransformationA plot of the first two columns of scores shows the ratings data projectedon<strong>to</strong> the first two principal components. princomp computes the scores <strong>to</strong>have mean zero.plot(scores(:,1),scores(:,2),'+')xlabel('1st Principal Component')ylabel('2nd Principal Component')Note the outlying points in the right half of the plot.While it is possible <strong>to</strong> create a three-dimensional plot using three columnsof scores, the examples in this section create two-dimensional plots, whichareeasier<strong>to</strong>describe.The function gname is useful for graphically identifying a few points in a plotlike this. You can call gname with a string matrix containing as many case10-37


10 <strong>Multivariate</strong> <strong>Methods</strong>labels as points in the plot. The string matrix names works for labeling pointswith the city names.gname(names)Move your cursor over the plot and click once near each point in the righthalf. As you click each point, it is labeled with the proper row from the namesstring matrix. Here is the plot after a few clicks:When you are finished labeling points, press the Return key.The labeled cities are some of the biggest population centers in the UnitedStates. They are definitely different from the remainder of the data, soperhaps they should be considered separately. To remove the labeled citiesfrom the data, first identify their corresponding row numbers as follows:10-38


Feature Transformation1 Close the plot window.2 Redraw the plot by enteringplot(scores(:,1),scores(:,2),'+')xlabel('1st Principal Component');ylabel('2nd Principal Component');3 Enter gname without any arguments.4 Click near the points you labeled in the preceding figure. This labels thepoints by their row numbers, as shown in the following figure.Then you can create an index variable containing the row numbers of allthe metropolitan areas you choose.10-39


10 <strong>Multivariate</strong> <strong>Methods</strong>metro = [43 65 179 213 234 270 314];names(metro,:)ans =Bos<strong>to</strong>n, MAChicago, ILLos Angeles, Long Beach, CANew York, NYPhiladelphia, PA-NJSan Francisco, CAWashing<strong>to</strong>n, DC-MD-VATo remove these rows from the ratings matrix, enter the following.rsubset = ratings;nsubset = names;nsubset(metro,:) = [];rsubset(metro,:) = [];size(rsubset)ans =322 9Component Variances. The third output, variances, is a vec<strong>to</strong>r containingthe variance explained by the corresponding principal component. Eachcolumn of scores has a sample variance equal <strong>to</strong> the corresponding elemen<strong>to</strong>f variances.variancesvariances =3.40831.21401.14150.92090.75330.63060.49300.31800.1204You can easily calculate the percent of the <strong>to</strong>tal variability explained by eachprincipal component.10-40


Feature Transformationpercent_explained = 100*variances/sum(variances)percent_explained =37.869913.488612.683110.23248.36987.00625.47833.53381.3378Use the pare<strong>to</strong> function <strong>to</strong> make a scree plot of the percent variabilityexplained by each principal component.pare<strong>to</strong>(percent_explained)xlabel('Principal Component')ylabel('Variance Explained (%)')10-41


10 <strong>Multivariate</strong> <strong>Methods</strong>The preceding figure shows that the only clear break in the amount ofvariance accounted for by each component is between the first and secondcomponents. However, that component by itself explains less than 40% of thevariance, so more components are probably needed. You can see that the firstthree principal components explain roughly two-thirds of the <strong>to</strong>tal variabilityin the standardized ratings, so that might be a reasonable way <strong>to</strong> reduce thedimensions in order <strong>to</strong> visualize the data.Hotelling’s T2. The last output of the princomp function,t2, isHotelling’sT 2 ,a statistical measure of the multivariate distance of each observation fromthe center of the data set. This is an analytical way <strong>to</strong> find the most extremepoints in the data.[st2, index] = sort(t2,'descend'); % Sort in descending order.extreme = index(1)extreme =213names(extreme,:)ans =New York, NYIt is not surprising that the ratings for New York are the furthest from theaverage U.S. <strong>to</strong>wn.Visualizing the Results. Use the biplot function <strong>to</strong> help visualize boththe principal component coefficients for each variable and the principalcomponent scores for each observation in a single plot. For example, thefollowing command plots the results from the principal components analysison the cities and labels each of the variables.biplot(coefs(:,1:2), 'scores',scores(:,1:2),...'varlabels',categories);axis([-.26 1 -.51 .51]);10-42


Feature TransformationEach of the nine variables is represented in this plot by a vec<strong>to</strong>r, and thedirection and length of the vec<strong>to</strong>r indicates how each variable contributes <strong>to</strong>the two principal components in the plot. For example, you have seen that thefirst principal component, represented in this biplot by the horizontal axis,has positive coefficients for all nine variables. That corresponds <strong>to</strong> the ninevec<strong>to</strong>rs directed in<strong>to</strong> the right half of the plot. You have also seen that thesecond principal component, represented by the vertical axis, has positivecoefficients for the variables education, health, arts, and transportation, andnegative coefficients for the remaining five variables. That corresponds <strong>to</strong>vec<strong>to</strong>rs directed in<strong>to</strong> the <strong>to</strong>p and bot<strong>to</strong>m halves of the plot, respectively. Thisindicates that this component distinguishes between cities that have highvalues for the first set of variables and low for the second, and cities thathave the opposite.10-43


10 <strong>Multivariate</strong> <strong>Methods</strong>The variable labels in this figure are somewhat crowded. You could eitherleave out the VarLabels parameter when making the plot, or simply selectand drag some of the labels <strong>to</strong> better positions using the Edit Plot <strong>to</strong>ol fromthe figure window <strong>to</strong>olbar.Each of the 329 observations is represented in this plot by a point, andtheir locations indicate the score of each observation for the two principalcomponents in the plot. For example, points near the left edge of this plothave the lowest scores for the first principal component. The points arescaled <strong>to</strong> fit within the unit square, so only their relative locations may bedetermined from the plot.You can use the Data Cursor, intheTools menu in the figure window, <strong>to</strong>identify the items in this plot. By clicking on a variable (vec<strong>to</strong>r), you can readoff that variable’s coefficients for each principal component. By clicking onan observation (point), you can read off that observation’s scores for eachprincipal component.You can also make a biplot in three dimensions. This can be useful if the firsttwo principal coordinates do not explain enough of the variance in your data.Selecting Rotate 3D in the Tools menu enables you <strong>to</strong> rotate the figure <strong>to</strong>see it from different angles.biplot(coefs(:,1:3), 'scores',scores(:,1:3),...'obslabels',names);axis([-.26 1 -.51 .51 -.61 .81]);view([30 40]);10-44


Feature TransformationFac<strong>to</strong>r Analysis• “<strong>Introduction</strong> <strong>to</strong> Fac<strong>to</strong>r Analysis” on page 10-45• “Example: Fac<strong>to</strong>r Analysis” on page 10-46<strong>Introduction</strong> <strong>to</strong> Fac<strong>to</strong>r Analysis<strong>Multivariate</strong> data often includes a large number of measured variables, andsometimes those variables overlap, in the sense that groups of them might bedependent. For example, in a decathlon, each athlete competes in 10 events,but several of them can be thought of as speed events, while others can bethought of as strength events, etc. Thus, you can think of a competi<strong>to</strong>r’s 10event scores as largely dependent on a smaller set of three or four types ofathletic ability.10-45


10 <strong>Multivariate</strong> <strong>Methods</strong>Fac<strong>to</strong>r analysis is a way <strong>to</strong> fit a model <strong>to</strong> multivariate data <strong>to</strong> estimate just thissort of interdependence. In a fac<strong>to</strong>r analysis model, the measured variablesdepend on a smaller number of unobserved (latent) fac<strong>to</strong>rs. Because eachfac<strong>to</strong>r might affect several variables in common, they are known as commonfac<strong>to</strong>rs. Each variable is assumed <strong>to</strong> be dependent on a linear combinationof the common fac<strong>to</strong>rs, and the coefficients are known as loadings. Eachmeasured variable also includes a component due <strong>to</strong> independent randomvariability, known as specific variance because it is specific <strong>to</strong> one variable.Specifically, fac<strong>to</strong>r analysis assumes that the covariance matrix of your datais of the form∑ = ΛΛ Τ + Ψxwhere Λ is the matrix of loadings, and the elements of the diagonal matrixΨ are the specific variances. The function fac<strong>to</strong>ran fits the Fac<strong>to</strong>r Analysismodel using maximum likelihood.Example: Fac<strong>to</strong>r Analysis• “Fac<strong>to</strong>r Loadings” on page 10-46• “Fac<strong>to</strong>r Rotation” on page 10-48• “Fac<strong>to</strong>r Scores” on page 10-50• “Visualizing the Results” on page 10-52Fac<strong>to</strong>r Loadings. Over the course of 100 weeks, the percent change in s<strong>to</strong>ckprices for ten companies has been recorded. Of the ten companies, the firstfour can be classified as primarily technology, the next three as financial, andthe last three as retail. It seems reasonable that the s<strong>to</strong>ck prices for companiesthat are in the same sec<strong>to</strong>r might vary <strong>to</strong>gether as economic conditionschange. Fac<strong>to</strong>r Analysis can provide quantitative evidence that companieswithin each sec<strong>to</strong>r do experience similar week-<strong>to</strong>-week changes in s<strong>to</strong>ck price.In this example, you first load the data, and then call fac<strong>to</strong>ran, specifyingamodel fit with three common fac<strong>to</strong>rs. By default, fac<strong>to</strong>ran computes rotatedestimates of the loadings <strong>to</strong> try and make their interpretation simpler. But inthis example, you specify an unrotated solution.10-46


Feature Transformationload s<strong>to</strong>ckreturns[Loadings,specificVar,T,stats] = ...fac<strong>to</strong>ran(s<strong>to</strong>cks,3,'rotate','none');The first two fac<strong>to</strong>ran return arguments are the estimated loadings and theestimated specific variances. Each row of the loadings matrix represents oneof the ten s<strong>to</strong>cks, and each column corresponds <strong>to</strong> a common fac<strong>to</strong>r. Withunrotated estimates, interpretation of the fac<strong>to</strong>rs in this fit is difficult becausemost of the s<strong>to</strong>cks contain fairly large coefficients for two or more fac<strong>to</strong>rs.LoadingsLoadings =0.8885 0.2367 -0.23540.7126 0.3862 0.00340.3351 0.2784 -0.02110.3088 0.1113 -0.19050.6277 -0.6643 0.14780.4726 -0.6383 0.01330.1133 -0.5416 0.03220.6403 0.1669 0.49600.2363 0.5293 0.57700.1105 0.1680 0.5524Note “Fac<strong>to</strong>r Rotation” on page 10-48 helps <strong>to</strong> simplify the structure in theLoadings matrix,<strong>to</strong>makeiteasier<strong>to</strong>assignmeaningful interpretations <strong>to</strong>the fac<strong>to</strong>rs.From the estimated specific variances, you can see that the model indicatesthat a particular s<strong>to</strong>ck price varies quite a lot beyond the variation due <strong>to</strong>the common fac<strong>to</strong>rs.specificVarspecificVar =0.09910.34310.80970.85590.142910-47


10 <strong>Multivariate</strong> <strong>Methods</strong>0.36910.69280.31620.33110.6544A specific variance of 1 would indicate that there is no common fac<strong>to</strong>rcomponent in that variable, while a specific variance of 0 would indicate thatthevariableisentirely determined by common fac<strong>to</strong>rs. These data seem <strong>to</strong>fall somewhere in between.The p value returned in the stats structure fails <strong>to</strong> reject the null hypothesisof three common fac<strong>to</strong>rs, suggesting that this model provides a satisfac<strong>to</strong>ryexplanation of the covariation in these data.stats.pans =0.8144To determine whether fewer than three fac<strong>to</strong>rs can provide an acceptable fit,you can try a model with two common fac<strong>to</strong>rs. The p value for this second fitis highly significant, and rejects the hypothesis of two fac<strong>to</strong>rs, indicating thatthe simpler model is not sufficient <strong>to</strong> explain the pattern in these data.[Loadings2,specificVar2,T2,stats2] = ...fac<strong>to</strong>ran(s<strong>to</strong>cks, 2,'rotate','none');stats2.pans =3.5610e-006Fac<strong>to</strong>r Rotation. As the results illustrate, the estimated loadings from anunrotated fac<strong>to</strong>r analysis fit can have a complicated structure. The goal offac<strong>to</strong>r rotation is <strong>to</strong> find a parameterization in which each variable has only asmall number of large loadings. That is, each variable is affected by a smallnumber of fac<strong>to</strong>rs, preferably only one. This can often make it easier <strong>to</strong>interpret what the fac<strong>to</strong>rs represent.If you think of each row of the loadings matrix as coordinates of a pointin M-dimensional space, then each fac<strong>to</strong>r corresponds <strong>to</strong> a coordinate axis.Fac<strong>to</strong>r rotation is equivalent <strong>to</strong> rotating those axes and computing new10-48


Feature Transformationloadings in the rotated coordinate system. There are various ways <strong>to</strong> do this.Some methods leave the axes orthogonal, while others are oblique methodsthat change the angles between them. For this example, you can rotate theestimated loadings by using the promax criterion, a common oblique method.[LoadingsPM,specVarPM] = fac<strong>to</strong>ran(s<strong>to</strong>cks,3,'rotate','promax');LoadingsPMLoadingsPM =0.9452 0.1214 -0.06170.7064 -0.0178 0.20580.3885 -0.0994 0.09750.4162 -0.0148 -0.12980.1021 0.9019 0.07680.0873 0.7709 -0.0821-0.1616 0.5320 -0.08880.2169 0.2844 0.66350.0016 -0.1881 0.7849-0.2289 0.0636 0.6475Promax rotation creates a simpler structure in the loadings, one in whichmos<strong>to</strong>fthes<strong>to</strong>ckshavealargeloadingononlyonefac<strong>to</strong>r. Toseethisstructure more clearly, you can use the biplot function <strong>to</strong> plot each s<strong>to</strong>ckusing its fac<strong>to</strong>r loadings as coordinates.biplot(LoadingsPM,'varlabels',num2str((1:10)'));axis squareview(155,27);10-49


10 <strong>Multivariate</strong> <strong>Methods</strong>This plot shows that promax has rotated the fac<strong>to</strong>r loadings <strong>to</strong> a simplerstructure. Each s<strong>to</strong>ck depends primarily ononlyonefac<strong>to</strong>r,anditispossible<strong>to</strong> describe each fac<strong>to</strong>r in terms of the s<strong>to</strong>cks that it affects. Based on whichcompanies are near which axes, you could reasonably conclude that the firstfac<strong>to</strong>r axis represents the financial sec<strong>to</strong>r, the second retail, and the thirdtechnology. The original conjecture, that s<strong>to</strong>cks vary primarily within sec<strong>to</strong>r,is apparently supported by the data.Fac<strong>to</strong>r Scores. Sometimes, it is useful <strong>to</strong> be able <strong>to</strong> classify an observationbased on its fac<strong>to</strong>r scores. For example, if you accepted the three-fac<strong>to</strong>r modeland the interpretation of the rotated fac<strong>to</strong>rs, you might want <strong>to</strong> categorizeeach week in terms of how favorable it was for each of the three s<strong>to</strong>ck sec<strong>to</strong>rs,based on the data from the 10 observed s<strong>to</strong>cks.Because the data in this example are the raw s<strong>to</strong>ck price changes, and notjust their correlation matrix, you can have fac<strong>to</strong>ran return estimates of the10-50


Feature Transformationvalueofeachofthethreerotatedcommonfac<strong>to</strong>rsforeachweek. Youcanthen plot the estimated scores <strong>to</strong> see how the different s<strong>to</strong>ck sec<strong>to</strong>rs wereaffected during each week.[LoadingsPM,specVarPM,TPM,stats,F] = ...fac<strong>to</strong>ran(s<strong>to</strong>cks, 3,'rotate','promax');plot3(F(:,1),F(:,2),F(:,3),'b.')line([-4 4 NaN 0 0 NaN 0 0], [0 0 NaN -4 4 NaN 0 0],...[0 0 NaN 0 0 NaN -4 4], 'Color','black')xlabel('Financial Sec<strong>to</strong>r')ylabel('Retail Sec<strong>to</strong>r')zlabel('Technology Sec<strong>to</strong>r')grid onaxis squareview(-22.5, 8)10-51


10 <strong>Multivariate</strong> <strong>Methods</strong>Oblique rotation often creates fac<strong>to</strong>rs that are correlated. This plot showssome evidence of correlation between the first and third fac<strong>to</strong>rs, and you caninvestigate further by computing the estimated fac<strong>to</strong>r correlation matrix.inv(TPM'*TPM)ans =1.0000 0.1559 0.40820.1559 1.0000 -0.05590.4082 -0.0559 1.0000Visualizing the Results. You can use the biplot function <strong>to</strong> help visualizeboth the fac<strong>to</strong>r loadings for each variable and the fac<strong>to</strong>r scores for eachobservation in a single plot. For example, the following command plots theresults from the fac<strong>to</strong>r analysis on the s<strong>to</strong>ck data and labels each of the 10s<strong>to</strong>cks.biplot(LoadingsPM,'scores',F,'varlabels',num2str((1:10)'))xlabel('Financial Sec<strong>to</strong>r')ylabel('Retail Sec<strong>to</strong>r')zlabel('Technology Sec<strong>to</strong>r')axis squareview(155,27)10-52


Feature TransformationIn this case, the fac<strong>to</strong>r analysis includes three fac<strong>to</strong>rs, and so the biplot isthree-dimensional. Each of the 10 s<strong>to</strong>cks is represented in this plot by a vec<strong>to</strong>r,and the direction and length of the vec<strong>to</strong>r indicates how each s<strong>to</strong>ck dependson the underlying fac<strong>to</strong>rs. For example, you have seen that after promaxrotation, the first four s<strong>to</strong>cks have positive loadings on the first fac<strong>to</strong>r, andunimportant loadings on the other two fac<strong>to</strong>rs. That first fac<strong>to</strong>r, interpretedas a financial sec<strong>to</strong>r effect, is represented in this biplot as one of the horizontalaxes. The dependence of those four s<strong>to</strong>cks on that fac<strong>to</strong>r corresponds <strong>to</strong> thefour vec<strong>to</strong>rs directed approximately along that axis. Similarly, the dependenceof s<strong>to</strong>cks 5, 6, and 7 primarily on the second fac<strong>to</strong>r, interpreted as a retailsec<strong>to</strong>r effect, is represented by vec<strong>to</strong>rs directed approximately along that axis.Each of the 100 observations is represented in this plot by a point, and theirlocations indicate the score of each observation for the three fac<strong>to</strong>rs. Forexample, points near the <strong>to</strong>p of this plot have the highest scores for the10-53


10 <strong>Multivariate</strong> <strong>Methods</strong>technology sec<strong>to</strong>r fac<strong>to</strong>r. The points are scaled<strong>to</strong>fitwithintheunitsquare,soonly their relative locations can be determined from the plot.You can use the Data Cursor <strong>to</strong>ol from the Tools menu in the figure window<strong>to</strong> identify the items in this plot. By clicking a s<strong>to</strong>ck (vec<strong>to</strong>r), you can read offthat s<strong>to</strong>ck’s loadings for each fac<strong>to</strong>r. By clicking an observation (point), youcan read off that observation’s scores for each fac<strong>to</strong>r.10-54

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!