These functions perform a (functional) principal component analysis (FPCA) of the input data and return an tfb_fpc tf-object that uses the empirical eigenfunctions as basis functions for representing the data. By default, a simple, not smoothed, truncated weighted SVD of the functions is used to compute those ("method = fpc_wsvd"). Note that this is suitable only for regular data all observed on the same (not necessarily equidistant) grid. See Details / Example for possible alternatives and extensions.

tfb_fpc(data, ...)

# S3 method for data.frame
tfb_fpc(
  data,
  id = 1,
  arg = 2,
  value = 3,
  domain = NULL,
  method = fpc_wsvd,
  resolution = NULL,
  ...
)

# S3 method for matrix
tfb_fpc(
  data,
  arg = NULL,
  domain = NULL,
  method = fpc_wsvd,
  resolution = NULL,
  ...
)

# S3 method for numeric
tfb_fpc(
  data,
  arg = NULL,
  domain = NULL,
  method = fpc_wsvd,
  resolution = NULL,
  ...
)

# S3 method for tf
tfb_fpc(data, arg = NULL, method = fpc_wsvd, ...)

# S3 method for default
tfb_fpc(
  data,
  arg = NULL,
  domain = NULL,
  method = fpc_wsvd,
  resolution = NULL,
  ...
)

Arguments

data

a matrix, data.frame or list of suitable shape, or another tf-object containing functional data.

...

arguments to the method which computes the (regularized/smoothed) FPCA. Unless set by the user tidyfun uses proportion of variance explained pve = .995 to determine the truncation levels.

id

The name/number of the column defining which data belong to which function.

arg

optional vector of argument values

value

The name/number of the column containing the function evaluations.

domain

range of the arg.

method

the function to use that computes eigenfunctions and scores. Defaults to fpc_wsvd(), which gives unsmoothed eigenfunctions.

resolution

resolution of the evaluation grid. See details for tfd().

Value

an object of class tfb_fpc, inheriting from tfb. The basis used by tfb_fpc is a tfd-vector containing the estimated mean and eigenfunctions.

Details

Any "factorization" method that accepts a data.frame with columns id, arg, value containing the functional data and returns a list structured like the return object of fpc_wsvd() can be used for the `method`` argument, see example below.

Methods (by class)

  • default: convert tfb: default method, returning prototype when data is NULL

See also

tfb(), fpc_wsvd() for FPCA options.

Examples

# Apply FPCA for sparse data using refund::fpca.sc: set.seed(99290) # create sparse data: data <- as.data.frame( tf_sparsify( tf_rgp(15) )) # wrap refund::fpca_sc for use as FPCA method in tfb_fpc: fpca_sc_wrapper <- function(data, arg, pve = .995, ...) { data_mat <- tidyfun:::df_2_mat(data) fpca <- refund::fpca.sc(Y = data_mat, argvals = attr(data_mat, "arg"), pve = pve, ...) fpca[c("mu", "efunctions", "scores", "npc")] } tfb_fpc(data, method = fpca_sc_wrapper)
#> tfb[15] on (0,1) in basis representation: #> using 5 FPCs #> 1: (0.00, -1.2);(0.02, -1.2);(0.04, -1.2); ... #> 2: (0.00, 0.67);(0.02, 0.59);(0.04, 0.52); ... #> 3: (0.00, 0.054);(0.02, 0.176);(0.04, 0.295); ... #> 4: (0.00, -1.7);(0.02, -1.4);(0.04, -1.2); ... #> 5: (0.00, 0.005);(0.02,-0.080);(0.04,-0.164); ... #> 6: (0.00, -0.54);(0.02, -0.37);(0.04, -0.21); ... #> 7: (0.00, -0.15);(0.02, -0.13);(0.04, -0.12); ... #> 8: (0.00, -1.5);(0.02, -1.4);(0.04, -1.2); ... #> 9: (0.00, 2.0);(0.02, 1.9);(0.04, 1.8); ... #> 10: (0.00, -0.18);(0.02, -0.19);(0.04, -0.19); ... #> [....] (5 not shown)