function [predictedValue] = myPCR10by3(testSet, trainSet)

% indicate components to retain 
if size(trainSet,2) <=2
    componentsToRetain = 1;
else
    componentsToRetain = 2;
end

% get the size
[n,p] = size(trainSet(:,1:(size(trainSet,2)-1)));

% store dependent and independent variables of the trainset
X = trainSet(:,1:(size(trainSet,2)-1));
y = trainSet(:,size(trainSet,2));

% apply principle component analysis
[PCALoadings,PCAScores,PCAVar] = princomp(X);

% retain all 10 of the principle components and
% fit the regression model
betaPCR = regress(y-mean(y), PCAScores(:,1:componentsToRetain));


% To make the PCR results easier to interpret in terms of the original 
% data, transform to regression coefficients for the original, 
% uncentered variables.
betaPCR = PCALoadings(:,1:componentsToRetain)*betaPCR;
betaPCR = [mean(y) - mean(X)*betaPCR; betaPCR];
predictedValue = abs([ones(size(testSet,1),1) testSet(:,1:(size(testSet,2)-1))]*betaPCR)';
end