Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis Documentation

This class implements a Principal Component Analysis: Reduces the dimensionality of a model in an attempt to maximize variances while maintaining the same explanatory outcome. By default this analysis will extract all the factors (i.e. the selected columns) included. ROTATION: There are two rotations available to use: UncorrelatedComponentRotation is an orthogonal varimax rotation. To use: UseUncorrelatedRotation() CorrelatedComponentRotation is an olique direct quartimin (oblimin gamma = 0) rotation, sometimes referred to as a transformation rather than a rotation. To use: UseCorrelatedRotation() When using a rotation the user can adjust three items to customize it: Normalize() signifies whether or not a Kaiser normalization takes place on the loadings prior to the rotation, the loadings will be un-normalized afterwards. SetEpsilon() siginfies the threshold of convergence through compared to the difference of the criterion for each iteration in the rotation algorithm. SetMaximumIterations() signifies the stopping point even if convergence is not reached during a rotation. This class used R's principal() documentation as a reference in some of the calculations: https://www.rdocumentation.org/packages/psych/versions/2.2.9/topics/principal For more information: https://en.wikipedia.org/wiki/Principal_component_analysis https://en.wikipedia.org/wiki/Factor_analysis https://en.wikipedia.org/wiki/Varimax_rotation https://dictionary.apa.org/oblique-rotation https://en.wikipedia.org/wiki/Rotation_matrix https://en.wikipedia.org/wiki/Transformation_matrix

Example Code

use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis

DataFrame frame
frame:Load("Data/Data.csv")
frame:SelectAllColumns()

PrincipalComponentAnalysis pca
pca:Calculate(frame)

output pca:GetFactorLoadings()

Inherits from: Libraries.Compute.Statistics.DataFrameCalculation, Libraries.Compute.Statistics.Tests.StatisticalTest, Libraries.Language.Object, Libraries.Compute.Statistics.Inputs.ColumnInput, Libraries.Compute.Statistics.Inputs.FactorInput

Actions Documentation

AddColumn(integer column)

This action adds a value to the end of the input.

Parameters

  • integer column

AddFactor(integer column)

This action adds a value to the end of the input.

Parameters

  • integer column

Calculate(Libraries.Compute.Statistics.DataFrame frame)

To extract all of the columns that are selected.

Parameters

Example


    use Libraries.Compute.Statistics.DataFrame
    use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis

    DataFrame frame
    frame:Load("Data/Data.csv")
    frame:SelectAllColumns()

    PrincipalComponentAnalysis pca
    pca:Calculate(frame)
    
    output pca:GetFactorLoadings()

Calculate(Libraries.Compute.Statistics.DataFrame frame, integer numberOfFactorsToExtract)

To extract a specific number of factors, include a second parameter.

Parameters

Example


    use Libraries.Compute.Statistics.DataFrame
    use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis

    DataFrame frame
    frame:Load("Data/Data.csv")
    frame:SelectAllColumns()

    PrincipalComponentAnalysis pca
    pca:Calculate(frame, 5)
    
    output pca:GetFactorLoadings()

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

EmptyColumns()

This action empty's the list, clearing out all of the items contained within it.

EmptyFactors()

This action empty's the list, clearing out all of the items contained within it.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetColumn(integer index)

This action gets the item at a given location in an array.

Parameters

  • integer index

Return

integer: The item at the given location.

GetColumnIterator()

This action gets an iterator for the object and returns that iterator.

Return

Libraries.Containers.Iterator: Returns the iterator for an object.

GetColumnSize()

This action gets the size of the array.

Return

integer:

GetCommunality()

This returns the communality if only one result exists.

Return

Libraries.Compute.Vector:

GetDegreesOfFreedom()

This returns the model degrees of freedom if only one result exists.

Return

number:

GetEigenvalues()

This returns the eigenvalues if only one result exists.

Return

Libraries.Compute.Vector:

GetFactor(integer index)

This action gets the item at a given location in an array.

Parameters

  • integer index

Return

integer: The item at the given location.

GetFactorIterator()

This action gets an iterator for the object and returns that iterator.

Return

Libraries.Containers.Iterator: Returns the iterator for an object.

GetFactorLoadings()

This returns the factor loadings if only one result exists.

Return

Libraries.Compute.Statistics.DataFrame:

GetFactorSize()

This action gets the size of the array.

Return

integer:

GetFormalSummary()

This action summarizes the results and places them into formal academic language, in APA format. For more information: https://apastyle.apa.org/instructional-aids/numbers-statistics-guide.pdf

Return

text: a condensed formal result of the test

Example

use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis
    
DataFrame frame
frame:Load("Data/Data.csv")
frame:SelectAllColumns()
    
PrincipalComponentAnalysis pca
pca:Calculate(frame)
output pca:GetFormalSummary()

GetGroups(Libraries.Compute.Statistics.DataFrame frame)

