How do I normalise the first principal component in PCA such that its scalar product is equal to 1?

5 views (last 30 days)
Hi all,
I am running PCA on a 80x13 data matrix, in which I require the scalar product of the first principal component to equal 1. I.e if P is the first principal component, then I need:
P'P = 1
So far, I am using the Matlab stat code but I am unable to normalise the first principal component to having a scalar product that is equal to 1.
Would any of you be able to help? I would be very appreciative of any help. My Matlab code is copied below:
With kind regards,
KB
%%PCA
clc clear all
%% Load Data
filename = 'DataFinal.xlsx'; A = xlsread(filename);
% Principal Component Analysis
[n m] = size(A); %size of A
Amean = mean(A);
Astd = std(A);
% Now I seek to standardise the data normally. This will ensure that the % data is centred and rescaled. I subtract the mean and divide by the % standard deviation.
B = (A - repmat(Amean,[n 1])) ./ repmat(Astd,[n 1]);
%Alternatively we can use the Zscore function, to demean and divide by the %standard deviation
BB = zscore(A);
%Calculating the coefficients of princ components and respective variances %, done by finding eigenfunctions of sample covariance matrix
[V D] = eig(cov(B))
% V here contains the coefficients of principal components, diagonal % elements of D store the variance of respective principal components.
%Alternatively the below is a better way of calculating our principal %components and their variance.
[COEFF SCORE LATENT] = princomp(B)
%COEFF is a 13x13 square matrix %LATENT is 13x1 matrix %SCORE is 80x13 matrix (same dimensions as original time series set)
% Cumulative variance contained in first so many principal components can % be calculated as:
cumsum(var(SCORE)) / sum(var(SCORE))
% Also note all of the principal components are completely uncorrelated

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!