@@ -214,82 +214,20 @@ par(op)
214
214
215
215
# compute proportions of variance associated with each angle
216
216
217
- # compute the harmonic scores associated with each angle
218
-
219
- gaitscores = gaitpca.fd $ scores
220
-
221
- # compute the values of the harmonics at time values for each angle
222
-
223
217
gaitharmmat = eval.fd(gaittime , gaitpca.fd $ harmonics )
224
218
hipharmmat = gaitharmmat [,,1 ]
225
219
kneeharmmat = gaitharmmat [,,2 ]
226
220
227
- # we need the values of the two mean functions also
228
-
229
- gaitmeanvec = eval.fd(gaittime , gaitmeanfd )
230
- hipmeanvec = gaitmeanvec [,,1 ]
231
- kneemeanvec = gaitmeanvec [,,2 ]
232
-
233
- # the values of the smooths of each angle less each mean function
234
-
235
- gaitsmtharray = eval.fd(gaittime , gaitfd )
236
- hipresmat = gaitsmtharray [,,1 ] - outer( hipmeanvec ,rep(1 ,39 ))
237
- kneeresmat = gaitsmtharray [,,2 ] - outer(kneemeanvec ,rep(1 ,39 ))
238
-
239
- # the variances of the residuals of the smooth angles from their means
240
-
241
- hipvar = mean( hipresmat ^ 2 )
242
- kneevar = mean(kneeresmat ^ 2 )
243
-
244
- print(paste(" Variances of fits by the means:" ,
245
- round(c(hipvar , kneevar ),1 )))
246
-
247
- # compute the fits to the residual from the mean achieved by the PCA
221
+ # then we want to find the total size of each
248
222
249
- hipfitarray = array (NA , c(nrow(hipharmmat ),nrow(gaitscores ),ncol(gaitscores )))
250
- kneefitarray = array (NA , c(nrow(kneeharmmat ),nrow(gaitscores ),ncol(gaitscores )))
251
- for (isc in 1 : 2 ) {
252
- hipfitarray [,,isc ] = hipharmmat %*% t(gaitscores [,,isc ])
253
- kneefitarray [,,isc ] = kneeharmmat %*% t(gaitscores [,,isc ])
254
- }
255
-
256
- # compute the variances of the PCA fits
257
-
258
- hipfitvar = c()
259
- kneefitvar = c()
260
- for (isc in 1 : 2 ) {
261
- hipfitvar = c(hipfitvar , mean( hipfitarray [,,isc ]^ 2 ))
262
- kneefitvar = c(kneefitvar , mean(kneefitarray [,,isc ]^ 2 ))
263
- }
264
-
265
- # compute percentages relative to the total PCA fit variance
266
- # these percentages will add to 100
223
+ hipharmL2 = apply(hipharmmat ^ 2 ,2 ,mean )
224
+ kneeharmL2 = apply(kneeharmmat ^ 2 ,2 ,mean )
267
225
268
- hippropvar1 = c()
269
- kneepropvar1 = c()
270
- for (isc in 2 ) {
271
- hippropvar1 = c(hippropvar1 , hipfitvar [isc ]/ (hipfitvar [isc ] +
272
- kneefitvar [isc ]))
273
- kneepropvar1 = c(kneepropvar1 , kneefitvar [isc ]/ (hipfitvar [isc ]+
274
- kneefitvar [isc ]))
275
- }
276
-
277
- print(paste(" Percentages of fits for the PCA:" ,
278
- round(100 * c(hippropvar1 , kneepropvar1 ),1 )))
279
-
280
- # compute percentages relative to the total mean fit variance
281
- # these percentages will add to the total percentage of fit
282
- # accounted for by the pca, which will typically be less than 100
283
-
284
- hippropvar2 = c()
285
- kneepropvar2 = c()
286
- for (isc in 1 : 2 ) {
287
- hippropvar2 = c(hippropvar2 , hipfitvar [isc ] / (hipvar + kneevar ))
288
- kneepropvar2 = c(kneepropvar2 , kneefitvar [isc ]/ (hipvar + kneevar ))
289
- }
226
+ hippropvar2 = hipharmL2 / (hipharmL2 + kneeharmL2 )
227
+ kneepropvar2 = 1 - hippropvar2
290
228
291
- print((paste( " Percentages of fits for the PCA:" ,
292
- round(100 * c (hippropvar2 , kneepropvar2 ),1 )) ))
229
+ print(" Percentages of fits for the PCA:" )
230
+ print( round(100 * cbind (hippropvar2 , kneepropvar2 ),1 ))
293
231
294
232
# --------------------------------------------------------------
295
233
# Canonical correlation analysis
0 commit comments