简体   繁体   English

在 R 中组合或合并两个或多个 .fd 类功能数据

[英]combine or merge two or more .fd class functional data in R

I am a newcomer in functional data analysis (FDA).我是功能数据分析(FDA)的新手。

library(fda)

set.seed(151)

I1 <- matrix(rnorm(20*20,mean=0,sd=1),20,20)
I2 <- matrix(rnorm(15*20,mean=0.5,sd=1),15,25)

data1 <- t(I1)
data2 <- t(I2)
minutetime1 <- seq(from = 1, to = 25, length.out = 20)
minutetime2 <- seq(from = 1, to = 25, length.out = 25)

minutebasis <- create.bspline.basis(rangeval=c(0,25),nbasis=10)

fd1<- Data2fd(data1, minutetime1, basisobj=minutebasis)
is.fd(fd1)
# [1] TRUE
fd2<- Data2fd(data2, minutetime2, basisobj=minutebasis)
is.fd(fd2)
# [1] TRUE

I would like to merge or combine fd1 and fd2 ( like combining two vectors), and the result will also be the .fd class.我想合并或合并 fd1 和 fd2(就像合并两个向量),结果也将是 .fd 类。 I have used c(fd1,fd2) , merge(fd1,fd2) and modifyList(fd1,fd2) , etc.我使用过c(fd1,fd2)merge(fd1,fd2)modifyList(fd1,fd2)等。

Because your data are represented on the same basis, you should be able to create a combined fd object by combining the basis function coefficients from fd1 and fd2 .由于您的数据以相同的基础表示,因此您应该能够通过组合fd1fd2的基函数系数来创建组合 fd 对象。

The coefficients are stored in matrices.系数存储在矩阵中。 Rows correspond to basis functions and columns correspond to observations (see ?fd ), so we can bind columns to combine observations.行对应于基函数,列对应于观察(见?fd ),所以我们可以绑定列来组合观察。

merged_coefs <- cbind(fd1$coefs, fd2$coefs)
merged_fd <- fd(coef = merged_coefs, basisobj = minutebasis)
is.fd(merged_fd)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM