Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: smoother
See also: Fouriertrans Fouriereval pca fft

Quantlet: FDApca
Description: Carries out a penalized functional principal component analysis (PCA) based on the coefficient matrix for functional data. It is possible to choose a smoothing parameter objectively.


Usage: {values,varprop,scores,harmcoef}=FDApca(coef,period,lambda{,npc})
coef K x N matrix, the coefficient matrix for functional data
period scalar, the period based on the grid points of original data
lambda scalar, a smoothing parameter
npc scalar, the number of principal components to be kept (Default is 4)
values P x 1 vector of eigenvalues
varprop P x 1 vector, the proportion of each variance explained by eigenfunctions
scores N x P matrix containing PC scores
harmcoef K x P matrix, the coefficient matrix for the eigenfunctions

temp   = read("dailtemp")            		; read daily temperature data
nbasis = 30                          		; set the number of basis functions
tempcoef =  Fouriertrans(temp,nbasis)		; calculation of coefficient matrix
period = 365                         		; period
lambda = 10000                       		; smoothing parameter
npc = 4                              		; number of principal components
tempfpcaresult = FDApca(tempcoef,period,lambda,npc); functional PCA
tempycoef = tempfpcaresult.harmcoef  		; coefficient for eigenfunctions
K   = rows(tempycoef)                		; number of basis functions in algorithm
nresol = 100                         		; number of grid points for evaluation
phi = Fouriereval(K,nresol,period)   		; evaluation of basis functions
tempxifdval =(tempycoef' * phi)'    		; evaluation of eigenfunctions
x  =((1:nresol)-0.5)/(nresol/period)		; generates grid
z1 = setmask(x~tempxifdval[,1], "line", "black")	; black line for PC1 weight
z2 = setmask(x~tempxifdval[,2], "line", "blue") 	; blue  line for PC2 weight
z3 = setmask(x~tempxifdval[,3], "line", "red")  	; red   line for PC3 weight
z4 = setmask(x~tempxifdval[,4], "line", "green")	; green line for PC4 weight
plot(z1, z2, z3, z4)                 		; plots lines
setgopt(plotdisplay,1,1,"title","PC Weight Functions(lambda=10000)")

PC1 weight function is displayed with black colour,
PC2 weight function is displayed with blue colour,
PC3 weight function is displayed with red colour,
PC4 weight function is displayed with green colour.

Author: Y. Yamanishi, 20010927 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006