Function-on-scalar regression model, denote \(n\) as total number of observations, \(p\) the number of coefficients, \(K\) as the number of B-splines, \(T\) as total time points.

spfda(
  Y,
  X,
  lambda,
  time = seq(0, 1, length.out = ncol(Y)),
  nsp = "auto",
  ord = 4,
  alpha = 0.5,
  W = NULL,
  init = NULL,
  max_iter = 50,
  inner_iter = 50,
  CI = FALSE,
  ...
)

Arguments

Y

Numeric \(n \times T\) matrix, response function.

X

Numeric \(n \times p\) matrix, design matrix

lambda

Regularization parameter \(\gamma\)

time

Time domain, numerical length of \(T\)

nsp

Integer or 'auto', number of B-splines \(K\); default is 'auto'

ord

B-spline order, default is 4; must be \(\geq 3\)

alpha

Bridge parameter \(\alpha\), default is 0.5

W

A \(T \times T\) weight matrix or NULL (identity matrix); default is NULL

init

Initial \(\gamma\); default is NULL

max_iter

Number of outer iterations

inner_iter

Number of \(ADMM\) iterations (inner steps)

CI

Logical, whether to calculate theoretical confidence intervals

...

Ignored

Value

A spfda.model object (environment) with following elements:

B

B-spline basis functions used

error

Root Mean Square Error ('RMSE')

CI

Whether confidence intervals are calculated

gamma

B-spline coefficient \(\gamma_{p \times K}\)

generate_splines

Function to generate B-splines given time points

K

Number of B-spline basis functions

knots

B-spline knots used to fit the model

predict

Function to predict responses \(\beta(t)\) given new X and/or time points

raw

A list of raw variables

Details

