Statistics - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Data Analysis : Statistics/PCA

Statistics

  

PCA

  

principal component analysis on data

 

Calling Sequence

Parameters

Options

Description

Notes

Examples

Compatibility

Calling Sequence

PCA( dataset )

PCA( dataset, options )

PrincipalComponentAnalysis( dataset )

PrincipalComponentAnalysis( dataset, options )

Parameters

dataset

-

data set or DataFrame ; Matrix or DataFrame of values with 2 or more columns

options

-

(optional) equation(s) of the form option=value

Options

• 

method : one of the names eigenvector or svd; controls if the principal component analysis uses the eigenvector method (on either the covariance or correlation matrix) or the singular values method. By default this is set to svd.

• 

columns : non-negative integer; controls the number of dimensions of data to retain. The default is set to the same number of dimensions as the original dataset. Columns of data are discarded based on their effect on the variability in the data with the columns accounting for the most variability being discarded last.

• 

tolerance : float; controls the number of dimensions of data to discard. The default is set to 0.0. Columns are discarded if their standard deviations are less than or equal to the value for tolerance multiplied by the standard deviation of the first component.

• 

correlation : truefalse; controls the choice of the transformation matrix in the computation. By default, correlation is set to false, and the covariance matrix is used.

• 

center : truefalse, numeric, procedure; controls if the returned list of values is centered or not. The default is set to true, which uses the Statistics[Mean] command to compute the center. If this is set to false, the list is not centered and the list of values will have the same central mean value as before. If a numeric value is entered, the list is centered using that value as its center. If a procedure is entered, the list is centered using the value returned from the procedure.  If a procedure is entered as the first value of a list, subsequent arguments in the list are passed to the procedure.

• 

scale : truefalse, numeric, procedure, or identical to the name auto; controls if the returned list of values is scaled or not. The default is set to auto. When set to auto, if the correlation matrix is used in the computation, scale is automatically set to true. If the covariance matrix is used, scale is set to false. If scale is set to false, each column is not scaled and therefore has the same standard deviation as before. When set to true, the Statistics[StandardDeviation] command is used to compute the standard deviation. If a numeric value is entered, the list is scaled using that value as its standard deviation. If a procedure is entered, the list is scaled using the value returned from the procedure.  If a procedure is entered as the first value of a list, subsequent arguments in the list are passed to the procedure.

• 

output : list; controls the form of the returned solution. The default is record. Output options include:

– 

record : a record which contains all of the following output options. Each of the outputs can be queried using :-outputname.

– 

values : the singular values or eigenvalues

– 

varianceproportion : the proportion of the total variance for each value

– 

stdev : the square root of the singular values or eigenvalues

– 

rotation : a matrix whose columns correspond to the eigenvectors

– 

principalcomponents : a matrix whose columns correspond to the resulting principal components

• 

ignore : truefalse; controls how missing data is handled. Missing items are represented by undefined or Float(undefined). If ignore=false and the dataset contains missing data, the PCA command will return undefined. If ignore = true, all rows with any missing items in dataset will be removed. The default value is false. The ignore option is not passed to any procedures entered for either of the center or scale options.

• 

summarize : truefalse; controls the display of a printed summary of the singular values or eigenvalues. The default is false

Description

• 

The PCA command is used to perform a principal component analysis on a set of data. Principal Component Analysis transforms a multi-dimensional data set to a new set of perpendicular axes (or components) that describe decreasing amounts of variance in the data.   

• 

The PCA command returns a record containing values for values, varianceproportion, stdev, rotation and principalcomponents by default. The output option can also be used to return specific elements from the principal component analysis.

• 

The default method is svd, which is generally the recommended method for numerical accuracy.

• 

The abbreviation PCA( data ) is available as a synonym for PrincipalComponentAnalysis( data ).

Notes

• 

To print out the results of the principal component analysis, set infolevel[Statistics] to 1, or use the summarize option.

Examples

withStatistics:

If infolevel[Statistics] is set to 1, the PCA command will return a printed summary for the results.

infolevelStatistics1:

data2,4,5,6,8,9|2,1,0,1,2,4

data224150618294

(1)

PCAnalysisPCAdata:

summary:

Values   proportion of variance  St. Deviation
11.2240     0.9904                 3.3502
0.1093      0.0096                 0.3306

The rotation matrix from the principal component analysis:

PCAnalysis:-rotation

0.7680953681125180.6403354632410230.6403354632410230.768095368112518

(2)

The principal components can be returned using :-principalcomponents.

PCAnalysis:-principalcomponents

4.523910918388630.2996423835837022.347384718922570.2129331747858250.9389538875690270.08517326991433010.4694769437845130.04258663495716542.646003143250570.4699889234123624.694769437845140.425866349571652

(3)

The following plot shows the original data set (in red) and the results from the principal component analysis.

plots:-displaydataplotdata,'points',color=Red,dataplotPCAnalysis:-principalcomponents,'points'

One use for principal component analysis is to eliminate dimensions from the data. The following plot shows the original two dimensions of data, X and Y, as well as the two resulting principal components. It can be observed that from the principal component analysis, the 2nd component has the least effect on the variance, suggesting that it can be removed.

plotoptssize=600,100,view=10..10,default,symbol=solidcircle,symbolsize=20:

splotsStatistics:-ScatterPlotdata..,1,color=Red,plotopts,title=X,Statistics:-ScatterPlotPCAnalysis:-principalcomponents..,1,color=Orange,plotopts,title=1st Component,Statistics:-ScatterPlotdata..,2,color=DarkBlue,plotopts,title=Y,Statistics:-ScatterPlotPCAnalysis:-principalcomponents..,2,color=RoyalBlue,plotopts,title=2nd Component:

