<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Functional Data Analysis on R Views</title>
    <link>https://rviews.rstudio.com/tags/functional-data-analysis/</link>
    <description>Recent content in Functional Data Analysis on R Views</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 14 Oct 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://rviews.rstudio.com/tags/functional-data-analysis/" rel="self" type="application/rss+xml" />
    
    
    
    
    <item>
      <title>FDA and the Dynamics of Curves</title>
      <link>https://rviews.rstudio.com/2021/10/14/fda-and-the-dynamics-of-curves/</link>
      <pubDate>Thu, 14 Oct 2021 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2021/10/14/fda-and-the-dynamics-of-curves/</guid>
      <description>
        
&lt;script src=&#34;/2021/10/14/fda-and-the-dynamics-of-curves/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;An elegant application of Functional Data Analysis is to model longitudinal data as a curve and then study the curve’s dynamics. For example, in pharmacokinetics and other medical studies analyzing multiple measurements of drug or protein concentrations in blood samples, it may be interest to determine if the concentrations in subjects undergoing one type of treatment rise quicker than those undergoing an alternative treatment. In this post, I will generate some plausible fake data for measurements taken over time for two groups of subjects, use the techniques of Functional Data Analysis to represent these data as a continuous curve for each subject, and look at some of the dynamic properties of the curves, in particular their velocities and accelerations.&lt;/p&gt;
&lt;div id=&#34;synthetic-data&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Synthetic Data&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://cran.r-project.org/package=fdaoutlier&#34;&gt;fdaoutlier&lt;/a&gt; package contains functions to generate a number of stochastic models with a mechanism to generate reasonable outliers for each type of model. THe curves produced by model 4 look like they can serve plausible synthetic concentration curves. Instead of thinking of normal curves and outliers, I imagine the two related sets of curves to be the results of two different treatments influencing some measured concentration curve. In the example below, the curves associated with &lt;strong&gt;treatment 2&lt;/strong&gt; are of the form: &lt;span class=&#34;math display&#34;&gt;\[X_i(t) = \mu t(1 - t)^m + e_i(t),\]&lt;/span&gt;
while those associated with &lt;strong&gt;treatment 1&lt;/strong&gt; are of the form:
&lt;span class=&#34;math display&#34;&gt;\[X_i(t) = \mu(1 - t)t^m + e_i(t)\]&lt;/span&gt; where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(t\in [0,1]\)&lt;/span&gt;,&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(e_i(t)\)&lt;/span&gt; is a Gaussian process with zero mean and covariance function of the form: &lt;span class=&#34;math display&#34;&gt;\[\gamma(s,t) = \alpha\exp\{-\beta|t-s|^\nu\},\]&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(m\)&lt;/span&gt; is a constant&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(\mu\)&lt;/span&gt; is the mean value&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(\alpha\)&lt;/span&gt;, &lt;span class=&#34;math inline&#34;&gt;\(\beta\)&lt;/span&gt;, and &lt;span class=&#34;math inline&#34;&gt;\(\nu\)&lt;/span&gt; are coefficients in the covariance function&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(fdaoutlier)
library(tidyverse)
library(fda)
library(gganimate)
library(gridExtra)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following code generates two different sets of longitudinal data from Model 4 which is described in the &lt;a href=&#34;https://cran.r-project.org/web/packages/fdaoutlier/vignettes/simulation_models.html&#34;&gt;vignette&lt;/a&gt; to the &lt;a href=&#34;https://cran.r-project.org/package=fdaoutlier&#34;&gt;fdaoutlier&lt;/a&gt; package.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(95139)
n_curves &amp;lt;- 100
n_obs &amp;lt;- 50
mod4 &amp;lt;- simulation_model4(n = n_curves, p = n_obs, outlier_rate = .5, seed = 50, plot = FALSE)
index &amp;lt;- 1:n_curves
index1 &amp;lt;- mod4$true_outliers
# curves_mat is an n_curves x n_obs matrix
curves_mat &amp;lt;- mod4$data
treat &amp;lt;- rep(2,n_obs)
curves &amp;lt;- data.frame(index, treat, curves_mat)
curves &amp;lt;- curves %&amp;gt;% mutate(treat = if_else((index %in% index1),1,2))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are 50 curves for each treatment and 50 points for each curve. This is probably the simplest case possible, and it is good enough to show how to explore the dynamics of curves. However, if you work with real longitudinal data you know that things are rarely this simple. But please be assured that FDA can deal with considerably more complexity, including a variable number of measurements for each subject, different measurement times for each subject, and situations where you have far fewer than 50 points for each subject. I have explored some of these situations in previous posts. For example, look &lt;a href=&#34;https://rviews.rstudio.com/2021/05/14/basic-fda-descriptive-statistics-with-r/&#34;&gt;here&lt;/a&gt; to see how to work with different time points, and &lt;a href=&#34;https://rviews.rstudio.com/2021/07/08/exploratory-fda-with-sparse-data/&#34;&gt;here&lt;/a&gt; for some ideas for working with sparse data. The first link above also points to basic references that should help you to get started with your data.&lt;/p&gt;
&lt;p&gt;Now, I reformat the data into a long form data frame and plot both sets of curves.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;time &amp;lt;- 1:n_obs

curves_l &amp;lt;- pivot_longer(curves, cols = !c(&amp;quot;index&amp;quot;, &amp;quot;treat&amp;quot;), names_to = &amp;quot;Xval&amp;quot;) %&amp;gt;%
            mutate(time = rep(time,100), .before = &amp;quot;treat&amp;quot;, treat = as.factor(treat)) %&amp;gt;%
            dplyr::select(-Xval)

p &amp;lt;- curves_l %&amp;gt;% ggplot(aes(time,value, color = treat)) +
     geom_line(aes(group = index)) + 
     scale_color_manual(values=c(&amp;quot;navy blue&amp;quot;, &amp;quot;dark grey&amp;quot;)) +
     ggtitle(&amp;quot;Model 4 Curves&amp;quot;)
p&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/10/14/fda-and-the-dynamics-of-curves/index_files/figure-html/unnamed-chunk-3-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;So far we just have plots based on a relatively small number of data points. Nevertheless, our eyes extrapolate, and we imagine seeing two sets of continuous curves with one set clearly rising to its maximum value faster than the other set. But we really don’t have continuous curves yet, we just have points.&lt;/p&gt;
&lt;p&gt;The next step is to invoke the mathematics of FDA to embed the points in an infinite dimensional vector space where the data for each subject is modeled by a continuous function (curve). Exactly how this happens is a bit involved, but the general idea is that we create a basis and then use the data and some techniques from the linear algebra of Hilbert spaces to estimate the time dependent coefficients that enable modeling each subject’s data points as a linear combination of the basis functions. So, from here on out we are not going to be working with the raw data anymore. We will be working with vector space models of the data. The upside is that we can now now have real curves (continuous function), and can calculate the values of the functions and other properties such as the first and second derivatives at any time point. If you are interested in the math, please have a look at the references listed at the bottom of my post on &lt;a href=&#34;https://rviews.rstudio.com/2021/06/10/functional-pca-with-r/&#34;&gt;Functional PCA&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;modeling-the-data-as-functions-with-a-b-spline-basis&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Modeling the data as functions with a B-Spline Basis&lt;/h3&gt;
&lt;p&gt;Here we use the function &lt;code&gt;fda::create.bspline.basis()&lt;/code&gt; to create a B-Spline basis covering the interval of our observations. The plot of the curves above indicates that specifying a knot at every multiple of 5 ought to be adequate for representing our data. Note that using cubic splines &lt;code&gt;n_order&lt;/code&gt; = 4 ensures that the splines will have continuous first and second derivatives at the knots.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;knots    = c(seq(0,n_obs,5)) #Location of knots
n_knots   = length(knots) #Number of knots
n_order   = 4 # order of basis functions: for cubic b-splines: order = 3 + 1
n_basis   = length(knots) + n_order - 2;
spline_basis = create.bspline.basis(rangeval = c(0,n_obs), nbasis = n_basis, norder = n_order)
#plot(spline_basis)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following code uses the function &lt;code&gt;fda::Data2fda()&lt;/code&gt; and the &lt;code&gt;spline-basis&lt;/code&gt; to convert the Model 4 data points into functions and produce one fda object for each of the two groups of treatments.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# df1 is an (n_curves/2) x (n_obs) matrix 
df1 &amp;lt;- curves_mat[index1,] # data for treatment 1
index2 &amp;lt;- index[!(index %in% index1)]
df2 &amp;lt;- curves_mat[index2,]  # data for treatment 2
# Use the b-spline basis to create represent the curves as vectors in the function space
df1_obj &amp;lt;- Data2fd(argvals = 1:n_obs, y = t(df1), basisobj = spline_basis, lambda = 0.5)
df2_obj &amp;lt;- Data2fd(argvals = 1:n_obs, y = t(df2), basisobj = spline_basis, lambda = 0.5)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;computing-derivatives&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Computing Derivatives&lt;/h3&gt;
&lt;p&gt;Here we evaluate each function along with its first and second derivatives at a finer time scale than we used to originally display our data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;tfine &amp;lt;- seq(0,50,by=.5)
# Each matrix is 101 x 50 rows are different times, columns are curves
pos1 &amp;lt;- as.vector(eval.fd(tfine, df1_obj));     pos2 &amp;lt;- as.vector(eval.fd(tfine, df2_obj))
vel1 &amp;lt;- as.vector(eval.fd(tfine, df1_obj,1));   vel2 &amp;lt;- as.vector(eval.fd(tfine, df2_obj,1)) 
acc1 &amp;lt;- as.vector(eval.fd(tfine, df1_obj,2));   acc2 &amp;lt;- as.vector(eval.fd(tfine, df2_obj,2))   &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that the velocities and accelerations computed above were returned as matrices. We convert them to vectors and put them into a data frame for plotting.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;time &amp;lt;- rep(tfine,50)
id1 &amp;lt;- rep(1:50,each=101)
id2 &amp;lt;- rep(51:100,each=101)

derv1 &amp;lt;- data.frame(time, id1, pos1, vel1, acc1)
derv2 &amp;lt;- data.frame(time, id2, pos2, vel2, acc2)

pv1 &amp;lt;- derv1 %&amp;gt;% ggplot(aes(time,vel1,col=id1)) + geom_line(aes(group = id1)) + ggtitle(&amp;quot;Velocity Treatment 1&amp;quot;)
pv2 &amp;lt;- derv2 %&amp;gt;% ggplot(aes(time,vel2,col=id2)) + geom_line(aes(group = id2)) + ggtitle(&amp;quot;Velocity Treatment 2&amp;quot;)
pa1 &amp;lt;- derv1 %&amp;gt;% ggplot(aes(time,acc1,col=id1)) + geom_line(aes(group = id1)) +ggtitle(&amp;quot;Acceleration Treatment 1&amp;quot;)
pa2 &amp;lt;- derv2 %&amp;gt;% ggplot(aes(time,acc2,col=id2)) + geom_line(aes(group = id2)) + ggtitle(&amp;quot;Acceleration Treatment 2&amp;quot;)