Gets the the fully factored samples/groups in an array of dataframes. Using an array of dataframes instead of a single dataframe helps with multivariate cases.

Parameters

Return

Libraries.Containers.HashTable:

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetItemComplexity()

This returns the item complexity if only one result exists.

Return

Libraries.Compute.Vector:

GetMeanItemComplexity()

This returns the mean item complexity if only one result exists.

Return

number:

GetModelFit()

This returns the fit of the model if only one result exists.

Return

number:

GetProbabilityValue()

This returns the probability if only one result exists.

Return

number:

GetProportionExplained()

This returns the proportion explained if only one result exists.

Return

Libraries.Compute.Vector:

GetProportionVariance()

This returns the proportion var if only one result exists.

Return

Libraries.Compute.Vector:

GetReport(Libraries.System.File file)

This creates an HTML page with the results as its contents.

Parameters

GetResidualHistogram()

This returns the residual histogram if only one result exists.

Return

Libraries.Interface.Controls.Charts.Chart:

GetResiduals()

This returns the residuals if only one result exists.

Return

Libraries.Compute.Statistics.DataFrame:

GetResult()

This returns a result if only one exists.

Return

Libraries.Compute.Statistics.Reporting.PrincipalComponentAnalysisResult: the PrincipalComponentAnalysisResult object

Example

use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis
use Libraries.Compute.Statistics.Reporting.PrincipalComponentAnalysisResult
    
DataFrame frame
frame:Load("Data/Data.csv")
frame:SelectAllColumns()
    
PrincipalComponentAnalysis pca
pca:Calculate(frame)

PrincipalComponentAnalysisResult result = pca:GetResult()

GetResults()

Return

Libraries.Containers.Array: an array of PrincipalComponentAnalysisResult objects

Example

use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis
use Libraries.Compute.Statistics.Reporting.PrincipalComponentAnalysisResult
    
DataFrame frame
frame:Load("Data/Data.csv")
frame:SelectAllColumns()
    
PrincipalComponentAnalysis pca
pca:Calculate(frame)

Array<PrincipalComponentAnalysisResult> results = pca:GetResults()

GetRootMeanSquareOfResiduals()

This returns the root mean square of residuals if only one result exists.

Return

number:

GetScreePlot()

This returns the scree plot if only one result exists.

Return

Libraries.Interface.Controls.Charts.Chart:

GetSignificanceLevel()

A list of unique items of the factor

Return

number:

GetStatisticalFormatting()

GetSummary()

Return

text: a list of the important statistics of the test

Example

use Libraries.Compute.Statistics.DataFrame
use Libraries.Compute.Statistics.Tests.PrincipalComponentAnalysis
    
DataFrame frame
frame:Load("Data/Data.csv")
frame:SelectAllColumns()
    
PrincipalComponentAnalysis pca
pca:Calculate(frame)
output pca:GetSummary()

GetTestStatistic()

This returns the test statistic of the model if only one result exists.

Return

number:

GetUniqueness()

This returns the uniqueness if only one result exists.

Return

Libraries.Compute.Vector:

GetVarianceAccountedFor()

This returns the VAF if only one result exists.

Return

Libraries.Compute.Vector:

IsEmptyColumns()

This action returns a boolean value, true if the container is empty and false if it contains any items.

Return

boolean: Returns true when the container is empty and false when it is not.

IsEmptyFactors()

This action returns a boolean value, true if the container is empty and false if it contains any items.

Return

boolean: Returns true when the container is empty and false when it is not.

Normalize(boolean normalize)

Will apply kaiser normalization before rotation

Parameters

  • boolean normalize

RemoveColumn(integer column)

This action removes the first occurrence of an item that is found in the Addable object.

Parameters

  • integer column

Return

boolean: Returns true if the item was removed and false if it was not removed.

RemoveColumnAt(integer index)

This action removes an item from an indexed object and returns that item.

Parameters

  • integer index

RemoveFactor(integer column)

This action removes the first occurrence of an item that is found in the Addable object.

Parameters

  • integer column

Return

boolean: Returns true if the item was removed and false if it was not removed.

RemoveFactorAt(integer index)

This action removes an item from an indexed object and returns that item.

Parameters

  • integer index

SetEpsilon(number epsilon)

Will control convergence point during rotation

Parameters

  • number epsilon

SetMaximumIterations(integer maxIterations)

Will control rotation or gradient iterations during rotation

Parameters

  • integer maxIterations

SetSignificanceLevel(number significanceLevel)

Sets the significance level of the test (default is 0.05).

Parameters

  • number significanceLevel: the significance level between 0 and 1.

SetStatisticalFormatting(Libraries.Compute.Statistics.Reporting.StatisticsFormatting formatting)

Create a new frame based on that list

Parameters

UseCorrelatedRotation()

Will apply an oblique rotation (namely direct quartimin) to the component loadings

UseUncorrelatedRotation()

Will apply an orthogonal rotation (namely varimax) to the component loadings