DocumentTools:-Tabulatesplots

Tabulate

(4)

 

infolevelStatistics0:

The following example performs a principal component analysis on multi-dimensional data. The components that have the least impact on the variance are discarded, and the simplified data is reconstructed from the remaining components.

data22.5|2.4|10.5,0.5|0.7|0.785,2.2|2.9|1.286,1.9|2.2|2.35,3.1|3.0|2.202,2.3|2.7|1.351,2.0|1.6|2.021,1.0|1.1|1.247,1.5|1.6|2.503,1.1|0.9|1.214

data22.52.410.50.50.70.7852.22.91.2861.92.22.353.13.02.2022.32.71.3512.01.62.0211.01.11.2471.51.62.5031.10.91.214

(5)

The columns option keeps the columns of data with the greatest variance. Here we discard the component with the least amount of impact on the variability of the dataset.

PCAnalysis2PCAdata2,columns=2,summarize=true:

summary:
Values   proportion of variance  St. Deviation
8.3208     0.8782                 2.8846
1.1119     0.1173                 1.0545
0.0425     0.0045                 0.2061

PCAnalysis2:-principalcomponents

7.988187958806680.4132208576658382.018075584298931.479698278334731.100545374570461.186039637066240.1543757522189800.3050805395865080.07464758865229911.701349118990771.043210727376071.091188102113230.5246774108110050.02801275103728591.461265360655200.9287708944738890.1106753661728270.4254297822692001.500714794050911.00852483397581

(6)

The data can be reconstructed using the principal components:

EVectorsPCAnalysis2:-rotation1..3,1..2

EVectors0.1240352340793790.6463230214959140.09631199526958410.7473506291701020.9875926590827140.154057096439744

(7)

TempMatrixEVectors.PCAnalysis2:-principalcomponents%T:

RecDataMatrixupperbounddata2,i,j→TempMatrixj,i+Meandata2j

RecData2.533742610068952.3705374529383610.49863539301070.6033244603559990.6097816745759630.7808213878394502.440058318692752.690391748072541.276291644337901.988032543582492.123133896490082.346439818259202.900362172073583.174314876310582.210073684126732.385865104414002.625026408017031.347527473085901.726816228643061.838531924579412.032048003784621.028465598145221.075145105157031.245848804105461.521307292739351.581395419210122.502138297821810.9720256712846001.011741494648881.21917549362819

(8)

plots:-displaydataplotdata2,'points',color=Red,dataplotconvertRecData,Matrix,'points'

The correlation option is used to compute the principal components using the correlation matrix instead of the covariance matrix. This is often done while using the eigenvector method.

PCAdata2,method=eigenvector,correlation=true,output=stdev,principalcomponents

1.459839088176520.8973362152256430.252304485644744,2.045410644357932.165341110539980.07295408984796472.259516397437650.2752894631465150.1620101886309250.9018826641520990.9192281524712640.3886771386998320.2675417336837700.2078247451668840.1429972860238261.862759656769230.8929089417129970.3232079584367540.8445084466649370.8387416547021930.1380962559338070.1454314635405880.08413583588304440.4452805637390751.472591414805030.1291639592270000.04209258552610040.5011212365998850.1947472032646530.03401187719199021.543442633244810.1782975937582350.212350899678612

(9)

A Scree Plot is often used to visually determine which principal components explain the majority of the variance.

data3DataFrame2.5|2.4|10.5|0.1|0.5,0.5|0.7|0.785|4.3|2.0,2.2|2.9|1.286|5.4|7.0,1.9|2.2|2.35|6.7|3.1,3.1|3.0|2.202|8.1|12,0.1|0.4|0.5|0.6|0.9,columns=a,b,c,d,e

data3abcde12.52.410.50.10.520.50.70.7854.32.032.22.91.2865.47.041.92.22.356.73.153.13.02.2028.11260.10.40.50.60.9

(10)

PCAnalysis3PCAdata3,summarize=true:

summary:

Values   proportion of variance  St. Deviation
31.4897     0.6658                 5.6116
13.2270     0.2797                 3.6369
2.3575      0.0498                 1.5354
0.2180      0.0046                 0.4669
0.0031      0.0001                 0.0558

The following plot indicates that the first three components account for approximately 99.5% of the variance.

ScreePlotPCAnalysis3

The tolerance or removecolumns options can be used to remove the components with the least effect on the overall variance. Using tolerance = 0.01 will remove any principal components whose value is at most 0.01 multiplied by the value of the first principal component, namely the last two.

PCAdata3,tolerance=0.01:-principalcomponents

12317.688417521905905.455950371125230.13955048794036621.062869046430373.274394630428280.76025401909986433.453639245808520.07175743563813100.60810493637110540.7358311947032420.7474518990400762.6224958407502258.377331436947992.794026825258270.83234493939503263.815515309123484.156373231277011.80274949614359

(11)

A Biplot can also be used to show the first two components and the observations on the same set of axes. The first principal component is plotted on the x-axis and the second on the y-axis.

BiplotPCAnalysis3,pointlabels=true,points=false

Compatibility

• 

The Statistics[PCA] command was introduced in Maple 2016.

• 

For more information on Maple 2016 changes, see Updates in Maple 2016.

Applications

Iris Data

See Also

Statistics

Statistics[Scale]

Statistics[CorrelationMatrix]

Statistics[CovarianceMatrix]

Statistics[ScreePlot]

Statistics[Biplot]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam