データサイエンティスト上がりのDX参謀・起業家

データサイエンティスト上がりのDX参謀・起業家のブログ。データ分析や事業について。自身はアーティスト、経営者、事業家。

関数データ解析(Functional data analysis)について

教科書はこちら。

Functional Data Analysis (Springer Series in Statistics)

Functional Data Analysis (Springer Series in Statistics)

Silverman先生は確かカーネル回帰などノンパラ法の権威。


webの資料は以下の2つがあります。

http://www.r-project.org/conferences/useR-2007/program/presentations/ramsay.pdf
http://ego.psych.mcgill.ca/misc/fda/index.html



Rのパッケージ:fda

  • 作者:Ramsay(教科書の作者と同じ)
  • 内容:主に時系列データに対して、何らかの滑らかな関数を当てはめる
  • 8種の基底関数:constant, monomial, polynomial, polygonal, B-splines, power, exponential, and Fourier
    • 定数、単項式、多項式、多角形、Bスプライン、累乗関数、指数関数、フーリエ関数
  • 観測ポイントの数が異なっていても解析可能
  • 関数解析の手順
    1. 基底関数の選択
    2. smoothing operatorの設定
    3. 目的関数を最適化して係数を計算
    4. モデル評価、残差プロット
    5. 仮説検定
  • 基底関数:f(t) = a1φ1(t) + a2φ2(t) + .... + akφk(t)
    • 多項式:1, t, t^2, ... , t^k
      • 昔ながらの方法
      • パラメータ推定が簡単なので手計算でやってた頃は重宝された
    • フーリエ関数:1, sin(ωt), cos(ωt), sin(2ωt), cos(2ωt), sin(3ωt), cos(3ωt),....
      • 19世紀初頭のフランスで使われていた
      • 周期性のあるデータに用いる
    • spline、wavelet
  • Flexibility:多くの曲線は特定の場所で尖った形をしていることが多い
    • 多項式:多くの項を入れないと対応できない
    • スプライン:いろんな曲線にfitしやすい
    • フーリエ:急激な変化に対応しにくい
    • ウェーブレット:急激な変化に強い
  • fdaパッケージに入っているサンプルデータ
    • gait
#---Hip and knee angle in degrees through a 20 point movement cycle for 39 boys
matplot(gait[, 1:10, 1], gait[, 1:10, 2], type="b", xlab = "hip angle", ylab = "knee angle", lwd = 2)
matplot(gait[, 1:39, 1], gait[, 1:39, 2], type="b", xlab = "hip angle", ylab = "knee angle", lwd = 2)

#---A list containing the heights of 39 boys and 54 girls from age 1 to 18 and the ages at which they were collected.
with(growth, matplot(age, hgtf[, 1:10], type="b"))
with(growth, matplot(age, hgtm[, 1:39], type="b"))
with(growth, matplot(age, hgtf[, 1:54], type="b"))

matplot(growth$age, data.frame(growth$hgtm[, 1:10], growth$hgtf[, 1:10]), type = "b")
matplot(growth$age, data.frame(growth$hgtm[, 1:39], growth$hgtf[, 1:54]), type = "b")

    • handwrite
#---handwrit An array of dimensions (1401, 20, 2) giving 1401 pairs of (x, y) coordinates for each
#---of 20 replicates of cursively writing "fda"
matplot(handwrit[, 1:20, 1], handwrit[, 1:20, 2], type="l")

    • pinch
#---151 measurements of pinch force during 20 replications with time from start of measurement.
matplot (pinchtime, pinch, type="l", cex=2,
  lwd=1, xlab = "Seconds", ylab="Force (N)")
abline(h=2, v=0.075, lty=2)





その他のRのパッケージ


MDFAでの解析例

MFDAパッケージの使用例を紹介します。

この論文の内容がパッケージ化されたものです。

http://genemerge.cbcb.umd.edu/online/SSC.pdf



MFDAパッケージに入っているサンプルデータはこのようになっています。

library(MFDA)
data("testdata")
matplot(1:10,t(testdata), type = "b", xlab = "x", ylab = "y", main = "usedata")



これは次の4つの関数から発生させたデータ集合です。

  1. -exp(tt)/1000:30カーブ
  2. tan(tt):40カーブ
  3. 5 *(tt - 4)^2/max((tt - 4)^2):50カーブ
  4. cos(tt):30カーブ


このデータを関数クラスタリングによってクラスタリングすると次のようになります。

my.clust <- MFclust(testdata,minG=3,maxG=5,nchain=1,iter.max=1)
matplot(1:10,t(testdata), type = "l", col = my.clust$clust, lty = 1, xlab = "x", ylab = "y", main = "cluster by MEDA")


5つのクラスターに分かれていますが、真の関数を概ね表現しているように見えます。

しかしこの関数クラスタリングの基底関数はスプラインなので、真の関数が何かを表現する事はできません。


あくまでも大体の形を推測するのに利用します。

次回、このMFclust関数の中身がどうなっているかを探りたいと思います。


混合効果モデル、EMアルゴリズム、スプラインといろいろミックスさせているので勉強になります。