This function implements "Functional Group Bridge for Simultaneous Regression and Support Estimation" (https://arxiv.org/abs/2006.10163). The model estimates functional coefficients \(\beta(t)\) under model \[y(t) = X\beta(t) + \epsilon(t)\] with B-spline basis expansion \[\beta(t) = \gamma B(t) + R(t), \] where \( R(t) \) is B-spline approximation error. The objective function \[ \left\| (Y-X\gamma B)W \right\|_{2}^{2} + \sum_{j,m} \left\| \gamma_{j}^{T}\mathbf{1}(B^{t} > 0) \right\|_{1}^{\alpha}. \] The input response variable is a matrix. If \(y_{i}(t)\) are observed at different time points, please interpolate (e.g. kernel) before feeding in.

Examples


dat <- spfda_simulate()
x <- dat$X
y <- dat$Y

fit <- spfda(y, x, lambda = 5, CI = TRUE)

BIC(fit)
#> [1] 102.6161

plot(fit, col = c("orange", "dodgerblue3", "darkgreen"),
     main = "Fitted with 95% CI", aty = c(0, 0.5, 1), atx = c(0,0.2,0.8,1))
matpoints(fit$time, t(dat$env$beta), type = 'l', col = 'black', lty = 2)
legend('topleft', c("Fitted", "Underlying"), lty = c(1,2))


print(fit)
#> Model: function-on-scalar with group-bridge penalty
#> Log-lik: -50042.01 (df=269)
#> E-BIC:   102.6161
#> RMSE :   1.069733
#> Parameters:
#>  K:      50
#>  alpha:  0.5
#>  lambda: 5
coefficients(fit)
#>               [,1]         [,2]         [,3]         [,4]         [,5]
#> [1,] -7.012115e-07 1.692958e-06 3.035323e-06 3.522342e-06 3.216476e-06
#> [2,]  3.899492e-07 1.953288e-02 5.440272e-02 7.455603e-02 9.087678e-02
#> [3,]  4.824930e-06 3.062445e-06 1.234592e-06 2.454777e-07 5.725427e-09
#>              [,6]         [,7]          [,8]          [,9]         [,10]
#> [1,] 2.137624e-06 5.671988e-07 -1.012244e-06 -2.128009e-06 -2.328751e-06
#> [2,] 1.302951e-01 1.853794e-01  2.228928e-01  2.366571e-01  2.564559e-01
#> [3,] 0.000000e+00 0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
#>              [,11]         [,12]         [,13]         [,14]        [,15]
#> [1,] -1.547007e-06 -5.688930e-07 -9.232223e-08 -4.274177e-10 0.000000e+00
#> [2,]  2.988815e-01  3.457207e-01  3.800646e-01  4.090581e-01 4.438675e-01
#> [3,]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00 1.033472e-08
#>             [,16]        [,17]        [,18]        [,19]       [,20]      [,21]
#> [1,] 0.000000e+00 0.000000e+00 0.000000e+00 0.0000000000 0.000000000 0.00000000
#> [2,] 4.809348e-01 5.106553e-01 5.316664e-01 0.5489712600 0.567639934 0.59259491
#> [3,] 1.177189e-07 4.256611e-07 7.768799e-07 0.0001224084 0.005213564 0.02625419
#>           [,22]     [,23]        [,24]        [,25]        [,26]        [,27]
#> [1,] 0.00000000 0.0000000 9.403889e-08 7.523111e-07 2.347954e-06 3.841781e-06
#> [2,] 0.62422273 0.6528084 6.712570e-01 6.884208e-01 7.148511e-01 7.441919e-01
#> [3,] 0.07275711 0.1500462 2.551439e-01 3.541341e-01 4.125178e-01 4.486505e-01
#>             [,28]        [,29]        [,30]         [,31]         [,32]
#> [1,] 3.678295e-06 2.045085e-06 4.497385e-07 -5.036751e-07 -1.427826e-06
#> [2,] 7.634550e-01 7.737690e-01 7.869391e-01  8.065791e-01  8.253142e-01
#> [3,] 5.023854e-01 5.808870e-01 6.661413e-01  7.422388e-01  7.968911e-01
#>              [,33]         [,34]         [,35]         [,36]         [,37]
#> [1,] -2.618263e-06 -3.481290e-06 -3.484719e-06 -2.823682e-06 -1.888758e-06
#> [2,]  8.386304e-01  8.500369e-01  8.633195e-01  8.790275e-01  8.968078e-01
#> [3,]  8.271295e-01  8.502456e-01  8.823304e-01  9.237079e-01  9.691749e-01
#>              [,38]         [,39]         [,40]         [,41]         [,42]
#> [1,] -1.171155e-06 -1.163954e-06 -1.713652e-06 -2.174629e-06 -2.113618e-06
#> [2,]  9.156166e-01  9.342083e-01  9.529468e-01  9.732888e-01  9.910018e-01
#> [3,]  1.001809e+00  1.001474e+00  9.785429e-01  9.662679e-01  9.743196e-01
#>              [,43]         [,44]        [,45]        [,46]        [,47]
#> [1,] -1.390520e-06 -2.877211e-08 1.626933e-06 3.121352e-06 3.730909e-06
#> [2,]  9.944654e-01  9.808218e-01 9.678718e-01 9.725311e-01 9.969943e-01
#> [3,]  9.810109e-01  9.757735e-01 9.775317e-01 9.997103e-01 1.017775e+00
#>             [,48]        [,49]         [,50]         [,51]         [,52]
#> [1,] 2.817584e-06 8.714609e-07 -1.138201e-06 -2.635401e-06 -3.358082e-06
#> [2,] 1.036748e+00 1.064897e+00  1.047697e+00  9.989148e-01  9.680815e-01
#> [3,] 1.004357e+00 9.812730e-01  9.891524e-01  1.020332e+00  1.030809e+00
#>              [,53]         [,54]         [,55]         [,56]         [,57]
#> [1,] -3.416356e-06 -3.392399e-06 -3.640053e-06 -3.933152e-06 -3.977445e-06
#> [2,]  9.726943e-01  9.874546e-01  9.930983e-01  9.902115e-01  9.829315e-01
#> [3,]  1.011226e+00  9.983699e-01  1.011343e+00  1.022885e+00  1.010329e+00
#>              [,58]         [,59]         [,60]        [,61]        [,62]
#> [1,] -3.520256e-06 -2.380238e-06 -8.264034e-07 6.696018e-07 1.623502e-06
#> [2,]  9.788561e-01  9.840580e-01  9.869441e-01 9.696805e-01 9.394833e-01
#> [3,]  9.944715e-01  1.001267e+00  1.014489e+00 1.001491e+00 9.667175e-01
#>             [,63]        [,64]         [,65]         [,66]         [,67]
#> [1,] 1.554354e-06 4.599397e-07 -1.040031e-06 -2.339615e-06 -2.956360e-06
#> [2,] 9.223332e-01 9.233987e-01  9.202185e-01  8.993214e-01  8.714216e-01
#> [3,] 9.426183e-01 9.383351e-01  9.318091e-01  9.060340e-01  8.599339e-01
#>              [,68]         [,69]         [,70]        [,71]        [,72]
#> [1,] -2.589401e-06 -1.597398e-06 -4.956303e-07 2.616530e-07 2.960383e-07
#> [2,]  8.480295e-01  8.307513e-01  8.181831e-01 8.049764e-01 7.846144e-01
#> [3,]  7.984197e-01  7.417279e-01  7.088987e-01 6.818144e-01 6.278567e-01
#>              [,73]        [,74]        [,75]        [,76]        [,77]
#> [1,] -4.538372e-08 1.223854e-07 9.022284e-07 1.364667e-06 9.976339e-07
#> [2,]  7.595492e-01 7.388705e-01 7.212256e-01 6.915201e-01 6.453107e-01
#> [3,]  5.465497e-01 4.619456e-01 3.880247e-01 3.248358e-01 2.674511e-01
#>             [,78]        [,79]        [,80]       [,81]        [,82]
#> [1,] 3.746302e-07 6.079649e-08 2.814652e-10 0.000000000 0.0000000000
#> [2,] 6.039739e-01 5.852963e-01 5.787304e-01 0.567730432 0.5437698866
#> [3,] 2.019148e-01 1.208014e-01 4.769353e-02 0.009482859 0.0002251713
#>             [,83]        [,84]        [,85]        [,86]        [,87]
#> [1,] 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
#> [2,] 5.028267e-01 4.545120e-01 4.186110e-01 4.032374e-01 4.009719e-01
#> [3,] 5.381960e-06 6.450455e-06 8.047045e-06 1.003097e-05 1.103181e-05
#>             [,88]        [,89]        [,90]        [,91]        [,92]
#> [1,] 0.000000e+00 0.000000e+00 2.049878e-07 1.639902e-06 5.114856e-06
#> [2,] 3.991240e-01 3.755551e-01 3.189491e-01 2.663931e-01 2.578203e-01
#> [3,] 1.023347e-05 8.240444e-06 5.869965e-06 4.021469e-06 3.451704e-06
#>             [,93]        [,94]        [,95]        [,96]        [,97]
#> [1,] 8.337264e-06 7.889571e-06 4.322783e-06 1.195489e-06 1.049538e-07
#> [2,] 2.647675e-01 2.323313e-01 1.685371e-01 1.287731e-01 1.233559e-01
#> [3,] 3.710993e-06 3.848403e-06 3.500939e-06 2.763473e-06 1.871041e-06
#>             [,98]         [,99]        [,100]
#> [1,] 0.000000e+00  0.000000e+00  0.000000e+00
#> [2,] 1.025808e-01  4.481035e-02  0.000000e+00
#> [3,] 1.219721e-06 -2.290948e-08 -5.455109e-06