## flm_stat
# Generate data
n <- 200
q <- 2
p <- 3
E <- matrix(rnorm(n * q), nrow = n, ncol = q)
X_fdata <- r_ou(n = n, t = seq(0, 1, l = 101))
# Compute FPC
X_fpc <- fpc(X_fdata)
# Adot
Adot_vec <- Adot(X = X_fpc[["scores"]])
# Check equality
constant <- n^(-2) * 2 * pi^((p / 2) - 1) / gamma(p / 2)
constant * .Fortran("pcvm_statistic", n = as.integer(n),
Adot_vec = Adot_vec, residuals = E[, 2],
statistic = 0)$statistic
flm_stat(E = E[, 2, drop = FALSE], p = p, Adot_vec = Adot_vec,
constant = FALSE)
## Adot
# Generate data
n <- 200
X_fdata <- r_ou(n = n, t = seq(0, 1, l = 101))
# Compute FPC
X_fpc <- fpc(X_fdata)
# Using inprod_fdata and Adot
Adot_vec <- Adot(X = X_fpc[["scores"]])
# Check with fda.usc::Adot with adequate inprod
head(drop(Adot_vec))
head(fda.usc::Adot(X_fdata))
# Obtention of the entire Adot matrix
Ad <- diag(rep(Adot_vec[1], n))
Ad[upper.tri(Ad, diag = FALSE)] <- Adot_vec[-1]
head(Ad <- t(Ad) + Ad - diag(diag(Ad)))
# Positive definite
eigen(Ad)$values
# # Warning if X contains repeated observations
# Adot(X = rbind(1:3, 1:3, 3:5))
# \donttest{
# Comparison with .Fortran("adot", PACKAGE = "fda.usc")
n <- as.integer(n)
a <- as.double(rep(0, (n * (n - 1) / 2 + 1)))
inprod <- X_fpc[["scores"]] %*% t(X_fpc[["scores"]])
inprod <- inprod[upper.tri(inprod, diag = TRUE)]
X <- X_fpc[["scores"]]
microbenchmark::microbenchmark(
.Fortran("adot", n = n, inprod = inprod, Adot_vec = a,
PACKAGE = "fda.usc"),
Adot(X = X),
times = 50, control = list(warmup = 10))
# }
Run the code above in your browser using DataLab