【问题标题】:Error with bspline smoothing for functional data in R with high number of basis functionsR中具有大量基函数的函数数据的bspline平滑错误
【发布时间】:2018-01-22 10:13:48
【问题描述】:

我在 R 中有这个错误,我无法解决它:

chol.default(temp) 中的错误: 445 阶的主要次要不是正定的 另外:警告信息: 在 smooth.basis1(argvals, y, fdParobj, wtvec = wtvec, fdnames = fdnames, : 基函数值矩阵的秩为 799

我想平滑数据。我的数据集有 44 467 行,只有一个变量需要平滑。平滑 200,300,400,500,600,700 个函数没有问题。但是我不能用800,我不明白为什么。这是一个没有惩罚的 b 样条平滑。 (我也没有问题用 200,300,400,500,600,700 个函数来平滑惩罚。)

 n=44467
 argvals=data_totale$temps_ref_st

library(fda)
TableGCV<-c()

i is the number of basis
j lambda for penalization (here =0)

 for (i in c(800)) {
 for (j in c(0)) { 
basisobj = create.bspline.basis(c(0, max(argvals)),i)

fdParobj = fdPar(fdobj=basisobj, Lfdobj=2, j)

smoothlist = smooth.basis(argvals, mdata, fdParobj)

xfd_acc = smoothlist$fd 
xfd_acc_coef = smoothlist$fd$coefs

#GCV output
gcv = smoothlist$gcv 
TableGCV <- rbind(TableGCV,c(i,j,gcv))

 }
} 

感谢您的帮助

【问题讨论】:

  • num [1:44467, 1] 2.12 2.33 2.5 2.63 2.71 ...
  • 是的,长度(argvals)=length(mdata)=44467

标签: r functional-programming statistics smoothing


【解决方案1】:

此代码适用于我的 R:

library(fda)
n <- 44467
set.seed(12345)
argvals <- 1:n
mdata <- cumsum(rnorm(n))

TableGCV<-c()
for (i in c(800)) {
  for (j in c(0)) { 
    basisobj <- create.bspline.basis(c(0, max(argvals)),i)
    fdParobj <- fdPar(fdobj=basisobj, Lfdobj=2, j)
    smoothlist <- smooth.basis(argvals, mdata, fdParobj)
    xfd_acc <- smoothlist$fd 
    xfd_acc_coef <- smoothlist$fd$coefs
    gcv <- smoothlist$gcv 
    TableGCV <- rbind(TableGCV,c(i,j,gcv))
 }
} 
plot(smoothlist)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-07
    • 2018-07-08
    • 1970-01-01
    • 2018-07-04
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多