cfda-package {cfda}R Documentation

Categorical Functional Data Analysis


cfda provides functions for the analysis of categorical functional data.

The main contribution is the computation of an optimal encoding (real functional variable) of each state of the categorical functional data. This can be done using the compute_optimal_encoding function that takes in arguments the data in a specific format and a basis of functions created using the fda package (cf. create.basis). The output can be analysed with summary.fmca, plot.fmca, get_encoding, plotEigenvalues and plotComponent.

Moreover, cfda contains functions to visualize and compute some statistics about categorical functional data. A summary of the dataset is available with summary_cfd. plotData shows a graphical representation of the dataset. Basic statistics can be computed: the number of jumps (compute_number_jumps), the duration (compute_duration), the time spent in each state (compute_time_spent), the probability to be in each state at any given time (estimate_pt), the transition table (statetable).

The parameters of a Markov process can be estimated using estimate_Markov function.

In order to test the different functions, a real dataset is provided (biofam2) as well as two functions for generating data: (generate_Markov and generate_2State).


See the vignette for a detailed example and mathematical background: RShowDoc("cfda", package = "cfda")


See Also



# Simulate the Jukes-Cantor model of nucleotide replacement  
K <- 4
Tmax <- 5
PJK <- matrix(1/3, nrow = K, ncol = K) - diag(rep(1/3, K))
lambda_PJK <- c(1, 1, 1, 1)
d_JK <- generate_Markov(n = 10, K = K, P = PJK, lambda = lambda_PJK, Tmax = Tmax)
d_JK2 <- cut_data(d_JK, Tmax)

# create basis object
m <- 5
b <- create.bspline.basis(c(0, Tmax), nbasis = m, norder = 4)

# compute encoding
encoding <- compute_optimal_encoding(d_JK2, b, computeCI = FALSE, nCores = 1)

# plot eigenvalues
plotEigenvalues(encoding, cumulative = TRUE, normalize = TRUE)

# plot the two first components
plotComponent(encoding, comp = c(1, 2))

# plot the encoding using the first harmonic

# extract the encoding using the first harmonic
encod <- get_encoding(encoding)

[Package cfda version 0.9.9 Index]