grid.arrange(pv1, pa1, pv2, pa2, nrow = 2,ncol = 2, padding = unit(1, &amp;quot;line&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/10/14/fda-and-the-dynamics-of-curves/index_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The velocities for treatment 1 head upwards before they decrease while the velocities for treatment 2 go straight down, and the curve up again. The accelerations for treatment 1 slope downward slightly while those of treatment two slope upward. So the plots indicate that the two sets of curves look like they behave differently.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;testing-for-differences&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Testing for Differences&lt;/h3&gt;
&lt;p&gt;We can test for differences using the function &lt;code&gt;fda::tperm.fd()&lt;/code&gt; which implements a resampling method to do pointwise t-tests. The functional data representing the curves for the two samples are combined in a single array and the labels for the curves are randomly shuffled. Recalculating the maximum value of the t-statistic for each point enables computing a null distribution. Then, at each time point, the observed data are compared with the 1 - &lt;span class=&#34;math inline&#34;&gt;\(\alpha\)&lt;/span&gt; quantile of the null distribution.&lt;/p&gt;
&lt;p&gt;The plot below shows the result of performing the t-test to compare the first derivatives of the two treatments. I use the function &lt;code&gt;fda.deriv.fd()&lt;/code&gt; to calculate the first derivative for each treatment on the fly, just to show another way of doing things in the &lt;code&gt;fda&lt;/code&gt; package. You can easily modify the code to compare accelerations.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;dfdt1 &amp;lt;- deriv.fd(df1_obj,1)
dfdt2 &amp;lt;- deriv.fd(df2_obj,1)
tres &amp;lt;- tperm.fd(dfdt1,dfdt2,plotres=FALSE)

max_q &amp;lt;- tres$qval
tres_dat &amp;lt;-tibble(time = tres$argvals, t_values = tres$Tvals,
                  q_vals = tres$qvals.pts)

p &amp;lt;- tres_dat %&amp;gt;% ggplot(aes(time,t_values, colour = &amp;quot;t_value&amp;quot;)) + geom_line() +
    geom_line(aes(time, q_vals, colour = &amp;quot;q_vals&amp;quot;)) +
    geom_line(aes(time, max_q,colour = &amp;quot;max_q&amp;quot;), linetype= &amp;quot;dashed&amp;quot;) + 
    labs(x = &amp;quot;time&amp;quot;, y = &amp;quot;&amp;quot;) +
    ggtitle(&amp;quot;Statistics for Pointwise t-test&amp;quot;)
p&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/10/14/fda-and-the-dynamics-of-curves/index_files/figure-html/unnamed-chunk-8-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The blue curve shows the t-statistic for the observed values. The green curve represents the 95% quantiles, and the dashed red line is the 95% quantile of the maximum of null distribution t-statistics. The t-test confirms that the derivatives are indeed different except in the regions of overlap around time = 10 and time = 40.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;examine-phase-plots&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Examine Phase Plots&lt;/h3&gt;
&lt;p&gt;Phase plots are useful for evaluating how the curves develop in the abstract &lt;em&gt;phase space&lt;/em&gt; created by looking at position versus velocity, or velocity versus acceleration. Here we pick three curves from each treatment and plot velocity versus acceleration.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;phase1 &amp;lt;- derv1 %&amp;gt;% filter(id1 %in% 15:17)
phase2 &amp;lt;- derv2 %&amp;gt;% filter(id2 %in% 51:53)
pph1 &amp;lt;- phase1 %&amp;gt;% ggplot(aes(vel1,acc1,col=id1)) + geom_point() + ggtitle(&amp;quot;Treat 1 v vs. acc&amp;quot;)
pph2 &amp;lt;- phase2 %&amp;gt;% ggplot(aes(vel2,acc2,col=id2)) + geom_point() + ggtitle(&amp;quot;Treat 2 v vs. acc&amp;quot;)

grid.arrange(pph1, pph2, ncol = 2, padding = unit(1, &amp;quot;line&amp;quot;))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/10/14/fda-and-the-dynamics-of-curves/index_files/figure-html/unnamed-chunk-9-1.png&#34; width=&#34;672&#34; /&gt;
Based on this small sample, it certainly appears that the curves associated with the two different treatments inhabit different regions of phase space.&lt;/p&gt;
&lt;p&gt;Finally, it is easy and helpful to animate a phase diagram to show how a function develops in phase space over time. The animation below shows the first curve for treatment 1.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;pos &amp;lt;- eval.fd(tfine, df2_obj[1])
vel &amp;lt;- eval.fd(tfine, df2_obj[1],1)
acc &amp;lt;- eval.fd(tfine, df2_obj[1],2)
phase_dat &amp;lt;- tibble(tfine, vel, acc)

p &amp;lt;- ggplot(phase_dat, aes(vel,acc)) +  geom_point() + ggtitle(&amp;quot;Trajectory in Phase Space&amp;quot;)

anim &amp;lt;- p + transition_time(tfine) + shadow_mark()
anim_save(&amp;quot;anim.gif&amp;quot;, anim)
#anim&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;anim.gif&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2021/10/14/fda-and-the-dynamics-of-curves/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>Functional PCA with R</title>
      <link>https://rviews.rstudio.com/2021/06/10/functional-pca-with-r/</link>
      <pubDate>Thu, 10 Jun 2021 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2021/06/10/functional-pca-with-r/</guid>
      <description>
        
&lt;script src=&#34;/2021/06/10/functional-pca-with-r/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;In two previous posts, &lt;a href=&#34;https://rviews.rstudio.com/2021/05/04/functional-data-analysis-in-r/&#34;&gt;Introduction to Functional Data Analysis with R&lt;/a&gt; and &lt;a href=&#34;https://rviews.rstudio.com/2021/05/14/basic-fda-descriptive-statistics-with-r/&#34;&gt;Basic FDA Descriptive Statistics with R&lt;/a&gt;, I began looking into FDA from a beginners perspective. In this post, I would like to continue where I left off and investigate Functional Principal Components Analysis (FPCA), the analog of ordinary Principal Components Analysis in multivariate statistics. I’ll begin with the math, and then show how to compute FPCs with R.&lt;/p&gt;
&lt;p&gt;As I have discussed previously, although the theoretical foundations of FDA depend on some pretty advanced mathematics, it is not necessary to master this math to do basic analyses. The R functions in the various packages insulate the user from most of the underlying theory. Nevertheless, attaining a deep understanding of what the R functions are doing, or looking into any of the background references requires some level of comfort with the notation and fundamental mathematical ideas.&lt;/p&gt;
&lt;p&gt;I will define some of the basic concepts and then provide a high level roadmap of the mathematical argument required to develop FPCA from first principals. It is my hope that if you are a total newcomer to Functional Data Analysis you will find this roadmap useful in apprehending the big picture. This synopsis closely follows the presentation by Kokoszka and Reimherr (Reference 1. below).&lt;/p&gt;
&lt;p&gt;We are working in &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt;, a separable &lt;a href=&#34;https://en.wikipedia.org/wiki/Hilbert_space#:~:text=A%20Hilbert%20space%20is%20a,of%20calculus%20to%20be%20used.&#34;&gt;Hilbert space&lt;/a&gt; of square integrable random functions where each random function, &lt;span class=&#34;math inline&#34;&gt;\(X(\omega,t)\)&lt;/span&gt;, where &lt;span class=&#34;math inline&#34;&gt;\(\omega \in \Omega\)&lt;/span&gt; the underlying space of probabilistic outcomes, and &lt;span class=&#34;math inline&#34;&gt;\(t \in [0,1]\)&lt;/span&gt;. (After the definitions below, I will suppress the independent variables and in most equations assume &lt;span class=&#34;math inline&#34;&gt;\(EX = 0\)&lt;/span&gt;.)&lt;/p&gt;
&lt;div id=&#34;definitions&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Definitions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A Hilbert Space &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; is an infinite dimensional vector space with an inner product denoted by &lt;span class=&#34;math inline&#34;&gt;\(&amp;lt;.,.&amp;gt;\)&lt;/span&gt;. In our case, the &lt;em&gt;vectors&lt;/em&gt; are functions.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; is separable if there exists an orthonormal basis. That is, there is an orthogonal collection of functions &lt;span class=&#34;math inline&#34;&gt;\((e_i)\)&lt;/span&gt; in &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; such that &lt;span class=&#34;math inline&#34;&gt;\(&amp;lt;e_i,e_j&amp;gt;\; = 0\)&lt;/span&gt; if &lt;span class=&#34;math inline&#34;&gt;\(i = j\)&lt;/span&gt; and 0 otherwise, and every function in &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; can be represented as a linear combination of these functions.&lt;/li&gt;
&lt;li&gt;The inner product of two functions &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; and &lt;span class=&#34;math inline&#34;&gt;\(Y\)&lt;/span&gt; in &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; is defined as &lt;span class=&#34;math inline&#34;&gt;\(&amp;lt;X,Y&amp;gt;\; = \int X(\omega,t) Y(\omega,t)dt\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;The norm of &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; is defined in terms of the inner product: &lt;span class=&#34;math inline&#34;&gt;\(\parallel X(\omega) \parallel ^2\; = \int X(\omega, t)^2 dt &amp;lt; \infty\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; is said to be square integrable if &lt;span class=&#34;math inline&#34;&gt;\(E\parallel X(\omega) \parallel ^2 &amp;lt; \infty\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://math.stackexchange.com/questions/1687111/understanding-the-definition-of-the-covariance-operator&#34;&gt;covariance operator&lt;/a&gt; &lt;span class=&#34;math inline&#34;&gt;\(C(y): \mathscr{H} \Rightarrow \mathscr{H}\)&lt;/span&gt; for any square integrable function &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; is given by: &lt;span class=&#34;math inline&#34;&gt;\(C(y) = E[&amp;lt;X - EX,y&amp;gt;(X - EX)]\)&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;the-road-to-functional-principal-components&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;The Road to Functional Principal Components&lt;/h3&gt;
&lt;p&gt;As we have seen, the fundamental idea of Functional Data Analysis is to represent a function &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; by a linear combination of basis elements. In the previous posts we showed how to accomplish this using a basis constructed from more or less arbitrarily selected B-spline vectors. But, is there a an empirical, some would say &lt;em&gt;natural&lt;/em&gt; basis that can be estimated from the data? The answer is yes, and that is what FPCA is all about.&lt;/p&gt;
&lt;p&gt;A good way to start is to look at the distance between a vector &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; and its projection down into the space spanned by some finite, p-dimensional basis &lt;span class=&#34;math inline&#34;&gt;\((u_k)\)&lt;/span&gt; which is expressed in the following equation,&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math inline&#34;&gt;\(D = E\parallel X - \sum_{k=1}^{p}&amp;lt;X, u_k&amp;gt;u_k\parallel^2\)&lt;/span&gt;             &lt;span class=&#34;math inline&#34;&gt;\((*)\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This expands out to:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math inline&#34;&gt;\(= E [&amp;lt; (X - \sum_{k=1}^{p}&amp;lt;X, u_k&amp;gt;u_k, X - \sum_{k=1}^{p}&amp;lt;X, u_k&amp;gt;u_k)&amp;gt;]\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;and with a little algebra this:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math inline&#34;&gt;\(= E\parallel X \parallel^2 - \sum_{k=1}^{p}E&amp;lt;X, u_k&amp;gt;^2\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It should be clear that we would want to find a basis that makes &lt;span class=&#34;math inline&#34;&gt;\(D\)&lt;/span&gt; as small as possible, and that minimizing &lt;span class=&#34;math inline&#34;&gt;\(D\)&lt;/span&gt; is equivalent to maximizing the term to be subtracted in the line above.&lt;/p&gt;
&lt;p&gt;A little algebra shows that, &lt;span class=&#34;math inline&#34;&gt;\(E&amp;lt;X, u_k&amp;gt;^2 \;=\; &amp;lt;C(u_k),u_k&amp;gt;\)&lt;/span&gt; where &lt;span class=&#34;math inline&#34;&gt;\(C(u_k)\)&lt;/span&gt; is the covariance operator defined above.&lt;/p&gt;
&lt;p&gt;Now, we are almost at our destination. There is a theorem (e.g. Theorem 11.4.1 in reference 1.) that says for any fixed number of basis elements p, the distance D above is minimized if &lt;span class=&#34;math inline&#34;&gt;\(u_j = v_j\)&lt;/span&gt; where the &lt;span class=&#34;math inline&#34;&gt;\(v_j\)&lt;/span&gt; are the eigenfunctions of &lt;span class=&#34;math inline&#34;&gt;\(C(y)\)&lt;/span&gt; with respect to the unit norm. From this it follows that &lt;span class=&#34;math inline&#34;&gt;\(E&amp;lt;X, v_j&amp;gt;^2 \;=\; &amp;lt;C(v_,),v_j&amp;gt;\; =\; &amp;lt;\lambda_j, v_j&amp;gt;\; =\; \lambda_j\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Going back to equation &lt;span class=&#34;math inline&#34;&gt;\((*)\)&lt;/span&gt;, we can expand &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt; in terms of the basis &lt;span class=&#34;math inline&#34;&gt;\((v_j)\)&lt;/span&gt; so &lt;span class=&#34;math inline&#34;&gt;\(D = 0\)&lt;/span&gt; and we have what is called the &lt;a href=&#34;https://en.wikipedia.org/wiki/Karhunen%E2%80%93Lo%C3%A8ve_theorem&#34;&gt;Karhunen–Loève&lt;/a&gt; expansion: &lt;span class=&#34;math inline&#34;&gt;\(X = \mu + \sum_{j=1}^{\infty}\xi_jv_j\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(\mu = EX\)&lt;/span&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;The deterministic basis functions &lt;span class=&#34;math inline&#34;&gt;\((v_j)\)&lt;/span&gt; are called the &lt;em&gt;functional principal components&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;The &lt;span class=&#34;math inline&#34;&gt;\((v_j)\)&lt;/span&gt; have unit norm and are unique up to their signs. (You can work with &lt;span class=&#34;math inline&#34;&gt;\(v_j\)&lt;/span&gt; or &lt;span class=&#34;math inline&#34;&gt;\(-v_j\)&lt;/span&gt;.)&lt;/li&gt;
&lt;li&gt;The eigenvalues are such that: &lt;span class=&#34;math inline&#34;&gt;\(\lambda_1 &amp;gt; \lambda_2 &amp;gt; . . . \lambda_p\)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;The random variables &lt;span class=&#34;math inline&#34;&gt;\(\xi_j =\; &amp;lt;X - \mu,v_j&amp;gt;\)&lt;/span&gt; are called the &lt;em&gt;scores&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(E\xi_j = 0\)&lt;/span&gt;, &lt;span class=&#34;math inline&#34;&gt;\(E\xi_j^2 = \lambda_j\)&lt;/span&gt; and &lt;span class=&#34;math inline&#34;&gt;\(E|\xi_i\xi_j| = 0,\; if\; i\;\neq\;j\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And finally, with one more line:&lt;br /&gt;
&lt;span class=&#34;math inline&#34;&gt;\(\sum_{j=1}^{\infty}\lambda_j \: = \: \sum_{j=1}^{\infty}E[&amp;lt;X,v_j&amp;gt;^2] = E\sum_{j=1}^{\infty}&amp;lt;X,v_j&amp;gt;^2 \; = \; E\parallel X \parallel^2 \; &amp;lt; \infty\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;we arrive at our destination, the variance decomposition:
&lt;span class=&#34;math inline&#34;&gt;\(E\parallel X - \mu \parallel^2 \;= \;\sum_{j=1}^{\infty}\lambda_j\)&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;lets-calculate&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Let’s Calculate&lt;/h3&gt;
&lt;p&gt;Now that we have enough math to set the context, let’s calculate. We will use the same simulated Brownian motion data that we used in the previous posts, and also construct the same B-spline basis that we used before and save it in the fda object &lt;code&gt;W.obj&lt;/code&gt;. I won’t repeat the code here.&lt;/p&gt;
&lt;p&gt;The following plot shows &lt;strong&gt;120&lt;/strong&gt; simulated curves, each having &lt;strong&gt;1000&lt;/strong&gt; points scattered over the interval &lt;strong&gt;[0, 100]&lt;/strong&gt;. Each curve has unique observation times over that interval.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/2021/06/10/functional-pca-with-r/index_files/figure-html/unnamed-chunk-1-1.png&#34; width=&#34;672&#34; /&gt;
For first attempt at calculating functional principal components we’ll use the &lt;code&gt;pca.fd()&lt;/code&gt; function from the &lt;code&gt;fda&lt;/code&gt; package. So set up wise, we are picking up our calculations exactly where we left off in the previous post. As before, the basis representations of these curves are packed into the fda object &lt;code&gt;W.obj&lt;/code&gt;. The function &lt;code&gt;pca.fd()&lt;/code&gt; takes &lt;code&gt;W.obj&lt;/code&gt; as input. It needs the non-orthogonal B-spline basis to seed its computations and the estimate the covariance matrix and the orthogonal eigenvector basis &lt;span class=&#34;math inline&#34;&gt;\(v_j\)&lt;/span&gt;. The &lt;code&gt;nharm = 5&lt;/code&gt; parameter requests computing 5 eigenvalues.&lt;/p&gt;
&lt;p&gt;The method of calculation roughly follows the theory outlined above. It starts with a basis representation of the functions, computes the covariance matrix, and calculates the eigenfunctions.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;fun_pca &amp;lt;- pca.fd(W.obj, nharm = 5)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The object produced by &lt;code&gt;pca.fd()&lt;/code&gt; is fairly complicated. For example, the list &lt;code&gt;fun_pca$harmonics&lt;/code&gt; does not contain the eignevectors themselves, but rather coefficients that enable the eigenvectors to be computed from the original basis. However, because there is a special plot method for &lt;code&gt;plot.pca.fd()&lt;/code&gt; it is easy to plot the eigenvectors.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;plot(fun_pca$harmonics, lwd = 3)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/06/10/functional-pca-with-r/index_files/figure-html/unnamed-chunk-3-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;done&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is also to obtain the eivenvalues &lt;span class=&#34;math inline&#34;&gt;\(\lambda_j\)&lt;/span&gt;,&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;fun_pca$values&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##  [1] 37.232207  3.724524  1.703604  0.763120  0.547976  0.389431  0.196101
##  [8]  0.163289  0.144052  0.116587  0.089307  0.057999  0.054246  0.050683
## [15]  0.042738  0.035107  0.031283  0.024905  0.019079  0.016428  0.011657
## [22]  0.007392  0.002664&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and, the proportion of the variance explained by each eigenvalue.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;fun_pca$varprop&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 0.81965 0.08199 0.03750 0.01680 0.01206&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div id=&#34;a-different-approach&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;A Different Approach&lt;/h3&gt;
&lt;p&gt;So far in this short series of FDA posts, I have been mostly using the &lt;code&gt;fda&lt;/code&gt; package to calculate. In 2003 when it was released, it was ground breaking work. It is still the package that you are most likely to find when doing internet searches, and is the foundation for many subsequent R packages. However, as the &lt;a href=&#34;https://cran.r-project.org/web/views/FunctionalData.html&#34;&gt;CRAN Task View&lt;/a&gt; on Functional Data Analysis indicates, new work in FDA has resulted in several new R packages. The more recent &lt;a href=&#34;https://cran.r-project.org/package=fdapace&#34;&gt;&lt;code&gt;fdapace&lt;/code&gt;&lt;/a&gt; takes a different approach to calculating principal components. The package takes its name from the &lt;strong&gt;(PACE)&lt;/strong&gt; Principal Components by Conditional Expectation algorithm described in the paper by Yao, Müller and Wang (Reference 4. below). The package &lt;a href=&#34;https://cran.r-project.org/web/packages/fdapace/vignettes/fdapaceVig.html&#34;&gt;vignette&lt;/a&gt; is exemplary. It describes the methods of calculation, develops clear examples and provides a list of references to guide your reading about PACE and FDA in general.&lt;/p&gt;
&lt;p&gt;A very notable feature of the PACE algorithm is that it is designed specifically to work with sparse data. The vignette describes the two different methods of calculation that package functions employ for sparse and non-sparse data. In this post, In this post we are not working with sparse data, but hope to do so in the future. See the vignette for examples of FPCA with sparse data.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(fdapace)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;fdapace&lt;/code&gt; package requires data for the functions (curves) and associated times be organized in lists. We begin by using the &lt;code&gt;fdapace::CheckData()&lt;/code&gt; function to check the data set up in the tibble &lt;code&gt;df&lt;/code&gt;. (See previous post on descriptive statistics for the details on the data construction.)&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;CheckData(df$Curve,df$Time)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No error message is generated, so we move on th having the &lt;code&gt;FPCA()&lt;/code&gt; function calculate the FPCA outputs including:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;W_fpca &amp;lt;- FPCA(df$Curve,df$Time)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the eigenvalues:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;W_fpca$lambda&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 37.5386  3.2098  1.0210  0.3533&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the cumulative percentage of variance explained by the eigenvalue&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;W_fpca$cumFVE&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 0.8875 0.9634 0.9875 0.9959&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and the scores:&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;head(W_fpca$xiEst)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;##         [,1]    [,2]     [,3]     [,4]
## [1,]  0.8187  1.1971 -1.77755  0.20087
## [2,] -8.7396  2.4165 -0.33768 -0.10565
## [3,] -2.7517 -0.4879 -0.06747 -0.13953
## [4,]  3.9218  0.9419  0.39098 -0.25449
## [5,] -1.4400  0.7691  2.11549 -0.59947
## [6,]  7.3952  0.5114 -2.16391  0.05199&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All of these are in fairly good agreement with what we computed above. I am, however, a little surprised by the discrepancy in the value of the second eigenvalue. The default plot method for &lt;code&gt;FPCA()&lt;/code&gt; produces a plot indicating the density of the data, a plot of the mean of the functions reconstructed from the eigenfunction expansion, a scree plot of the eigenvalues and a plot of the first three eigenfunctions.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;plot(W_fpca)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/06/10/functional-pca-with-r/index_files/figure-html/unnamed-chunk-12-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Finally, it has probably already occurred to you that if you know the eigenvalues and scores, the Karhunen–Loève expansion can be used to simulate random functions. It can be shown that for the Wiener process:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math inline&#34;&gt;\(v_j(t) = \sqrt2 sin(( j - \frac{1}{2})\pi t)\)&lt;/span&gt; and &lt;span class=&#34;math inline&#34;&gt;\(\lambda_j = \frac{1}{(j - \frac{1}{2})^2\pi^2}\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This gives us:&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;math inline&#34;&gt;\(W(t) = \sum_{j=1}^{\infty} \frac {\sqrt2}{(j - \frac{1}{2})\pi)} N_j sin(( j - \frac{1}{2})\pi t\)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;where the &lt;span class=&#34;math inline&#34;&gt;\(N_j \:are\; iid \;N(0,1)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;fdapace&lt;/code&gt; function &lt;code&gt;fdapace::Wiener()&lt;/code&gt; uses this information to simulate an alternative, smoothed version of the Brownian motion, Wiener process.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(123)
w &amp;lt;- Wiener(n = 1, pts = seq(0,1, length = 100))
t &amp;lt;- 1:100
df_w &amp;lt;- tibble(t, as.vector(w))
ggplot(df_w, aes(x = t, y = w)) + geom_line()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/06/10/functional-pca-with-r/index_files/figure-html/unnamed-chunk-13-1.png&#34; width=&#34;576&#34; /&gt;&lt;/p&gt;
&lt;p&gt;In future posts, I hope to continue exploring the &lt;code&gt;fdapace&lt;/code&gt; package, including its ability to work with sparse data.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;references&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;p&gt;I found the following references particularly helpful.&lt;/p&gt;
&lt;ol style=&#34;list-style-type: decimal&#34;&gt;
&lt;li&gt;Kokoszka, P. and Reimherr, M. (2017). &lt;a href=&#34;https://www.amazon.com/Introduction-Functional-Analysis-Chapman-Statistical-ebook/dp/B075Z9QCV9/ref=sr_1_1?dchild=1&amp;amp;keywords=Introduction+to+functional+data+analysis&amp;amp;qid=1623276309&amp;amp;sr=8-1&#34;&gt;&lt;em&gt;Introduction to Functional Data Analysis&lt;/em&gt;&lt;/a&gt;. CRC.&lt;/li&gt;
&lt;li&gt;Hsing, T and Eubank, R. (2015). &lt;a href=&#34;https://www.amazon.com/Theoretical-Foundations-Functional-Introduction-Probability/dp/0470016914/ref=sr_1_1?dchild=1&amp;amp;keywords=theoretical+foundations+of+functional+data+analysis&amp;amp;qid=1623276176&amp;amp;sr=8-1&#34;&gt;&lt;em&gt;Theoretical Foundations of Functional Data Analysis, with an Introduction to Linear Operators&lt;/em&gt;&lt;/a&gt; Wiley&lt;/li&gt;
&lt;li&gt;Wang, J., Chiou, J. and Müller, H. (2015). &lt;a href=&#34;https://arxiv.org/pdf/1507.05135.pdf&#34;&gt;&lt;em&gt;Review of Functional Data Analysis&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Yao, F., Müller, H, Wang, J. (2012). &lt;a href=&#34;https://anson.ucdavis.edu/~mueller/jasa03-190final.pdf&#34;&gt;&lt;em&gt;Functional Data Analysis for Sparse Longitudinal Data&lt;/em&gt;&lt;/a&gt; JASA J100, I 470&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2021/06/10/functional-pca-with-r/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>Basic FDA Descriptive Statistics with R</title>
      <link>https://rviews.rstudio.com/2021/05/14/basic-fda-descriptive-statistics-with-r/</link>
      <pubDate>Fri, 14 May 2021 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2021/05/14/basic-fda-descriptive-statistics-with-r/</guid>
      <description>
        
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/htmlwidgets/htmlwidgets.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/plotly-binding/plotly.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/typedarray/typedarray.min.js&#34;&gt;&lt;/script&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/jquery/jquery.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/crosstalk/css/crosstalk.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/crosstalk/js/crosstalk.min.js&#34;&gt;&lt;/script&gt;
&lt;link href=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/plotly-htmlwidgets-css/plotly-htmlwidgets.css&#34; rel=&#34;stylesheet&#34; /&gt;
&lt;script src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/plotly-main/plotly-latest.min.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;In a previous post, I introduced the topic of Functional Data Analysis (FDA). In that post, I provided some background on Functional Analysis, the mathematical theory that makes FDA possible, identified FDA resources that might be of interest R users, and showed how to turn a series of data points into an FDA object. In this post, I will pick up where I left off and move on to doing some very basic FDA descriptive statistics.&lt;/p&gt;
&lt;p&gt;Let’s continue with the same motivating example from last time. We will use synthetic data generated by a Brownian motion process and pretend that it is observed longitudinal data. However, before getting to the statistics, I would like to take a tiny, tidy diversion. The functions in &lt;code&gt;fda&lt;/code&gt; and other fundamental FDA R packages require data structured in matrices. Consequently, the examples in the basic FDA reference works (listed below) construct matrices using code that seems to be convenient for the occasion. I think this makes adapting sample code to user data a little harder than it needs to be. There ought to be standard data structures for working with FDA data. I propose tibbles or data frames with function values packed into lists.&lt;/p&gt;
&lt;p&gt;The following function generates &lt;code&gt;n_points&lt;/code&gt; data points for each of &lt;code&gt;n_curve&lt;/code&gt; Brownian motion curves that represent the longitudinal data collected from &lt;code&gt;n_curve&lt;/code&gt; subjects.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;library(fda)
library(tidyverse)
library(plotly)

# Function to simulate data
fake_curves &amp;lt;- function(n_curves = 100, n_points = 80, max_time = 100){
  ID &amp;lt;- 1:n_curves
  x &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = n_curves)
  t &amp;lt;- vector(mode = &amp;quot;list&amp;quot;, length = n_curves)
  
  for (i in 1:n_curves){
    t[i] &amp;lt;- list(sort(runif(n_points,0,max_time)))
    x[i] &amp;lt;- list(cumsum(rnorm(n_points)) / sqrt(n_points))
  }
  df &amp;lt;- tibble(ID,t,x)
  names(df) &amp;lt;- c(&amp;quot;ID&amp;quot;, &amp;quot;Time&amp;quot;, &amp;quot;Curve&amp;quot;)
  return(df)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that each curve is associated with a unique set of random time points that lie in the interval [0, max_time]. Not being restricted to situations where data from all subjects must be observed at the same times is a big deal. However, in practice you may encounter problems that will require curve alignment procedures. We will ignore this for now. Note that the variables &lt;code&gt;Time&lt;/code&gt; and &lt;code&gt;Curve&lt;/code&gt; contain lists of data points in each cell.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(123)
n_curves &amp;lt;- 40
n_points &amp;lt;- 80
max_time &amp;lt;- 100
df &amp;lt;- fake_curves(n_curves = n_curves,n_points = n_points, max_time = max_time)
head(df)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## # A tibble: 6 x 3
##      ID Time       Curve     
##   &amp;lt;int&amp;gt; &amp;lt;list&amp;gt;     &amp;lt;list&amp;gt;    
## 1     1 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;
## 2     2 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;
## 3     3 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;
## 4     4 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;
## 5     5 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;
## 6     6 &amp;lt;dbl [80]&amp;gt; &amp;lt;dbl [80]&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Later on, this kind of structure will be convenient for data sets that contain both FDA curves and other scalar covariates. Note that if you are using the RStudio IDE running the function &lt;code&gt;View(df)&lt;/code&gt; will show you an expanded view of the tibble under a tab labeled df that should look something like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;df.png&#34; height = &#34;400&#34; width=&#34;600&#34;&gt;&lt;/p&gt;
&lt;p&gt;Next, we unpack the data into a long form tibble and plot.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;df_1 &amp;lt;- df %&amp;gt;% select(!c(ID,Curve)) %&amp;gt;% unnest_longer(Time) 
df_2 &amp;lt;- df %&amp;gt;% select(!c(ID,Time)) %&amp;gt;% unnest_longer(Curve)
ID &amp;lt;- sort(rep(1:n_curves,n_points))
df_l &amp;lt;- cbind(ID,df_1,df_2)
p &amp;lt;- ggplot(df_l, aes(x = Time, y = Curve, group = ID, col = ID)) +
      geom_line()
p&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/figure-html/unnamed-chunk-3-1.png&#34; width=&#34;672&#34; /&gt;
Now that we have the data, remember that FDA treats each curve as a basic data element living in an infinite dimensional vector space. The vectors, &lt;span class=&#34;math inline&#34;&gt;\(X\)&lt;/span&gt;, are random functions: &lt;span class=&#34;math inline&#34;&gt;\(X: \Omega \Rightarrow \mathscr{H}\)&lt;/span&gt; where &lt;span class=&#34;math inline&#34;&gt;\(\Omega\)&lt;/span&gt; is an underlying probability space and &lt;span class=&#34;math inline&#34;&gt;\(\mathscr{H}\)&lt;/span&gt; is typically a complete Hilbert Space of square integrable functions. That is, for each &lt;span class=&#34;math inline&#34;&gt;\(\omega \in \Omega\)&lt;/span&gt;, &lt;span class=&#34;math inline&#34;&gt;\(\parallel X(\omega) \parallel ^2 = \int X((\omega)(t))^2 dt &amp;lt; \infty\)&lt;/span&gt;. In multivariate statistics we work with random variables that live in a Euclidean space, here we are dealing with random functions that live in a Hilbert space. In this context, square integrable means &lt;span class=&#34;math inline&#34;&gt;\(E \parallel X \parallel ^2 &amp;lt; \infty\)&lt;/span&gt;. You will find lucid elaborations of all of this in the references below which I have reproduced below from the previous post.&lt;/p&gt;
&lt;p&gt;The bridge from the theory to practice is the ability to represent the random functions as a linear combination of basis vectors. This was the topic of the previous post. Here is some compact code to construct the basis.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;knots    = c(seq(0,max_time,5)) #Location of knots
n_knots   = length(knots) #Number of knots
n_order   = 4 # order of basis functions: for cubic b-splines: order = 3 + 1
n_basis   = length(knots) + n_order - 2;
basis = create.bspline.basis(rangeval = c(0,max_time), n_basis)
plot(basis)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/figure-html/unnamed-chunk-4-1.png&#34; width=&#34;672&#34; /&gt;
This next bit of code formats the data in the long form tibble into the matrix input expected by the &lt;code&gt;fda&lt;/code&gt; functions and creates an &lt;code&gt;fda&lt;/code&gt; object that contains the coefficients and basis functions used to smooth data. Note the smoothing constant of lambda = .5.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;argvals &amp;lt;- matrix(df_l$Time, nrow = n_points, ncol = n_curves)
y_mat &amp;lt;- matrix(df_l$Curve, nrow = n_points, ncol = n_curves)

W.obj &amp;lt;- Data2fd(argvals = argvals, y = y_mat, basisobj = basis, lambda = 0.5)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next somewhat anticlimactically after all of the preparation and theory, we use the &lt;code&gt;fda&lt;/code&gt; functions &lt;code&gt;mean.fd()&lt;/code&gt; and &lt;code&gt;std.fd()&lt;/code&gt; to calculate the pointwise mean and standard deviation from information contained in &lt;code&gt;fda&lt;/code&gt; object. In order to use these objects to calculate the pointwise confidence interval for the mean it is necessary to construct a couple of new &lt;code&gt;fda&lt;/code&gt; objects for the upper and lower curves. Then, we plot the smoothed curves for our data along with the pointwise mean and pointwise 95% confidence bands for the mean.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;W_mean &amp;lt;- mean.fd(W.obj)
W_sd &amp;lt;- std.fd(W.obj)
# Create objects for the standard upper and lower standard deviation
SE_u &amp;lt;- fd(basisobj = basis)
SE_l &amp;lt;- fd(basisobj = basis)
# Fill in the sd values
SE_u$coefs &amp;lt;- W_mean$coefs +  1.96 * W_sd$coefs/sqrt(n_curves) 
SE_l$coefs &amp;lt;- W_mean$coefs -  1.96 * W_sd$coefs/sqrt(n_curves)

plot(W.obj, xlab=&amp;quot;Time&amp;quot;, ylab=&amp;quot;&amp;quot;, lty = 1)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;done&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;title(main = &amp;quot;Smoothed Curves&amp;quot;)
lines(SE_u, lwd = 3, lty = 3)
lines(SE_l, lwd = 3, lty = 3)
lines(W_mean,  lwd = 3)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/14/basic-fda-descriptive-statistics-with-r/index_files/figure-html/unnamed-chunk-6-1.png&#34; width=&#34;672&#34; /&gt;
Finally, we compute the covariance/correlation matrix for our sample of smoothed curves and use &lt;a href=&#34;https://plotly.com/r/3d-surface-plots/&#34;&gt;&lt;code&gt;plotly&lt;/code&gt;&lt;/a&gt; to create an interactive plot of the three dimensional correlation surface along with a contour map.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;days &amp;lt;- seq(0,100, by=2)
cov_W &amp;lt;- var.fd(W.obj)
var_mat &amp;lt;-  eval.bifd(days,days,cov_W)&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;fig &amp;lt;- plot_ly(x = days, y = days, z = ~var_mat) %&amp;gt;% 
  add_surface(contours = list(
    z = list(show=TRUE,usecolormap=TRUE, highlightcolor=&amp;quot;#ff0000&amp;quot;, project=list(z=TRUE))))

fig &amp;lt;- fig %&amp;gt;% 
  layout(scene = list(camera=list(eye = list(x=1.87, y=0.88, z=-0.64))))

fig&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;div id=&#34;htmlwidget-1&#34; style=&#34;width:672px;height:480px;&#34; class=&#34;plotly html-widget&#34;&gt;&lt;/div&gt;
&lt;script type=&#34;application/json&#34; data-for=&#34;htmlwidget-1&#34;&gt;{&#34;x&#34;:{&#34;visdat&#34;:{&#34;10fc4fe7d04f&#34;:[&#34;function () &#34;,&#34;plotlyVisDat&#34;]},&#34;cur_data&#34;:&#34;10fc4fe7d04f&#34;,&#34;attrs&#34;:{&#34;10fc4fe7d04f&#34;:{&#34;x&#34;:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100],&#34;y&#34;:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100],&#34;z&#34;:{},&#34;alpha_stroke&#34;:1,&#34;sizes&#34;:[10,100],&#34;spans&#34;:[1,20],&#34;type&#34;:&#34;surface&#34;,&#34;contours&#34;:{&#34;z&#34;:{&#34;show&#34;:true,&#34;usecolormap&#34;:true,&#34;highlightcolor&#34;:&#34;#ff0000&#34;,&#34;project&#34;:{&#34;z&#34;:true}}},&#34;inherit&#34;:true}},&#34;layout&#34;:{&#34;margin&#34;:{&#34;b&#34;:40,&#34;l&#34;:60,&#34;t&#34;:25,&#34;r&#34;:10},&#34;scene&#34;:{&#34;camera&#34;:{&#34;eye&#34;:{&#34;x&#34;:1.87,&#34;y&#34;:0.88,&#34;z&#34;:-0.64}},&#34;xaxis&#34;:{&#34;title&#34;:[]},&#34;yaxis&#34;:{&#34;title&#34;:[]},&#34;zaxis&#34;:{&#34;title&#34;:&#34;var_mat&#34;}},&#34;hovermode&#34;:&#34;closest&#34;,&#34;showlegend&#34;:false,&#34;legend&#34;:{&#34;yanchor&#34;:&#34;top&#34;,&#34;y&#34;:0.5}},&#34;source&#34;:&#34;A&#34;,&#34;config&#34;:{&#34;showSendToCloud&#34;:false},&#34;data&#34;:[{&#34;colorbar&#34;:{&#34;title&#34;:&#34;var_mat&#34;,&#34;ticklen&#34;:2,&#34;len&#34;:0.5,&#34;lenmode&#34;:&#34;fraction&#34;,&#34;y&#34;:1,&#34;yanchor&#34;:&#34;top&#34;},&#34;colorscale&#34;:[[&#34;0&#34;,&#34;rgba(68,1,84,1)&#34;],[&#34;0.0416666666666667&#34;,&#34;rgba(70,19,97,1)&#34;],[&#34;0.0833333333333333&#34;,&#34;rgba(72,32,111,1)&#34;],[&#34;0.125&#34;,&#34;rgba(71,45,122,1)&#34;],[&#34;0.166666666666667&#34;,&#34;rgba(68,58,128,1)&#34;],[&#34;0.208333333333333&#34;,&#34;rgba(64,70,135,1)&#34;],[&#34;0.25&#34;,&#34;rgba(60,82,138,1)&#34;],[&#34;0.291666666666667&#34;,&#34;rgba(56,93,140,1)&#34;],[&#34;0.333333333333333&#34;,&#34;rgba(49,104,142,1)&#34;],[&#34;0.375&#34;,&#34;rgba(46,114,142,1)&#34;],[&#34;0.416666666666667&#34;,&#34;rgba(42,123,142,1)&#34;],[&#34;0.458333333333333&#34;,&#34;rgba(38,133,141,1)&#34;],[&#34;0.5&#34;,&#34;rgba(37,144,140,1)&#34;],[&#34;0.541666666666667&#34;,&#34;rgba(33,154,138,1)&#34;],[&#34;0.583333333333333&#34;,&#34;rgba(39,164,133,1)&#34;],[&#34;0.625&#34;,&#34;rgba(47,174,127,1)&#34;],[&#34;0.666666666666667&#34;,&#34;rgba(53,183,121,1)&#34;],[&#34;0.708333333333333&#34;,&#34;rgba(79,191,110,1)&#34;],[&#34;0.75&#34;,&#34;rgba(98,199,98,1)&#34;],[&#34;0.791666666666667&#34;,&#34;rgba(119,207,85,1)&#34;],[&#34;0.833333333333333&#34;,&#34;rgba(147,214,70,1)&#34;],[&#34;0.875&#34;,&#34;rgba(172,220,52,1)&#34;],[&#34;0.916666666666667&#34;,&#34;rgba(199,225,42,1)&#34;],[&#34;0.958333333333333&#34;,&#34;rgba(226,228,40,1)&#34;],[&#34;1&#34;,&#34;rgba(253,231,37,1)&#34;]],&#34;showscale&#34;:true,&#34;x&#34;:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100],&#34;y&#34;:[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100],&#34;z&#34;:[[0.0300141214765612,0.015686905073093,0.00564093884922246,0.00447256728960355,0.00995490109738018,0.0130378171941865,0.00725655484167828,-0.00232554798509603,-0.00801467720093724,-0.00790263578918598,-0.00586684380172273,-0.00503976012652639,-0.00456780472318001,-0.00268331461816891,0.000485556784993114,0.00291483970576381,0.00310419846129833,0.00197754095554643,0.00105330118737587,0.00158461271469904,0.00455930865447297,0.0102627510155511,0.0162165565814951,0.0193760713693298,0.0195639488111623,0.0194701497541815,0.0210337796708257,0.0226918603753865,0.0221081111780568,0.0192972748291135,0.0166251175189173,0.0157786309103451,0.015320834914587,0.013141952079488,0.00962070316816562,0.00762430715900963,0.0091589006740241,0.0123535086113619,0.0144475321088493,0.01451241822894,0.0134516599587157,0.012184664428522,0.0113758786592171,0.0115914994526642,0.0126039892034018,0.0133920758986437,0.0132433983079006,0.0128192790963617,0.0130612176454187,0.0134560954089633,0.0120361759133872],[0.015686905073093,0.0226633175061417,0.0244188932917484,0.0250220663890372,0.0258019153407324,0.025348163273158,0.0226239217260867,0.0185622655307192,0.0145795755299542,0.0118809819100223,0.011460364200486,0.0136427970615,0.0161148749202248,0.0160327747314867,0.0135243329261398,0.0116890454110662,0.0127990751660581,0.0153004431188909,0.0167891143432511,0.0173100860678814,0.0193573876765801,0.0245339491722834,0.0304523843988157,0.0338539590040724,0.0343832480444693,0.0345881359849426,0.0363282575780583,0.0382053253515058,0.0380840687391034,0.0356116588086777,0.0322177082620627,0.0291246356267592,0.0264160928835393,0.0239139417559029,0.0219667756937601,0.0214499198734321,0.0229121181584461,0.0255041836435166,0.0280467134870814,0.029803440233887,0.0304812318149881,0.0298735894418936,0.0280434804242242,0.0251388192376269,0.021711875112217,0.0187192720325778,0.0169049313606271,0.0160916414016255,0.0158522428499515,0.01530729642547,0.0131250828735328],[0.00564093884922246,0.0244188932917484,0.0404127823425623,0.0483733511242439,0.0480174477822059,0.0440280234846942,0.0403499317976119,0.0371119657865627,0.0335517590970443,0.0303526265888372,0.0296435643360046,0.0324526349389525,0.035152744283584,0.0331828317842279,0.0272677591173969,0.0234183102217875,0.026004021647384,0.0319101495611166,0.0363122500732657,0.0380973901937379,0.0398641478320654,0.0435528802177005,0.0478255817033191,0.0506029719293355,0.0516070386956147,0.0523610379614717,0.0538230640251236,0.0543773005126641,0.0518705141914604,0.0465888704428848,0.0412579332623144,0.0380833303825961,0.0367667012492371,0.0364074277070802,0.0366508994378863,0.0376885139603343,0.0396474612639257,0.0423031433367703,0.0453253497513456,0.0479775655285843,0.0491169711378746,0.0478109208618154,0.0440381258969864,0.0380544047895784,0.0312487428714465,0.0261432922601097,0.0245335471295971,0.0251112973955133,0.0258242178246622,0.025351634247369,0.0231045235574797],[0.00447256728960355,0.0250220663890372,0.0483733511242439,0.0658210619904763,0.0737960986504746,0.0738656199344664,0.0682277414378763,0.0607111433530042,0.0554453449883687,0.0541034188934748,0.055901990858814,0.059498497561025,0.0617408273533381,0.0592276422063684,0.0532303001501739,0.049692855274256,0.0528918336035986,0.0596210061121686,0.0649634904915878,0.0676832204828881,0.0702249458765112,0.0744621022049338,0.0793427260471337,0.0831343126365808,0.0852729502426609,0.0863633201706759,0.0866778286903351,0.0849565483575114,0.0796664880504596,0.0718051109167692,0.0649003343733642,0.0616710344942862,0.0611598429786833,0.0615355063179176,0.0620058163799042,0.0628176104091112,0.0643008086961966,0.0669369601728294,0.0711766273093092,0.0758858192786237,0.0783459919564488,0.0764513991188953,0.0708230606303023,0.0627955601389712,0.0544365433170178,0.0485467178603732,0.0470326094185766,0.0480965264079801,0.0490696898156232,0.0485475588451775,0.0463898309169458],[0.00995490109738018,0.0258019153407324,0.0480174477822059,0.0737960986504746,0.0971085914615697,0.10870177301888,0.102995904418255,0.0896655781362864,0.081799993583024,0.0833119041988271,0.0889376174543645,0.0937835994937921,0.0960328548021177,0.0947403483065957,0.0913260396462496,0.0895748831718718,0.0921893839315523,0.0971309463344363,0.10129314750544,0.104270865706126,0.108360280334708,0.115145590152833,0.122893279873863,0.129099970422491,0.132632271361622,0.133726780892375,0.132535733834645,0.128635652589831,0.121538220159228,0.112574159748106,0.104893234765713,0.1008406212425,0.0992267908756421,0.098035543560513,0.0965617776673574,0.0954114900412902,0.095367918350293,0.097695246427747,0.103646726979766,0.111458756334261,0.11635087444094,0.114697704490176,0.108018873309467,0.099107724487911,0.0904693162179292,0.084320421295265,0.0821118946249729,0.0822810561400769,0.0825592190496153,0.0817673680001241,0.0798161590756366],[0.0130378171941865,0.025348163273158,0.0440280234846942,0.0738656199344664,0.10870177301888,0.131429901425073,0.130338371899877,0.117199239378325,0.109151554151168,0.111744052608463,0.118935157239576,0.125205625814209,0.129141263988743,0.130406449035972,0.129868680057772,0.129598577985106,0.131177622726623,0.134021491522753,0.137061062815098,0.140530208014422,0.145965791500655,0.154228736045967,0.163249590518587,0.170292721388971,0.174149949926465,0.175140552199302,0.173523514301647,0.169051018118542,0.161419129688686,0.151947374787411,0.143578738926672,0.138481517872149,0.135442907580638,0.132469174994164,0.129046543615972,0.12614119351053,0.124904427310549,0.126970654171923,0.133934823992636,0.143706461230417,0.150509664902736,0.149900457099137,0.143403495752272,0.134024472210158,0.124513190276249,0.117363566209445,0.114287591739835,0.113914062663951,0.114141378734128,0.113797207304149,0.112638483329245],[0.00725655484167828,0.0226239217260867,0.0403499317976119,0.0682277414378763,0.102995904418255,0.130338371899877,0.139688182032744,0.137397260506744,0.133823360055384,0.134174652061097,0.138509726555246,0.146085330009431,0.153846414021606,0.158293537808086,0.158999056330915,0.158607120297858,0.159403311653335,0.16170471194128,0.165336738878575,0.170135419462684,0.175947389971655,0.182424713480816,0.188439315162361,0.192711088947525,0.194949003168609,0.195851100558978,0.195717042964027,0.19308095573795,0.186158898282678,0.176003247922498,0.166502699904055,0.160623618434228,0.15714977087869,0.153889591090921,0.150268773980867,0.147330275514936,0.146229194592453,0.148287939051957,0.154740975922443,0.163838107212786,0.170844469911743,0.171861305927171,0.166853349020735,0.1568316981457,0.144658773502766,0.135048316540061,0.131476061460251,0.132143744571539,0.133992284753065,0.135289287908722,0.135629046967152],[-0.00232554798509603,0.0185622655307192,0.0371119657865627,0.0607111433530042,0.0896655781362864,0.117199239378325,0.137397260506744,0.149021050937968,0.152158909046904,0.150528992318004,0.151479317345255,0.160019309553339,0.17117274984456,0.177717176035795,0.178183990982668,0.176858462579558,0.177467053922628,0.180500336734544,0.185609272525172,0.191740163307645,0.197134651598366,0.200408010855296,0.201792587780331,0.201934709781931,0.201704089367035,0.202193824141059,0.203687257405181,0.203189865661295,0.197077963680589,0.186104880523814,0.175400959541291,0.169000153079858,0.165789629595956,0.1634337203065,0.161065507288953,0.159286823481326,0.158833987946666,0.160725829315896,0.165959553302808,0.173410608511967,0.179832686438706,0.182195069327086,0.178698403652472,0.168035338100033,0.153134227850431,0.141159134579828,0.137488888247712,0.139624747338963,0.143184656221075,0.145766370540687,0.146947457223577],[-0.00801467720093724,0.0145795755299542,0.0335517590970443,0.0554453449883687,0.081799993583024,0.109151554151168,0.133823360055384,0.152158909046904,0.160759913976905,0.162051089760505,0.164280153376763,0.173284826371914,0.184250152549762,0.189965437082023,0.189370893621324,0.18755764430121,0.188800283197836,0.193037568943746,0.199106383544097,0.205431500374914,0.210025584183091,0.211435296519902,0.210414957220078,0.208268791568572,0.20625481507554,0.205584833476341,0.206553546822989,0.205795268916695,0.199235499638045,0.187544239635493,0.176135990325352,0.169354995508846,0.166439337958515,0.165382190838407,0.164904232232213,0.164453645143262,0.163936442039167,0.164963430649948,0.169454935750345,0.176647601384842,0.183094390867664,0.185548505510878,0.182030825701433,0.171074994035733,0.155719029247019,0.143505326205363,0.140040182937765,0.142402140335997,0.145642027044141,0.147207893536936,0.146945012119781],[-0.00790263578918598,0.0118809819100223,0.0303526265888372,0.0541034188934748,0.0833119041988271,0.111744052608463,0.134174652061097,0.150528992318004,0.162051089760505,0.170700287551338,0.179151255634655,0.188978321865683,0.197230041086307,0.200018353165535,0.197936248422864,0.196057767628283,0.198383944655527,0.203844472671486,0.210131452167584,0.215632561163899,0.219431055209156,0.220875817626191,0.220257272829271,0.218115273498233,0.215312661145223,0.21303526611469,0.211703065462037,0.20861645111564,0.200474760734835,0.188090698271463,0.176390333969868,0.169382638465077,0.166692815903987,0.166839231539204,0.168089613361411,0.168461052099373,0.166954905361007,0.166553187359872,0.171034412275775,0.179607818029667,0.186913366283649,0.188377265566261,0.183365368612479,0.172349353976725,0.158581939873738,0.148096884178574,0.14520462632401,0.146838672902345,0.148201202752072,0.147091220206974,0.143904555096121],[-0.00586684380172273,0.011460364200486,0.0296435643360046,0.055901990858814,0.0889376174543645,0.118935157239576,0.138509726555246,0.151479317345255,0.164280153376763,0.179151255634655,0.194134442321539,0.207015416909719,0.215285372260236,0.216547915360939,0.212685614130958,0.20985999742071,0.212748494985508,0.219347973081767,0.226063519070894,0.231102545847802,0.234474791840914,0.236211400126787,0.236115684455659,0.233972826276096,0.230460982724484,0.227151286625036,0.224790732613606,0.220674462452998,0.211423082374906,0.197991035415441,0.185666601415132,0.178728193736514,0.176661049081538,0.177732671916507,0.179763491086094,0.180126859813348,0.177508440228303,0.175920882370973,0.180448181283924,0.19018508658607,0.198237102472678,0.198945893456674,0.192639373221394,0.181216192008275,0.168281008165233,0.159144488146665,0.157417469158103,0.159614774347633,0.1606122604985,0.158391638832914,0.154040475012052],[-0.00503976012652639,0.0136427970615,0.0324526349389525,0.059498497561025,0.0937835994937921,0.125205625814209,0.146085330009431,0.160019309553339,0.173284826371914,0.188978321865683,0.207015416909719,0.226109065876101,0.240714743303262,0.244563014165053,0.239192032493299,0.233947541377799,0.236123607806666,0.243449752785962,0.251354795250806,0.257347545901448,0.261016807203268,0.2621094067394,0.260642534865696,0.256757706272572,0.251901309402189,0.248824606448451,0.248855362704169,0.247400421292272,0.238677363741663,0.223596057395594,0.20975865541166,0.203180237592353,0.202363714525955,0.20396716548771,0.205412522534698,0.204885570505838,0.201735186368487,0.199829771641696,0.203924162419897,0.213173923859123,0.221135350177003,0.222354612483207,0.216311175705738,0.203857529124282,0.189059282651913,0.179195166835087,0.179292120516932,0.184811112138843,0.189007860808978,0.189421680781059,0.187875481454371],[-0.00456780472318001,0.0161148749202248,0.035152744283584,0.0617408273533381,0.0960328548021177,0.129141263988743,0.153846414021606,0.171172749844561,0.184250152549762,0.197230041086307,0.215285372260236,0.240714743303262,0.264141654392061,0.273778057962538,0.269502116479285,0.262858202435585,0.263266344191042,0.269620287478599,0.278215275521839,0.28610711893243,0.29111219571012,0.291611942233209,0.288115755804973,0.281735341820846,0.275199716477354,0.272855206772115,0.276772608953709,0.279639324830909,0.272228571166917,0.255241826705762,0.239308832172306,0.232761966132105,0.23301750425598,0.234863600825815,0.23540920982273,0.234084084927079,0.231119034228133,0.229545466111812,0.23291543691702,0.240652454195423,0.248051476711448,0.25073177323223,0.246327861020472,0.233237750290338,0.215832110290119,0.204454269302239,0.206439741046498,0.216054057681938,0.224544341762145,0.228886688889647,0.231786167715914],[-0.00268331461816891,0.0160327747314867,0.0331828317842279,0.0592276422063684,0.0947403483065957,0.130406449035972,0.158293537808086,0.177717176035795,0.189965437082023,0.200018353165535,0.216547915360938,0.244563014165053,0.273778057962538,0.290572798312891,0.292573151941868,0.288651200741483,0.286737733825309,0.289042514381638,0.296222610813786,0.30611901054109,0.313756619998902,0.315175948630781,0.310969671127717,0.302955086674437,0.294940907638863,0.292727259572112,0.299164990782613,0.304961507880513,0.298318983747391,0.279644005272815,0.261547573354341,0.253979104530278,0.254119171117953,0.25607802348289,0.256769361369846,0.255910333902806,0.253830406873757,0.252820756332902,0.25554153363934,0.261859488272072,0.268847967829996,0.273294804653498,0.271331579071523,0.259269362595121,0.241320972989505,0.22960097427405,0.232798630393512,0.244527788254317,0.254931804696063,0.261016412991644,0.266649722847255],[0.000485556784993114,0.0135243329261398,0.0272677591173969,0.0532303001501739,0.0913260396462496,0.129868680057772,0.158999056330915,0.178183990982668,0.189370893621324,0.197936248422864,0.212685614130957,0.239192032493299,0.269502116479285,0.292573151941868,0.304084866530968,0.306439429693472,0.303057606677035,0.300265425619857,0.30480328575577,0.316236859897483,0.326957094436583,0.33064485798658,0.327388486556694,0.318988840468754,0.309791901709214,0.306688773929157,0.313271127157899,0.319490267082992,0.312455188069513,0.29233381903075,0.272353023428209,0.263086482662052,0.262224030835217,0.264331737959722,0.266211221915455,0.266899648450175,0.266091910995561,0.265725022785431,0.268205597825174,0.273848879004003,0.280878738094951,0.286898206164275,0.28739066816697,0.27767308912116,0.261422740636704,0.250677200915191,0.254094213698673,0.26535821852726,0.274730759985274,0.279843297835096,0.285697207017158],[0.00291483970576381,0.0116890454110662,0.0234183102217875,0.049692855274256,0.0895748831718718,0.129598577985106,0.158607120297858,0.176858462579558,0.18755764430121,0.196057767628283,0.20985999742071,0.233947541377799,0.262858202435585,0.288651200741483,0.306439429693472,0.314389455940099,0.312704592994684,0.309204068220854,0.313232618676246,0.325430199741382,0.337731985119672,0.343248592386973,0.341306289683202,0.332931048721084,0.322502032644519,0.317751596028588,0.322945736593217,0.327901860910561,0.319408078209404,0.29765805792069,0.276251029677522,0.266088035103276,0.26494596200812,0.26741130770582,0.270155472518723,0.271934759777765,0.272178336907421,0.27264423587875,0.275594391087112,0.281489521543979,0.288989130876933,0.296033547649337,0.297999655017049,0.289977868944833,0.275209671095333,0.265087608829077,0.267839041596672,0.277613000565924,0.285352127040801,0.289202483083125,0.294513551512573],[0.00310419846129833,0.0127990751660581,0.026004021647384,0.0528918336035986,0.0921893839315523,0.131177622726623,0.159403311653335,0.177467053922628,0.188800283197836,0.198383944655527,0.212748494985508,0.236123607806666,0.263266344191042,0.286737733825309,0.303057606677035,0.312704592994684,0.317105958549478,0.320795024198311,0.328855480815721,0.341169712939617,0.352418798771269,0.35791411030228,0.356392769700643,0.347634698529288,0.335706140920473,0.328959663575778,0.332178669150744,0.33512445671338,0.324411072215951,0.300642835576825,0.278414340680476,0.269212797906219,0.26966279248818,0.27282133348202,0.275151272423422,0.276521303328098,0.277252984769834,0.278887013123408,0.283196363791438,0.290286387461154,0.298594810104402,0.305911837133245,0.307727613410256,0.299305263018981,0.283911780284874,0.2728180297753,0.274256187773986,0.282911699996743,0.290363130038896,0.294624453490113,0.300145057934403],[0.00197754095554643,0.0153004431188909,0.0319101495611166,0.0596210061121686,0.0971309463344363,0.134021491522753,0.16170471194128,0.180500336734544,0.193037568943746,0.203844472671486,0.219347973081767,0.243449752785962,0.269620287478599,0.289042514381637,0.300265425619857,0.309204068220854,0.320795024198311,0.334779962483662,0.349582114419545,0.363171397029049,0.37306441301572,0.377071908776566,0.374260042755413,0.36420041359492,0.350871125241779,0.342656786946715,0.344349675078645,0.345606385730735,0.332936500117839,0.30749841883916,0.285099361878255,0.277894716559139,0.280884918805161,0.285014172433834,0.286574313382245,0.287204809707052,0.288632814369124,0.292006196968851,0.298266092384556,0.306929616209746,0.316089864753118,0.323293649031453,0.324150294421663,0.314137195281634,0.296837874960971,0.283941985800991,0.2841000136905,0.292396017144489,0.300764836732139,0.306716257668493,0.313335009814453],[0.00105330118737587,0.0167891143432511,0.0363122500732657,0.0649634904915878,0.10129314750544,0.137061062815098,0.165336738878575,0.185609272525172,0.199106383544097,0.210131452167584,0.226063519070894,0.251354795250806,0.278215275521839,0.296222610813786,0.30480328575577,0.313232618676246,0.328855480815721,0.349582114419545,0.370984151742953,0.389094311990697,0.400406401317044,0.402341684864012,0.395951074689911,0.383309110744288,0.369163304706409,0.360934139985263,0.362547165055812,0.36348332400828,0.350264985949383,0.324423770577444,0.302500548182388,0.297055887456202,0.3021188462484,0.307373832604049,0.309134496410136,0.310343729395571,0.313679062288349,0.319603670188119,0.327992114572648,0.337913388479374,0.347630916505408,0.354837546540918,0.35508391850748,0.3437550001667,0.324742995420216,0.310447344309692,0.3101171483734,0.318920635807337,0.328733235184467,0.336661005466127,0.345040636002025],[0.00158461271469904,0.0173100860678814,0.0380973901937379,0.0676832204828881,0.104270865706126,0.140530208014422,0.170135419462684,0.191740163307645,0.205431500374914,0.215632561163899,0.231102545847802,0.257347545901448,0.28610711893243,0.30611901054109,0.316236859897483,0.325430199741382,0.341169712939617,0.363171397029049,0.389094311990697,0.413877394668567,0.429739458769652,0.431049389052446,0.421249419374843,0.406064538201852,0.39155133264059,0.384097988440287,0.386666813598334,0.388458935775705,0.375894171990615,0.350548981412123,0.329156465360131,0.324417648570495,0.330269311677518,0.336262693460866,0.338975973627527,0.342014272811809,0.348387788586863,0.357504949598187,0.367888852076066,0.378410118034793,0.388286895272678,0.39594582808551,0.396587107492231,0.385004366348378,0.365192506093068,0.350347696748992,0.350321470200624,0.359986585156321,0.370722880057251,0.379700972961929,0.389882261546216],[0.00455930865447297,0.0193573876765801,0.0398641478320654,0.0702249458765112,0.108360280334708,0.145965791500655,0.175947389971655,0.197134651598366,0.210025584183091,0.219431055209156,0.234474791840914,0.261016807203268,0.29111219571012,0.313756619998902,0.326957094436583,0.337731985119672,0.352418798771269,0.37306441301572,0.400406401317044,0.429739458769652,0.450915402098339,0.456227225263344,0.448679218709221,0.43399327559022,0.418806196598807,0.410669689965659,0.413411559059499,0.415804873446741,0.40353871876728,0.37793526971434,0.355949790034467,0.350500579454025,0.355639283522414,0.361021505897904,0.363677148260339,0.368010410311134,0.377389876800323,0.389759186059976,0.401796610629334,0.412270451715893,0.422039039195408,0.430764527316019,0.432960884568757,0.422295336741163,0.402562095543856,0.387682358610529,0.387994106900862,0.39774123973533,0.407466892609289,0.415137602465859,0.426143307695915],[0.0102627510155511,0.0245339491722834,0.0435528802177005,0.0744621022049338,0.115145590152833,0.154228736045967,0.182424713480816,0.200408010855296,0.211435296519902,0.220875817626191,0.236211400126787,0.262109406739399,0.291611942233209,0.315175948630781,0.33064485798658,0.343248592386973,0.35791411030228,0.377071908776566,0.402341684864012,0.431049389052446,0.456227225263344,0.471713187952435,0.475315172245749,0.466116373399275,0.44970496080387,0.438174077985257,0.439084189309815,0.440733742656996,0.427329602525772,0.399728810463848,0.375438585067662,0.367819908526032,0.370753134432285,0.373607043309506,0.373997849489237,0.377789201111481,0.389187998900115,0.404339817600011,0.417561860121391,0.427471401556844,0.436985789181323,0.447303940848557,0.452003218086965,0.443239184389206,0.424289997295981,0.409556408396027,0.409624129776975,0.41788435133975,0.423866209365925,0.427140109465569,0.437317726577243],[0.0162165565814951,0.0304523843988157,0.0478255817033191,0.0793427260471338,0.122893279873863,0.163249590518587,0.188439315162361,0.201792587780331,0.210414957220078,0.220257272829271,0.236115684455659,0.260642534865696,0.288115755804973,0.310969671127718,0.327388486556694,0.341306289683202,0.356392769700643,0.374260042755413,0.395951074689911,0.421249419374843,0.448679218709221,0.475315172245749,0.492653238320889,0.491359229692647,0.475083372807843,0.460460307802116,0.458942148751755,0.458992746593247,0.444068798352341,0.414644974161663,0.388213917260719,0.378121765487047,0.378168987573464,0.377661321888484,0.374913305773777,0.377248275544171,0.389748533039457,0.406965494551783,0.421086008099859,0.430464443312404,0.439622691428143,0.450989028425408,0.457544656787058,0.450414823856973,0.432358481381503,0.417768285509471,0.417094601932727,0.42299538157567,0.424227190249541,0.422121121075806,0.430582794486151],[0.0193760713693298,0.0338539590040724,0.0506029719293355,0.0831343126365808,0.129099970422491,0.170292721388971,0.192711088947525,0.201934709781931,0.208268791568572,0.218115273498233,0.233972826276096,0.256757706272572,0.281735341820845,0.302955086674437,0.318988840468754,0.332931048721084,0.347634698529288,0.36420041359492,0.383309110744288,0.406064538201852,0.43399327559022,0.466116373399275,0.491359229692647,0.496771232159396,0.484303531324282,0.470809040547772,0.46829506710943,0.466794883037271,0.451513381679334,0.422953449440548,0.396915965782739,0.38544867037553,0.382926223188107,0.379686126428383,0.374831462072606,0.376230891865352,0.389241041266658,0.407645941943051,0.422630307690389,0.432136955591859,0.440866806017986,0.451495296269285,0.457420609055407,0.450202304850737,0.432455846616029,0.417852599798406,0.416199279096981,0.419921230569029,0.417696722356713,0.411964100245248,0.418921787662896],[0.0195639488111623,0.0343832480444693,0.0516070386956147,0.0852729502426609,0.132632271361622,0.174149949926465,0.194949003168609,0.201704089367035,0.20625481507554,0.215312661145223,0.230460982724484,0.251901309402189,0.275199716477354,0.294940907638863,0.309791901709214,0.322502032644519,0.335706140920473,0.350871125241779,0.369163304706409,0.39155133264059,0.418806196598807,0.44970496080387,0.475083372807843,0.484303531324282,0.4784961826378,0.470560720604065,0.469663561445729,0.467992489536655,0.454029492570107,0.428650367716082,0.40512472162131,0.393582438634855,0.389439068788739,0.384767773448362,0.379374196969909,0.38079646670035,0.394092004671593,0.413050632004732,0.428916568775937,0.439173916265262,0.447546656956644,0.456126506677243,0.459390917895988,0.450343846596568,0.431880843911928,0.416789056124265,0.414162394520702,0.416601552990779,0.413172633257409,0.406482117247161,0.41267686709026],[0.0194701497541815,0.0345881359849426,0.0523610379614717,0.0863633201706759,0.133726780892375,0.175140552199302,0.195851100558978,0.202193824141059,0.205584833476341,0.21303526611469,0.227151286625036,0.248824606448451,0.272855206772115,0.292727259572112,0.306688773929156,0.317751596028588,0.328959663575778,0.342656786946715,0.360934139985263,0.384097988440287,0.410669689965659,0.438174077985257,0.460460307802116,0.470809040547772,0.470560720604065,0.469115575603143,0.472779236162325,0.474077243404792,0.462592335719025,0.439458303186664,0.417359987582511,0.406044181113312,0.401496599158257,0.396577111193187,0.391377322675403,0.393220575043668,0.406984823385701,0.426508784170891,0.443127157996766,0.454057902463434,0.462402232173585,0.469814678020682,0.471139860930387,0.459943837840332,0.439542676278332,0.423002454362375,0.419638658976955,0.422068758056881,0.419303690994989,0.413417849679406,0.41954907849355],[0.0210337796708257,0.0363282575780583,0.0538230640251236,0.0866778286903351,0.132535733834645,0.173523514301647,0.195717042964027,0.203687257405181,0.206553546822989,0.211703065462037,0.224790732613606,0.248855362704169,0.276772608953709,0.299164990782613,0.313271127157899,0.322945736593217,0.332178669150744,0.344349675078645,0.362547165055812,0.386666813598334,0.413411559059499,0.439084189309815,0.458942148751755,0.46829506710943,0.469663561445729,0.472779236162324,0.48360904363182,0.491807243355981,0.483588029512162,0.459842077823593,0.436136545559384,0.424554952905488,0.420693840142059,0.4163763933165,0.411438785581337,0.413730177194226,0.428485347922813,0.449087992599913,0.466245834218447,0.4772629818291,0.486039930540316,0.494647711593813,0.49669230318913,0.484169386589381,0.460711868512451,0.44158988113099,0.437839440090394,0.441536229630547,0.440592365552886,0.436179795156215,0.442730297236699],[0.0226918603753865,0.0382053253515058,0.0543773005126641,0.0849565483575114,0.128635652589831,0.169051018118542,0.19308095573795,0.203189865661295,0.205795268916695,0.20861645111564,0.220674462452998,0.247400421292272,0.279639324830909,0.304961507880513,0.319490267082992,0.327901860910561,0.33512445671338,0.345606385730735,0.36348332400828,0.388458935775705,0.415804873446741,0.440733742656996,0.458992746593247,0.466794883037271,0.467992489536655,0.474077243404792,0.491807243355981,0.507677692879297,0.503896944557904,0.480587427684073,0.455785648259172,0.44368092602074,0.439958344049395,0.436039663502974,0.4316896020926,0.435015834082681,0.451340200927786,0.473390263877326,0.491077480554345,0.501960036355071,0.511242844448911,0.521749517586555,0.525448601144149,0.512201578850094,0.485824153938282,0.464086249148102,0.459953954192522,0.464751205895275,0.46499924937509,0.461199799648683,0.467835041630759],[0.0221081111780568,0.0380840687391034,0.0518705141914604,0.0796664880504596,0.121538220159228,0.161419129688686,0.186158898282678,0.197077963680589,0.199235499638045,0.200474760734835,0.211423082374906,0.238677363741663,0.272228571166917,0.298318983747391,0.312455188069513,0.319408078209404,0.324411072215951,0.332936500117839,0.350264985949383,0.375894171990615,0.40353871876728,0.427329602525772,0.444068798352341,0.451513381679334,0.454029492570107,0.462592335719025,0.483588029512162,0.503896944557905,0.506227456261832,0.48949010008663,0.46879757155209,0.456414732531753,0.450397343347703,0.445509862382192,0.442519137322143,0.448194405159151,0.466632497873868,0.490196733611043,0.508662304073023,0.5197451973432,0.529102197886016,0.539854500427431,0.543599932673212,0.529687626975937,0.502006082931013,0.478983167376673,0.474042569654484,0.478062683511896,0.476929702418906,0.471344663130109,0.476823445684704],[0.0192972748291135,0.0356116588086776,0.0465888704428848,0.0718051109167692,0.112574159748106,0.151947374787411,0.176003247922498,0.186104880523813,0.187544239635493,0.188090698271463,0.197991035415441,0.223596057395594,0.255241826705762,0.279644005272815,0.29233381903075,0.29765805792069,0.300642835576825,0.30749841883916,0.324423770577444,0.350548981412123,0.37793526971434,0.399728810463848,0.414644974161663,0.422953449440548,0.428650367716082,0.439458303186664,0.459842077823594,0.480587427684073,0.48949010008663,0.484230845366375,0.472375416874993,0.460698163707857,0.451088686975665,0.444296767638183,0.442943624095666,0.451521912188858,0.47214524953392,0.497085633467737,0.516481498387758,0.527988647690225,0.53678025377018,0.54578138088254,0.547617292200202,0.532915275809014,0.505573049014237,0.48275875834055,0.476829521694732,0.478590441778143,0.474134533299673,0.465100874572452,0.468674607513855],[0.0166251175189173,0.0322177082620627,0.0412579332623144,0.0649003343733642,0.104893234765713,0.143578738926672,0.166502699904055,0.175400959541291,0.176135990325352,0.176390333969868,0.185666601415132,0.20975865541166,0.239308832172306,0.261547573354341,0.272353023428209,0.276251029677522,0.278414340680476,0.285099361878255,0.302500548182388,0.329156465360131,0.355949790034467,0.375438585067662,0.388213917260719,0.396915965782739,0.40512472162131,0.417359987582511,0.436136545559384,0.455785648259172,0.46879757155209,0.472375416874993,0.468435111231379,0.459422170015031,0.449080840343203,0.441476994009423,0.440606162951622,0.450393539252134,0.472361361980421,0.498432291172835,0.518457243656538,0.529834621887771,0.53751031395185,0.54443319605555,0.544251490695122,0.528812802680059,0.502029288859946,0.479877658124455,0.473702912379025,0.474225042628651,0.467709999290762,0.45657461194633,0.459386589339875],[0.0157786309103451,0.0291246356267592,0.0380833303825961,0.0616710344942862,0.1008406212425,0.138481517872149,0.160623618434228,0.169000153079858,0.169354995508846,0.169382638465077,0.178728193736514,0.203180237592353,0.232761966132105,0.253979104530278,0.263086482662052,0.266088035103276,0.269212797906219,0.277894716559139,0.297055887456202,0.324417648570495,0.350500579454025,0.367819908526032,0.378121765487047,0.38544867037553,0.393582438634855,0.406044181113312,0.424554952905488,0.44368092602074,0.456414732531752,0.460698163707857,0.459422170015031,0.455349888117668,0.449872476135279,0.444155568067038,0.442066619777388,0.450174908996043,0.47205200752875,0.498808781421859,0.518817411678937,0.529109381436008,0.535375475961557,0.541203508738676,0.540263440520645,0.524279252988556,0.497245062359597,0.475425119387053,0.470333511356097,0.472349735238402,0.467288600496787,0.457500998193171,0.461873900988569],[0.015320834914587,0.0264160928835393,0.0367667012492371,0.0611598429786833,0.0992267908756421,0.135442907580638,0.15714977087869,0.165789629595956,0.166439337958515,0.166692815903987,0.176661049081538,0.202363714525955,0.23301750425598,0.254119171117953,0.262224030835217,0.26494596200812,0.26966279248818,0.280884918805161,0.3021188462484,0.330269311677518,0.355639283522414,0.370753134432285,0.378168987573464,0.382926223188107,0.389439068788739,0.401496599158257,0.420693840142059,0.439958344049395,0.450397343347703,0.451088686975665,0.449080840343203,0.449872476135279,0.451376901968089,0.44988736596414,0.448051597036438,0.454871804888492,0.475976224283362,0.502392063128317,0.521892469247847,0.531363112983211,0.536802187192439,0.542042016419592,0.540666665428192,0.524246217019632,0.496956662604507,0.475579902202605,0.472015999154859,0.476445338154734,0.474326860754641,0.467414468485694,0.473757022857713],[0.013141952079488,0.0239139417559029,0.0364074277070802,0.0615355063179176,0.098035543560513,0.132469174994164,0.153889591090921,0.1634337203065,0.165382190838407,0.166839231539204,0.177732671916507,0.20396716548771,0.234863600825815,0.25607802348289,0.264331737959722,0.26741130770582,0.27282133348202,0.285014172433834,0.307373832604049,0.336262693460866,0.361021505897904,0.373607043309506,0.377661321888484,0.379686126428384,0.384767773448362,0.396577111193187,0.4163763933165,0.436039663502974,0.445509862382192,0.444296767638183,0.441476994009423,0.444155568067038,0.44988736596414,0.454087083196024,0.457858625031747,0.467995106514124,0.488749400593422,0.513223984062976,0.532025928598614,0.54248276607584,0.548642488569836,0.552915213701676,0.549990785589102,0.533117094808669,0.506768673133801,0.486646693534791,0.483833995147439,0.488987622430972,0.488309143092758,0.482972478937609,0.489123905867787],[0.00962070316816562,0.0219667756937601,0.0366508994378863,0.0620058163799043,0.0965617776673574,0.129046543615972,0.150268773980867,0.161065507288953,0.164904232232213,0.168089613361412,0.179763491086095,0.205412522534698,0.23540920982273,0.256769361369846,0.266211221915455,0.270155472518723,0.275151272423422,0.286574313382245,0.309134496410136,0.338975973627527,0.363677148260339,0.373997849489237,0.374913305773777,0.374831462072606,0.379374196969909,0.391377322675403,0.411438785581337,0.4316896020926,0.442519137322143,0.442943624095666,0.440606162951622,0.442066619777388,0.448051597036438,0.457858625031747,0.471457839062233,0.489491979422758,0.511752752149262,0.53451075146009,0.55327142593128,0.566188267317039,0.574062810549737,0.576978154350557,0.57168312334756,0.554459777554331,0.530026666886978,0.511538831164126,0.508179224538887,0.51177524286709,0.510371975484521,0.50481592197545,0.508754992172626],[0.00762430715900963,0.0214499198734321,0.0376885139603343,0.0628176104091112,0.0954114900412902,0.12614119351053,0.147330275514936,0.159286823481326,0.164453645143262,0.168461052099373,0.180126859813348,0.204885570505838,0.234084084927079,0.255910333902806,0.266899648450175,0.271934759777765,0.276521303328098,0.287204809707052,0.310343729395571,0.342014272811809,0.368010410311134,0.377789201111481,0.377248275544171,0.376230891865352,0.38079646670035,0.393220575043668,0.413730177194226,0.435015834082681,0.448194405159151,0.451521912188858,0.450393539252133,0.450174908996043,0.454871804888492,0.467995106514124,0.489491979422758,0.515745875129392,0.543133321982381,0.568622932017401,0.58939272141059,0.604032520366637,0.612543973118782,0.614574451294114,0.608108703220587,0.591006647618568,0.567817206203912,0.549778303687962,0.54475151836718,0.545929738009707,0.54330405084826,0.537569126338575,0.540123215159413],[0.0091589006740241,0.0229121181584461,0.0396474612639257,0.0643008086961966,0.095367918350293,0.124904427310549,0.146229194592453,0.158833987946666,0.163936442039167,0.166954905361007,0.177508440228303,0.201735186368487,0.231119034228132,0.253830406873757,0.266091910995561,0.272178336907421,0.277252984769834,0.288632814369124,0.313679062288349,0.348387788586863,0.377389876800323,0.389187998900115,0.389748533039457,0.389241041266658,0.394092004671593,0.406984823385701,0.428485347922813,0.451340200927786,0.466632497873868,0.47214524953392,0.472361361980421,0.47205200752875,0.475976224283362,0.488749400593422,0.511752752149262,0.543133321982381,0.579891489816235,0.615003446952348,0.640693227552964,0.655024335003,0.661899741910047,0.66410144349512,0.658911965568111,0.642567491498452,0.618860277638933,0.599138653325696,0.5916170129157,0.590659911199867,0.587575328027475,0.58300659709459,0.586932405944075],[0.0123535086113619,0.0255041836435166,0.0423031433367703,0.0669369601728294,0.097695246427747,0.126970654171923,0.148287939051957,0.160725829315896,0.164963430649948,0.166553187359872,0.175920882370973,0.199829771641696,0.229545466111812,0.252820756332902,0.265725022785431,0.27264423587875,0.278887013123408,0.292006196968851,0.319603670188119,0.357504949598187,0.389759186059976,0.404339817600011,0.406965494551783,0.407645941943052,0.413050632004732,0.426508784170891,0.449087992599913,0.473390263877326,0.490196733611043,0.497085633467737,0.498432291172835,0.498808781421859,0.502392063128317,0.513223984062976,0.53451075146009,0.568622932017401,0.615003446952348,0.661529964350107,0.693685379505064,0.708373019034013,0.713916640876153,0.716660320288563,0.713043239830729,0.697407018116191,0.672802436012822,0.650989436642837,0.640775220956778,0.637641384304702,0.634093496532438,0.630810773091416,0.636646075038659],[0.0144475321088493,0.0280467134870814,0.0453253497513456,0.0711766273093092,0.103646726979766,0.133934823992636,0.154740975922443,0.165959553302808,0.169454935750345,0.171034412275775,0.180448181283924,0.203924162419897,0.23291543691702,0.25554153363934,0.268205597825174,0.275594391087112,0.283196363791438,0.298266092384556,0.327992114572648,0.367888852076066,0.401796610629334,0.417561860121391,0.421086008099859,0.422630307690389,0.428916568775937,0.443127157996766,0.466245834218447,0.491077480554345,0.508662304073023,0.516481498387758,0.518457243656538,0.518817411678937,0.521892469247847,0.532025928598614,0.55327142593128,0.58939272141059,0.640693227552964,0.693685379505064,0.731958672093633,0.75117309266341,0.759059121077132,0.761790173772067,0.757212197393526,0.741394265942365,0.717420333900737,0.695389236232093,0.68298265091228,0.676993648752599,0.671773520528878,0.668122107397169,0.673287800893748],[0.01451241822894,0.029803440233887,0.0479775655285843,0.0758858192786237,0.111458756334261,0.143706461230417,0.163838107212786,0.173410608511967,0.176647601384842,0.179607818029667,0.19018508658607,0.213173923859123,0.240652454195423,0.261859488272072,0.273848879004003,0.281489521543979,0.290286387461154,0.306929616209746,0.337913388479374,0.378410118034794,0.412270451715893,0.427471401556844,0.430464443312404,0.432136955591859,0.439173916265262,0.454057902463434,0.4772629818291,0.501960036355071,0.5197451973432,0.527988647690225,0.529834621887771,0.529109381436008,0.531363112983211,0.54248276607584,0.566188267317039,0.604032520366637,0.655024335003,0.708373019034013,0.751173092663411,0.778226097529673,0.792040596706031,0.795054719943551,0.788084512150767,0.771682049115599,0.749655104696312,0.72906715082152,0.715289796331835,0.7063609893558,0.698680729923973,0.693144760907573,0.695144568018487],[0.0134516599587157,0.0304812318149881,0.0491169711378746,0.0783459919564488,0.11635087444094,0.150509664902736,0.170844469911743,0.179832686438706,0.183094390867664,0.186913366283649,0.198237102472678,0.221135350177003,0.248051476711448,0.268847967829996,0.280878738094951,0.288989130876933,0.298594810104402,0.316089864753118,0.347630916505408,0.388286895272678,0.422039039195408,0.436985789181323,0.439622691428143,0.440866806017986,0.447546656956644,0.462402232173585,0.486039930540316,0.511242844448911,0.529102197886016,0.53678025377018,0.53751031395185,0.535375475961557,0.536802187192439,0.548642488569836,0.574062810549737,0.612543973118782,0.661899741910047,0.713916640876153,0.759059121077132,0.792040596706031,0.811823445088911,0.818042298701227,0.812281860505905,0.796706957442559,0.77561236261166,0.755422795274529,0.741041135892844,0.730912484310399,0.722030820366355,0.715146602345967,0.714766766980591],[0.012184664428522,0.0298735894418936,0.0478109208618154,0.0764513991188953,0.114697704490176,0.149900457099137,0.171861305927171,0.182195069327086,0.185548505510878,0.188377265566261,0.198945893456674,0.222354612483207,0.25073177323223,0.273294804653498,0.286898206164275,0.296033547649337,0.305911837133245,0.323293649031453,0.354837546540918,0.39594582808551,0.430764527316019,0.447303940848557,0.450989028425408,0.451495296269285,0.456126506677243,0.469814678020682,0.494647711593813,0.521749517586555,0.539854500427431,0.545781380882539,0.54443319605555,0.541203508738676,0.542042016419592,0.552915213701676,0.576978154350557,0.614574451294114,0.66410144349512,0.716660320288563,0.761790173772067,0.795054719943551,0.818042298701227,0.831782934255224,0.834025627384994,0.821986847722224,0.799500733226275,0.777019090184183,0.7626638177211,0.754086287475037,0.746539338907004,0.740315104458059,0.740745009549303],[0.0113758786592171,0.0280434804242242,0.0440381258969864,0.0708230606303023,0.108018873309467,0.143403495752272,0.166853349020735,0.178698403652472,0.182030825701433,0.183365368612479,0.192639373221394,0.216311175705738,0.246327861020472,0.271331579071523,0.28739066816697,0.297999655017049,0.307727613410256,0.324150294421663,0.35508391850748,0.396587107492231,0.432960884568757,0.452003218086965,0.457544656787058,0.457420609055407,0.459390917895988,0.471139860930387,0.49669230318913,0.525448601144149,0.543599932673212,0.547617292200202,0.544251490695122,0.540263440520645,0.540666665428192,0.549990785589103,0.57168312334756,0.608108703220587,0.65891196556811,0.713043239830729,0.757212197393526,0.788084512150767,0.812281860505905,0.834025627384994,0.846204553107233,0.839402248954447,0.816347064838136,0.79191208929948,0.777821061626795,0.771088195639605,0.765329870251256,0.760592032978596,0.763350199941972],[0.0115914994526642,0.0251388192376269,0.0380544047895784,0.0627955601389712,0.099107724487911,0.134024472210158,0.1568316981457,0.168035338100033,0.171074994035733,0.172349353976725,0.181216192008275,0.203857529124282,0.233237750290338,0.259269362595121,0.27767308912116,0.289977868944833,0.299305263018981,0.314137195281635,0.3437550001667,0.385004366348379,0.422295336741163,0.443239184389206,0.450414823856973,0.450202304850737,0.450343846596568,0.459943837840332,0.484169386589381,0.512201578850094,0.529687626975937,0.532915275809014,0.528812802680059,0.524279252988556,0.524246217019632,0.533117094808669,0.554459777554332,0.591006647618568,0.642567491498452,0.697407018116191,0.741394265942365,0.771682049115599,0.79670695744256,0.821986847722224,0.839402248954446,0.837968384106799,0.81921307224918,0.79717672855382,0.783171392528298,0.775419497351596,0.769108763063164,0.764893743882469,0.768895828209003],[0.0126039892034018,0.021711875112217,0.0312487428714465,0.0544365433170178,0.0904693162179292,0.124513190276249,0.144658773502766,0.153134227850431,0.155719029247019,0.158581939873738,0.168281008165233,0.189059282651913,0.215832110290119,0.241320972989505,0.261422740636704,0.275209671095333,0.283911780284874,0.296837874960971,0.324742995420216,0.365192506093068,0.402562095543856,0.424289997295981,0.432358481381503,0.432455846616029,0.431880843911928,0.439542676278332,0.460711868512451,0.485824153938282,0.502006082931013,0.505573049014237,0.502029288859946,0.497245062359597,0.496956662604507,0.5067686731338,0.530026666886978,0.567817206203912,0.618860277638933,0.672802436012822,0.717420333900737,0.749655104696312,0.77561236261166,0.799500733226275,0.816347064838136,0.81921307224918,0.808757619221069,0.793236718475193,0.77965794064671,0.768713844728515,0.759639720544742,0.754464983981018,0.758013176984464],[0.0133920758986437,0.0187192720325778,0.0261432922601097,0.0485467178603732,0.084320421295265,0.117363566209445,0.135048316540061,0.141159134579828,0.143505326205363,0.148096884178574,0.159144488146665,0.179195166835087,0.204454269302239,0.22960097427405,0.250677200915191,0.265087608829077,0.2728180297753,0.283941985800991,0.310447344309692,0.350347696748992,0.387682358610529,0.409556408396027,0.417768285509471,0.417852599798406,0.416789056124265,0.423002454362375,0.44158988113099,0.464086249148102,0.478983167376673,0.48275875834055,0.479877658124455,0.475425119387052,0.475579902202605,0.486646693534791,0.511538831164126,0.549778303687962,0.599138653325696,0.650989436642838,0.695389236232093,0.72906715082152,0.755422795274529,0.777019090184183,0.79191208929948,0.79717672855382,0.793236718475193,0.783864544186173,0.772508441505872,0.760737253457883,0.749743800435967,0.742878890922022,0.745651321486086],[0.0132433983079006,0.0169049313606271,0.0245335471295971,0.0470326094185766,0.0821118946249729,0.114287591739835,0.131476061460251,0.137488888247712,0.140040182937765,0.14520462632401,0.157417469158103,0.179292120516932,0.206439741046498,0.232798630393512,0.254094213698673,0.267839041596672,0.274256187773986,0.2841000136905,0.3101171483734,0.350321470200625,0.387994106900862,0.409624129776975,0.417094601932727,0.416199279096981,0.414162394520702,0.419638658976955,0.437839440090394,0.459953954192522,0.474042569654484,0.476829521694731,0.473702912379025,0.470333511356097,0.472015999154859,0.483833995147439,0.508179224538888,0.54475151836718,0.5916170129157,0.640775220956778,0.68298265091228,0.715289796331835,0.741041135892844,0.7626638177211,0.777821061626796,0.783171392528298,0.77965794064671,0.772508441505872,0.765873337377905,0.758848748779751,0.749517114130461,0.741708533689831,0.745000769558399],[0.0128192790963617,0.0160916414016255,0.0251112973955133,0.0480965264079801,0.0822810561400769,0.113914062663951,0.132143744571539,0.139624747338963,0.142402140335997,0.146838672902345,0.159614774347633,0.184811112138843,0.216054057681938,0.244527788254317,0.26535821852726,0.277613000565924,0.282911699996743,0.292396017144489,0.318920635807337,0.359986585156321,0.39774123973533,0.41788435133975,0.42299538157567,0.419921230569029,0.416601552990779,0.422068758056881,0.441536229630547,0.464751205895275,0.478062683511897,0.478590441778143,0.474225042628651,0.472349735238402,0.476445338154734,0.488987622430972,0.51177524286709,0.545929738009707,0.590659911199867,0.637641384304702,0.676993648752599,0.7063609893558,0.730912484310399,0.754086287475036,0.771088195639605,0.775419497351596,0.768713844728515,0.760737253457883,0.758848748779751,0.75936507004516,0.756232969455926,0.752382638643508,0.759727708669011],[0.0130612176454187,0.0158522428499515,0.0258242178246622,0.0490696898156232,0.0825592190496153,0.114141378734128,0.133992284753065,0.143184656221075,0.145642027044141,0.148201202752072,0.1606122604985,0.189007860808978,0.224544341762145,0.254931804696063,0.274730759985274,0.285352127040801,0.290363130038896,0.300764836732139,0.328733235184467,0.370722880057251,0.407466892609289,0.423866209365925,0.424227190249541,0.417696722356713,0.413172633257409,0.419303690994989,0.440592365552886,0.46499924937509,0.476929702418906,0.474134533299673,0.467709999290762,0.467288600496787,0.474326860754641,0.488309143092758,0.510371975484521,0.54330405084826,0.587575328027474,0.634093496532438,0.671773520528878,0.698680729923973,0.722030820366355,0.746539338907004,0.765329870251256,0.769108763063164,0.759639720544742,0.749743800435966,0.749517114130462,0.756232969455926,0.764217043125277,0.773730616715519,0.790970576667741],[0.0134560954089633,0.01530729642547,0.025351634247369,0.0485475588451775,0.0817673680001241,0.113797207304149,0.135289287908722,0.145766370540687,0.147207893536936,0.147091220206974,0.158391638832914,0.189421680781059,0.228886688889647,0.261016412991644,0.279843297835096,0.289202483083125,0.294624453490113,0.306716257668493,0.336661005466127,0.379700972961929,0.415137602465859,0.427140109465569,0.422121121075806,0.411964100245248,0.406482117247161,0.413417849679406,0.436179795156215,0.461199799648683,0.471344663130109,0.465100874572452,0.45657461194633,0.457500998193171,0.467414468485694,0.482972478937609,0.50481592197545,0.537569126338575,0.58300659709459,0.630810773091416,0.668122107397169,0.693144760907573,0.715146602345967,0.740315104458059,0.760592032978596,0.764893743882469,0.754464983981018,0.742878890922022,0.741708533689831,0.752382638643508,0.773730616715519,0.803127594121945,0.836494412362482],[0.0120361759133872,0.0131250828735328,0.0231045235574797,0.0463898309169458,0.0798161590756366,0.112638483329245,0.135629046967152,0.146947457223577,0.146945012119781,0.143904555096121,0.154040475012052,0.187875481454371,0.231786167715914,0.266649722847255,0.285697207017158,0.294513551512573,0.300145057934403,0.313335009814453,0.345040636002025,0.389882261546216,0.426143307695915,0.437317726577243,0.430582794486151,0.418921787662896,0.41267686709026,0.41954907849355,0.442730297236699,0.467835041630759,0.476823445684704,0.468674607513855,0.459386589339875,0.461873900988569,0.473757022857713,0.489123905867787,0.508754992172626,0.540123215159413,0.586932405944075,0.636646075038659,0.673287800893748,0.695144568018487,0.714766766980591,0.740745009549303,0.763350199941972,0.768895828209003,0.758013176984464,0.745651321486086,0.745000769558399,0.759727708669011,0.790970576667741,0.836494412362482,0.890690855519201]],&#34;type&#34;:&#34;surface&#34;,&#34;contours&#34;:{&#34;z&#34;:{&#34;show&#34;:true,&#34;usecolormap&#34;:true,&#34;highlightcolor&#34;:&#34;#ff0000&#34;,&#34;project&#34;:{&#34;z&#34;:true}}},&#34;frame&#34;:null}],&#34;highlight&#34;:{&#34;on&#34;:&#34;plotly_click&#34;,&#34;persistent&#34;:false,&#34;dynamic&#34;:false,&#34;selectize&#34;:false,&#34;opacityDim&#34;:0.2,&#34;selected&#34;:{&#34;opacity&#34;:1},&#34;debounce&#34;:0},&#34;shinyEvents&#34;:[&#34;plotly_hover&#34;,&#34;plotly_click&#34;,&#34;plotly_selected&#34;,&#34;plotly_relayout&#34;,&#34;plotly_brushed&#34;,&#34;plotly_brushing&#34;,&#34;plotly_clickannotation&#34;,&#34;plotly_doubleclick&#34;,&#34;plotly_deselect&#34;,&#34;plotly_afterplot&#34;,&#34;plotly_sunburstclick&#34;],&#34;base_url&#34;:&#34;https://plot.ly&#34;},&#34;evals&#34;:[],&#34;jsHooks&#34;:[]}&lt;/script&gt;
This covariance surface for the Brownian motion random walk we are using for data is interesting in its own right. There is a theoretical result that says that the estimate for the covariance function for this process is &lt;span class=&#34;math inline&#34;&gt;\(\hat{c}(t,s) = min(t,s)\)&lt;/span&gt;. You can find the proof in the book by Kokoszka and Reimherr referenced below. Using the mouse to hover over some points in the graph makes this result seem plausible.&lt;/p&gt;
&lt;div id=&#34;references&#34; class=&#34;section level4&#34;&gt;
&lt;h4&gt;References&lt;/h4&gt;
&lt;div id=&#34;books&#34; class=&#34;section level5&#34;&gt;
&lt;h5&gt;Books&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;Kokoszka, P. and Reimherr, M. (2017). &lt;em&gt;Introduction to Functional Data Analysis&lt;/em&gt;. CRC.&lt;/li&gt;
&lt;li&gt;Ramsay, J.O. and Silverman, B.W. (2005). &lt;em&gt;Functional Data Analysis&lt;/em&gt;. Springer.&lt;/li&gt;
&lt;li&gt;Ramsay, J.0., Hooker, G. and Graves, S. (2009) &lt;em&gt;Functional Data Analysis with R and MATLAB&lt;/em&gt; Springer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;online-resources&#34; class=&#34;section level5&#34;&gt;
&lt;h5&gt;Online Resources&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;Cao, J. (2019). &lt;a href=&#34;https://www.youtube.com/watch?v=SUp_Nq8NwfE&#34;&gt;&lt;em&gt;Functional Data Analysis Course&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Staicu, A. and Park, Y. (2016) &lt;a href=&#34;https://www4.stat.ncsu.edu/~staicu/FDAtutorial/&#34;&gt;&lt;em&gt;Short Course on Applied Functional Data Analysis&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;recommended-papers&#34; class=&#34;section level5&#34;&gt;
&lt;h5&gt;Recommended Papers&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;Sørensen, H. Goldsmith, J. and Sangalli, L. (2013). &lt;a href=&#34;https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.5989&#34;&gt;&lt;em&gt;An introduction with medical applications fo functional data analysis&lt;/em&gt;&lt;/a&gt; Wiley&lt;/li&gt;
&lt;li&gt;Wang, J., Chiou, J. and Müller, H. (2015). &lt;a href=&#34;https://arxiv.org/pdf/1507.05135.pdf&#34;&gt;&lt;em&gt;Review of Functional Data Analysis&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Yao, F., Müller, H, Wang, J. (2012). &lt;a href=&#34;https://anson.ucdavis.edu/~mueller/jasa03-190final.pdf&#34;&gt;&lt;em&gt;Functional Data Analysis for Sparse Longitudinal Data&lt;/em&gt;&lt;/a&gt; JASA J100, I 470&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2021/05/14/basic-fda-descriptive-statistics-with-r/&#39;;&lt;/script&gt;
      </description>
    </item>
    
    <item>
      <title>Introduction to Functional Data Analysis with R</title>
      <link>https://rviews.rstudio.com/2021/05/04/functional-data-analysis-in-r/</link>
      <pubDate>Tue, 04 May 2021 00:00:00 +0000</pubDate>
      
      <guid>https://rviews.rstudio.com/2021/05/04/functional-data-analysis-in-r/</guid>
      <description>
        
&lt;script src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/header-attrs/header-attrs.js&#34;&gt;&lt;/script&gt;


&lt;p&gt;Suppose you have data that looks something like this.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/figure-html/unnamed-chunk-1-1.png&#34; width=&#34;672&#34; /&gt;
This plot might depict 80 measurements for a participant in a clinical trial where each data point represents the change in the level of some protein level. Or it could represent any series of longitudinal data where the measurements are taken at irregular intervals. The curve looks like a time series with obvious correlations among the points, but there are not enough measurements to model the data with the usual time series methods. In a scenario like this, you might find &lt;a href=&#34;https://en.wikipedia.org/wiki/Functional_data_analysis&#34;&gt;Functional Data Analysis&lt;/a&gt; (FDA) to be a viable alternative to the usual multi-level, mixed model approach.&lt;/p&gt;
&lt;p&gt;This post is meant to be a “gentle” introduction to doing FDA with R for someone who is totally new to the subject. I’ll show some “first steps” code, but most of the post will be about providing background and motivation for looking into FDA. I will also point out some of the available resources that a newcommer to FDA should find helpful.&lt;/p&gt;
&lt;p&gt;FDA is a branch of statistics that deals with data that can be conceptualized as a function of an underlying, continuous variable. The data in FDA are smooth curves (or surfaces) in time or space. To fix a mental model of this idea, first consider an ordinary time series. For example, you might think of the daily closing prices of your favorite stock. The data that make up a time series are the individual points which are considered to be random draws from an underlying stochastic process.&lt;/p&gt;
&lt;p&gt;Now, go up a level of abstraction, and consider a space where the whole time series, or rather an imaginary continuous curve that runs through all of your data points is the basic item of analysis. In this conceptual model, the curve comprises an infinite number of points, not just the few you observed. Moreover, unlike in basic time series analysis, the observed points do not need to be equally spaced, and the various curves that make up your data set do not need to be sampled at the same time points.&lt;/p&gt;
&lt;p&gt;Mathematically, the curves are modeled as functions that live in an infinite dimensional vector space, what the mathematicians call a &lt;a href=&#34;https://iopscience.iop.org/article/10.1088/1742-6596/839/1/012002/pdf&#34;&gt;Hilbert Space&lt;/a&gt;. One way to think of this is that you are dealing with the ultimate large p small n problem. Each curve has infinitely many points, not just the 3 or 30 or 3,000 you happen to have.&lt;/p&gt;
&lt;p&gt;The theory of Hilbert Spaces is part of the area of mathematical analysis called &lt;a href=&#34;https://en.wikipedia.org/wiki/Functional_analysis&#34;&gt;Functional Analysis&lt;/a&gt;, a subject usually introduced as part of a second or third course in mathematical analysis, or perhaps in a course on &lt;a href=&#34;https://quantum.phys.cmu.edu/QCQI/qitd114.pdf&#34;&gt;Quantum Mechanics&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It would be a heavy lift to expect someone new to Functional Data Analysis to start with the mathematics. Fortunately, this is not really necessary. The practical applications of FDA and the necessary supporting software have been sufficiently developed so that anyone familiar with the basics of ordinary vector spaces should have sufficient background to get started. The salient points to remember are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hilbert space is an infinite dimensional linear vector space&lt;/li&gt;
&lt;li&gt;The vectors in Hilbert space are functions&lt;/li&gt;
&lt;li&gt;The inner product of two functions in the Hilbert space is defined as the integral of two functions, but it behaves very much like the familiar dot product.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Moreover, for the last twenty years or so mathematical statisticians have been writing R packages to put FDA within the reach of anyone with motivation and minimal R skills. The CRAN Task View on &lt;a href=&#34;https://cran.r-project.org/view=FunctionalData&#34;&gt;Functional Data Analysis&lt;/a&gt; categorizes and provides brief explanations for forty packages that collectively cover most of the established work on FDA. The following graph built with functions from the &lt;a href=&#34;https://cran.r-project.org/package=cranly&#34;&gt;&lt;code&gt;cranly&lt;/code&gt;&lt;/a&gt; package shows part of the network for two core FDA packages.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;fda.png&#34; height = &#34;600&#34; width=&#34;100%&#34;&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://cran.r-project.org/package=fda&#34;&gt;&lt;code&gt;fda&lt;/code&gt;&lt;/a&gt; package emphasized in the network plot above is the logical place for an R user to begin investigating FDA. With thirty-two reverse depends, thirty-eight reverse imports and thirteen reverse suggest, fda is at the root of Functional Data Analysis software for R. Moreover, in a very real sense, it is at the root of modern FDA itself. &lt;code&gt;fda&lt;/code&gt; was written to explicate the theory developed in the 2005 book by Ramsay and Silverman&lt;span class=&#34;math inline&#34;&gt;\(^{1}\)&lt;/span&gt;. Kokoszka and Reimnerr state that the first edition of this book published in 1997: “is largely credited with solidifying FDA as an official subbranch of statistics” (p xiv)&lt;span class=&#34;math inline&#34;&gt;\(^{2}\)&lt;/span&gt;. The &lt;a href=&#34;https://cran.r-project.org/package=refund&#34;&gt;&lt;code&gt;refund&lt;/code&gt;&lt;/a&gt; package is used extensively throughout the book by Kokoszka and Reimnerr.&lt;/p&gt;
&lt;div id=&#34;first-steps&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;First Steps&lt;/h3&gt;
&lt;p&gt;The synthetic data in the figure above were generated by a Wiener, Brownian Motion process, which for the purposes of this post, is just a convenient way to generate a variety of reasonable looking curves. We suppose that the data points shown represent noisy observations generated by a smooth curve f(t). We estimate this curve with the model: &lt;span class=&#34;math inline&#34;&gt;\(y_{i} = f(t_{i}) + \epsilon_{i}\)&lt;/span&gt; where the &lt;span class=&#34;math inline&#34;&gt;\(\epsilon_{i}\)&lt;/span&gt; are normally distributed with mean 0 and variance &lt;span class=&#34;math inline&#34;&gt;\(\sigma^{2}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Notice that the measurement times are randomly selected within the 100 day window and not uniformly spaced.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;set.seed(999)
n_obs &amp;lt;- 80
time_span &amp;lt;- 100
time &amp;lt;- sort(runif(n_obs,0,time_span))
Wiener &amp;lt;- cumsum(rnorm(n_obs)) / sqrt(n_obs)
y_obs &amp;lt;- Wiener + rnorm(n_obs,0,.05)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remember that the task ahead is to represent the entire curve of infinitely many points and not just the handful of observed values. Here is where the linear algebra comes in. The curve is treated as a vector in an infinite dimensional vector space, and what we want is something that will serve as a basis for this curve projected down into the subspace where the measurements live. The standard way to do this for non-periodic data is to construct a &lt;a href=&#34;https://en.wikipedia.org/wiki/B-spline&#34;&gt;B-spline&lt;/a&gt; basis. (B-splines or basis splines are splines designed to have properties that make them suitable for representing vectors.) The code that follows is mostly &lt;em&gt;borrowed&lt;/em&gt; from Jiguo Cao’s Youtube Video Course&lt;span class=&#34;math inline&#34;&gt;\(^{3}\)&lt;/span&gt; which I very highly recommend for anyone just starting with FDA. In his first five videos, Cao explains B-splines and the placement of knots in great detail and derives the formula used in the code to calculates the number of basis elements from the number of knots and the order of the splines.&lt;/p&gt;
&lt;p&gt;Note that we are placing the knots at times equally spaced over the 100 day time span.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;times_basis = seq(0,time_span,1)
knots    = c(seq(0,time_span,5)) #Location of knots
n_knots   = length(knots) #Number of knots
n_order   = 4 # order of basis functions: cubic bspline: order = 3 + 1
n_basis   = length(knots) + n_order - 2;
basis = create.bspline.basis(c(min(times_basis),max(times_basis)),n_basis,n_order,knots)
n_basis&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 23&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and there are 23 basis vectors.&lt;/p&gt;
&lt;p&gt;Next, we use the function &lt;code&gt;eval.basis()&lt;/code&gt; to evaluate the basis functions at the times where our data curve was observed The matrix &lt;code&gt;PHI&lt;/code&gt; contains the values of the 23 basis functions &lt;span class=&#34;math inline&#34;&gt;\(\phi_j(t)\)&lt;/span&gt; evaluated at 80 points.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;PHI = eval.basis(time, basis) 
dim(PHI)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 80 23&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We plot the basis functions and locations of the knots.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;matplot(time,PHI,type=&amp;#39;l&amp;#39;,lwd=1,lty=1, xlab=&amp;#39;time&amp;#39;,ylab=&amp;#39;basis&amp;#39;,cex.lab=1,cex.axis=1)
for (i in 1:n_knots)
{
  abline(v=knots[i], lty=2, lwd=1)
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/figure-html/unnamed-chunk-5-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;The plot shows that for interior points, four basis functions contribute to computing the value of any point. The endpoints, however, are computed from a single basis function.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;estimating-the-basis-coefficients&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Estimating the Basis Coefficients&lt;/h3&gt;
&lt;p&gt;As in ordinary regression, we express the function in terms of the coefficients &lt;span class=&#34;math inline&#34;&gt;\(c_j\)&lt;/span&gt; and basis functions &lt;span class=&#34;math inline&#34;&gt;\(\phi_j\)&lt;/span&gt; using the formula: &lt;span class=&#34;math inline&#34;&gt;\(f(t) = \sum c_j \phi_j(t)\)&lt;/span&gt;. Later we will see how to use built-in &lt;code&gt;fda&lt;/code&gt; functions to estimate the coefficients, but now we follow Cao’s lead and calculate everything from first principles.&lt;/p&gt;
&lt;p&gt;The following code uses matrix least squares equation &lt;span class=&#34;math inline&#34;&gt;\(\hat{c} = (\Phi^t\Phi)^{-1} \Phi^{t}y\)&lt;/span&gt; to estimate the coefficients.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# Least squares estimate
# estimate basis coefficient
M = ginv(t(PHI) %*% PHI) %*% t(PHI)
c_hat = M %*% Wiener&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We compute &lt;span class=&#34;math inline&#34;&gt;\(\hat{y}\)&lt;/span&gt;, the estimates of our observed values, and plot.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;y_hat = PHI %*% c_hat
# Augment data frame for plotting
df &amp;lt;- df %&amp;gt;% mutate(y_hat = y_hat)
p2 &amp;lt;- df %&amp;gt;% ggplot() + 
      geom_line(aes(x = time, y = Wiener), col = &amp;quot;grey&amp;quot;) +
      geom_point(aes(x = time, y = y_obs)) +
      geom_line(aes(x = time, y = y_hat), col = &amp;quot;red&amp;quot;)
p2 + ggtitle(&amp;quot;Original curve and least squares estimate&amp;quot;) + 
      xlab(&amp;quot;time&amp;quot;) + ylab(&amp;quot;f(time)&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/figure-html/unnamed-chunk-7-1.png&#34; width=&#34;672&#34; /&gt;
The gray curve in the plot represents the underlying Brownian motion process, the dots are the observed values (the same as in the first plot), and the red curve represents the least squares “smoothed” estimates.&lt;/p&gt;
&lt;p&gt;Now, we work through the matrix calculations to estimate the variance of the noise and the error bars for &lt;span class=&#34;math inline&#34;&gt;\(\hat{y}\)&lt;/span&gt;.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;# estimate the variance of noise
## SSE = (Y - Xb)&amp;#39;(Y - Xb)
SSE = t(y_hat-y_obs)%*%(y_hat-y_obs)
sigma2 = SSE/(n_obs-n_basis)

# estimate the variance of the fitted curve
# H is the Hat matrix H
# H = X*inv(X&amp;#39;X)*X``
H = PHI %*% M
varYhat = diag(H %*% H * matrix(sigma2,n_obs,n_obs))

# 95% confidence interval

y_hat025 = y_hat-1.96*sqrt(varYhat)
y_hat975 = y_hat+1.96*sqrt(varYhat)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And, we plot. We have a satisfying smoothed representation of our original curve that looks like it would be and adequate starting point for further study. Note that process of using regression to produce a curve from the basis functions is often referred to as “regression smoothing”&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;df &amp;lt;- mutate(df, y_hat025 = y_hat025,
                 y_hat975 = y_hat975)
#names(df) &amp;lt;- c(&amp;quot;time&amp;quot;,&amp;quot;Wiener&amp;quot;,&amp;quot;y_hat&amp;quot;, &amp;quot;y_hat025&amp;quot;, &amp;quot;y_hat975&amp;quot;)
p3 &amp;lt;- df %&amp;gt;% ggplot() + 
      geom_line(aes(x = time, y = Wiener), col = &amp;quot;grey&amp;quot;) +
      geom_point(aes(x = time, y = y_obs)) +
      geom_line(aes(x = time, y = y_hat), col = &amp;quot;red&amp;quot;) +
      geom_line(aes(x = time, y_hat025), col = &amp;quot;green&amp;quot;) +
      geom_line(aes(x = time, y_hat975), col = &amp;quot;green&amp;quot;) 
p3 + ggtitle(&amp;quot;Estimated curve with error bars&amp;quot;) + 
     xlab(&amp;quot;time&amp;quot;) + ylab(&amp;quot;f(time)&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/figure-html/unnamed-chunk-9-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We finish for today, by showing how to do the hard work of estimating coefficients and function values with a single line of code using the &lt;code&gt;fda&lt;/code&gt; function &lt;code&gt;smooth.basis()&lt;/code&gt;. The function takes the arguments &lt;code&gt;argvals&lt;/code&gt; the times we want to use for evaluation as a vector (or matrix or array), &lt;code&gt;y&lt;/code&gt; the observed values, and &lt;code&gt;fdParobj&lt;/code&gt;, an &lt;code&gt;fda&lt;/code&gt; object containing the basis elements.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;Wiener_obj &amp;lt;- smooth.basis(argvals = time, y = y_obs, fdParobj = basis)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we plot our “hand calculated” curve in red and show the &lt;code&gt;smooth.basis()&lt;/code&gt; curve in blue. They are reasonably close, except at the end points, where there is not much data to construct the basis.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;plot(time, Wiener, type = &amp;quot;l&amp;quot;, xlab = &amp;quot;time&amp;quot;, ylab = &amp;quot;f(time)&amp;quot;, 
     main = &amp;quot;Comparison of fda package and naive smoothing estimates&amp;quot;, col = &amp;quot;grey&amp;quot;)
lines(time,y_hat,type = &amp;quot;l&amp;quot;,col=&amp;quot;red&amp;quot;)
lines(Wiener_obj, lwd = 1, col = &amp;quot;blue&amp;quot;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;/2021/05/04/functional-data-analysis-in-r/index_files/figure-html/unnamed-chunk-11-1.png&#34; width=&#34;672&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Note that we have shown the simplest use of &lt;code&gt;smooth.basis()&lt;/code&gt; which is capable of computing penalized regression estimates and more. The &lt;a href=&#34;https://www.rdocumentation.org/packages/fda/versions/5.1.9/topics/smooth.basis&#34;&gt;examples&lt;/a&gt; of using the &lt;code&gt;smooth.basis()&lt;/code&gt; function in the &lt;code&gt;fda&lt;/code&gt; pdf are extensive and worth multiple blog posts. In general, the pdf level documentation for &lt;code&gt;fda&lt;/code&gt; is superb. However, the package lacks vignettes. For a price, the book &lt;em&gt;Functional Data Analysis with R and Matlab&lt;/em&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{4}\)&lt;/span&gt; supplies the equivalent of several the missing vignettes.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;next-steps&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;Next Steps&lt;/h3&gt;
&lt;p&gt;Once you have a basis representation, what’s next? You may be interested in the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;More exploratory work such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Functional_principal_component_analysis&#34;&gt;Functional Principal Components Analysis&lt;/a&gt;, the analog of principal components analysis.&lt;/li&gt;
&lt;li&gt;Clustering curves. See the &lt;a href=&#34;https://cran.r-project.org/package=funHDDC&#34;&gt;funHDDC&lt;/a&gt; package.&lt;/li&gt;
&lt;li&gt;Setting up regression models where either the dependent variable, or some of the independent variables, or both are functional objects. See the &lt;a href=&#34;https://CRAN.R-project.org/package=refund&#34;&gt;refund&lt;/a&gt; package and the book by Kokoszka and Reimnerr&lt;span class=&#34;math inline&#34;&gt;\(^{2}\)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Studying the shape of the curves themselves. For example, the shape of a protein concentration curve may convey some clinical meaning. FDA permits studying the velocity and acceleration of curves, offering the possibility of obtaining more information than the standard practice of looking at the area under the curves. You can explore this with the &lt;code&gt;fda&lt;/code&gt; package (But be sure to check that the order of your basis functions is adequate to compute derivatives.). See the book by Ramsay, Hooker and Graves&lt;span class=&#34;math inline&#34;&gt;\(^{4}\)&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Learning what to do when you have sparse data. See the paper by Yao et al. below&lt;span class=&#34;math inline&#34;&gt;\(^{5}\)&lt;/span&gt; and look into the &lt;a href=&#34;https://cran.r-project.org/package=fdapace&#34;&gt;fdapace&lt;/a&gt; package.&lt;/li&gt;
&lt;li&gt;Working with two and three dimensional medical images&lt;span class=&#34;math inline&#34;&gt;\(^{6}\)&lt;/span&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I would like to make Functional Data Analysis a regular feature on R Views. If you are working with FDA and would like to post, please let me (&lt;a href=&#34;mailto:joseph.rickert@rstudio.com&#34; class=&#34;email&#34;&gt;joseph.rickert@rstudio.com&lt;/a&gt;) know.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&#34;references&#34; class=&#34;section level3&#34;&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;div id=&#34;books&#34; class=&#34;section level4&#34;&gt;
&lt;h4&gt;Books&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{2}\)&lt;/span&gt;Kokoszka, P. and Reimherr, M. (2017). &lt;em&gt;Introduction to Functional Data Analysis&lt;/em&gt;. CRC.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{1}\)&lt;/span&gt;Ramsay, J.O. and Silverman, B.W. (2005). &lt;em&gt;Functional Data Analysis&lt;/em&gt;. Springer.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{4}\)&lt;/span&gt;Ramsay, J.0., Hooker, G. and Graves, S. (2009) &lt;em&gt;Functional Data Analysis with R and MATLAB&lt;/em&gt; Springer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;online-resources&#34; class=&#34;section level4&#34;&gt;
&lt;h4&gt;Online Resources&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{3}\)&lt;/span&gt;Cao, J. (2019). &lt;a href=&#34;https://www.youtube.com/watch?v=SUp_Nq8NwfE&#34;&gt;&lt;em&gt;Functional Data Analysis Course&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Staicu, A. and Park, Y. (2016) &lt;a href=&#34;https://www4.stat.ncsu.edu/~staicu/FDAtutorial/&#34;&gt;&lt;em&gt;Short Course on Applied Functional Data Analysis&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&#34;recommended-papers&#34; class=&#34;section level4&#34;&gt;
&lt;h4&gt;Recommended Papers&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{6}\)&lt;/span&gt;Sørensen, H. Goldsmith, J. and Sangalli, L. (2013). &lt;a href=&#34;https://onlinelibrary.wiley.com/doi/abs/10.1002/sim.5989&#34;&gt;&lt;em&gt;An introduction with medical applications fo functional data analysis&lt;/em&gt;&lt;/a&gt; Wiley&lt;/li&gt;
&lt;li&gt;Wang, J., Chiou, J. and Müller, H. (2015). &lt;a href=&#34;https://arxiv.org/pdf/1507.05135.pdf&#34;&gt;&lt;em&gt;Review of Functional Data Analysis&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;math inline&#34;&gt;\(^{5}\)&lt;/span&gt; Yao, F., Müller, H, Wang, J. (2012). &lt;a href=&#34;https://anson.ucdavis.edu/~mueller/jasa03-190final.pdf&#34;&gt;&lt;em&gt;Functional Data Analysis for Sparse Longitudinal Data&lt;/em&gt;&lt;/a&gt; JASA J100, I 470&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

        &lt;script&gt;window.location.href=&#39;https://rviews.rstudio.com/2021/05/04/functional-data-analysis-in-r/&#39;;&lt;/script&gt;
      </description>
    </item>
    
  </channel>
</rss>
