FPCASCORE Procedure
Example 12.2 Scoring Growth Data with a Saved FPCA Model
This example demonstrates how to use the FPCASCORE procedure to score new functional data by using a previously trained FPCA model. The data come from the Berkeley Growth Study (Tuddenham and Snyder 1954), which includes height trajectories of 93 children that were measured over 31 time points.[4]
The following DATA step creates the data table growth_curve. Each of the columns y1 through y93 corresponds to a child’s growth curve, and the column _TIMEPOINTS_ contains the time points.
data growth_curves;
input _TIMEPOINTS_ y1-y93;
datalines;
1.0 81.3 76.2 76.8 74.1 74.2 76.8 72.4 73.8 75.4
78.8 76.9 81.6 78.0 76.4 76.4 76.2 75.0 79.7 70.0
... more lines ...
The following DATA step creates the data table growth_labels, which contains the gender ID for each curve—0 for males and 1 for females:
data growth_labels;
infile datalines dsd;
input ID :$5. Gender;
datalines;
y1,0
... more lines ...
To visualize the raw functional data, the data are first transposed to long format and then merged with gender information, as shown in the following statements. The results are displayed in Output 12.2.1, which plots the height trajectories for all 93 children; the curves are colored by gender.
/* Convert to long format and merge with gender */
proc transpose data=growth_curves out=growth_long(rename=(col1=value)) name=id;
by _TIMEPOINTS_;
run;
proc sql;
create table growth_long_gender as
select a._TIMEPOINTS_, a.id, a.value, b.gender
from growth_long as a
left join growth_labels as b
on a.id = b.id;
quit;
/* Plot all curves colored by gender */
ods graphics / reset width=7in height=5in imagename="growth_curves_by_gender"
imagefmt=png;
proc sgplot data=growth_long_gender;
series x=_TIMEPOINTS_ y=value / group=gender lineattrs=(thickness=1)
transparency=0.7;
xaxis label="Age (Years)";
yaxis label="Height (cm)";
title "Growth Curves Colored by Gender";
run;
ods listing close;
Output 12.2.1: Plot of Raw Functional Gowth Curves

The plot in Output 12.2.1 shows that boys generally exhibit smoother and taller growth curves than girls, although you can see considerable overlap among the trajectories.
The following statements perform functional principal component analysis on the growth data by using the FPCA procedure, extract the first two principal component scores by using PROC FPCASCORE, and visualize these scores in a scatter plot that is colored by gender. Output 12.2.2 shows the results.
You start by loading the growth_curves and growth_label data into your SAS library and by using your libref in the first statement of the following DATA step. These statements assume that your SAS library is named mylib, but you can substitute any appropriately defined CAS engine libref.
data mylib.growth;
set growth_curves;
run;
data mylib.labels;
set growth_labels;
run;
/* Train FPCA model */
proc fpca data=mylib.growth nBins=10;
input y1-y93;
savestate rstore=mylib.state_fpca;
run;
/* Score same data using the analytic store */
proc fpcascore data=mylib.growth model=mylib.state_fpca;
input y1-y93;
output out=mylib.score_new npc=4;
run;
/* Assign child ID and merge with gender */
data score_fpca_id;
set mylib.score_new;
length id $4;
id = cats("y", _n_);
run;
proc sql;
create table score_gender as
select a._PCS_1, a._PCS_2, a.id, b.gender
from score_fpca_id as a
left join growth_labels as b
on a.id = b.id;
quit;
/* Plot FPCA scores colored by gender */
ods graphics / imagename="growth_fpca_scores" imagefmt=png;
proc sgplot data=score_gender;
scatter x=_PCS_1 y=_PCS_2 / group=gender markerattrs=(symbol=circlefilled);
xaxis label="First Principal Component";
yaxis label="Second Principal Component";
title "Growth Curve FPCA Scores Colored by Gender";
run;
ods listing close;
Output 12.2.2: Plot of First Two FPCA Scores by Gender

The FPCA scores in the final scatter plot, shown in Output 12.2.2, reveal clear clustering of individuals by gender. This suggests that the dominant growth variations that FPCA captures are influenced by gender-based biological patterns.
[4] Disclaimer: SAS may reference other websites or content or resources for use at Customer’s sole discretion. SAS has no control over any websites or resources that are provided by companies or persons other than SAS. Customer acknowledges and agrees that SAS is not responsible for the availability or use of any such external sites or resources, and does not endorse any advertising, products, or other materials on or available from such websites or resources. Customer acknowledges and agrees that SAS is not liable for any loss or damage that may be incurred by Customer or its end users as a result of the availability or use of those external sites or resources, or as a result of any reliance placed by Customer or its end users on the completeness, accuracy, or existence of any advertising, products, or other materials on, or available from, such websites or resources.