Search code examples
rfunctional-programmingstatisticssmoothing

Error with bspline smoothing for functional data in R with high number of basis functions


I have this error in R, I can't solve it :

Error in chol.default(temp) : the leading minor of order 445 is not positive definite In addition: Warning message: In smooth.basis1(argvals, y, fdParobj, wtvec = wtvec, fdnames = fdnames, : Matrix of basis function values has rank 799 < dim(fdobj$basis)[2] = 800 ignoring null space

I want to smooth data. My data set have 44 467 rows, and just one variable to smooth. I don't have problem to smooth with 200,300,400,500,600,700 functions. But I can't with 800 and I don't understand why. It's a b-spline smoothing with no penalty here. ( also I don't have problem to smooth with penalty with 200,300,400,500,600,700 functions.)

 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))

 }
} 

Thanks for your help


Solution

  • This code works on my 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)
    

    enter image description here