Title: | Estimating Penalized Functional Linear Regression |
---|---|
Description: | Implementation of commonly used penalized functional linear regression models, including the Smooth and Locally Sparse (SLoS) method by Lin et al. (2016) <doi:10.1080/10618600.2016.1195273>, Nested Group bridge Regression (NGR) method by Guan et al. (2020) <doi:10.1080/10618600.2020.1713797>, Functional Linear Regression That's interpretable (FLIRTI) by James et al. (2009) <doi:10.1214/08-AOS641>, and the Penalized B-spline regression method. |
Authors: | Tianyu Guan [aut], Haolun Shi [aut, cre, cph], Rob Cameron [aut], Zhenhua Lin [aut] |
Maintainer: | Haolun Shi <[email protected]> |
License: | GPL-2 |
Version: | 1.1.0 |
Built: | 2025-02-19 03:28:34 UTC |
Source: | https://github.com/cran/PFLR |
Calculates functional regression that's interpretable using the FLiRTI method.
FLiRTI( Y, X, d, cons, domain, extra = list(Mf = 6:30, lambda = seq(5e-04, 100, length.out = 50)) )
FLiRTI( Y, X, d, cons, domain, extra = list(Mf = 6:30, lambda = seq(5e-04, 100, length.out = 50)) )
Y |
Vector of length n, centred response. |
X |
Matrix of n x p, covariate matrix, should be dense. |
d |
Integer, degree of the B-spline basis functions. |
cons |
Divide subinterval into how many small ones. |
domain |
The range over which the function X(t) is evaluated and the coefficient function |
extra |
List containing parameters which have default values:
|
beta: Estimated (t) at discrete points.
extra: List containing other values which may be of use:
X: Matrix of n x p used for model.
Y: Vector of length n used for model.
domain: The range over which the function X(t) was evaluated and the coefficient function (t) was expanded by the B-spline basis functions.
delta: Estimated cutoff point.
OptM: Optimal number of B-spline knots selected by BIC.
Optlambda: Optimal shrinkage parameter selected by BIC.
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra)
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra)
Calculates a functional regression model using a nested group bridge approach.
ngr( Y, X, M, d, domain, extra = list(alphaPS = 10^(-10:0), kappa = 10^(-(9:7)), tau = exp(seq(-50, -15, len = 20)), gamma = 0.5, niter = 100) )
ngr( Y, X, M, d, domain, extra = list(alphaPS = 10^(-10:0), kappa = 10^(-(9:7)), tau = exp(seq(-50, -15, len = 20)), gamma = 0.5, niter = 100) )
Y |
Vector of length n. |
X |
Matrix of n x p, covariate matrix, should be dense. |
M |
Integer, t1,..., tM are M equally spaced knots. |
d |
Integer, the degree of B-Splines. |
domain |
The range over which the function X(t) is evaluated and the coefficient function |
extra |
List containing other parameters which have defaults:
|
beta: Estimated (t) at discrete points.
extra: List containing other values which may be of use:
b: Estimated b-hat.
delta: Estimated cutoff point.
Ymean: Estimated y-hat.
Xmean: Estimated x-hat.
Optkappa: Optimal roughness penalty selected.
Opttau: Optimal group bridge penalty selected.
M: Integer representing the number of knots used in the model calculation.
d: Integer, degree of B-Splines used.
domain: The range over which the function X(t) was evaluated and the coefficient function (t) was expanded by the B-spline basis functions.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau))
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau))
Generating random curves from B-Splines n,nknots,norder,p,domain=c(0,1),snr,betaind
ngr.data.generator.bsplines( n, nknots, norder, p, domain = c(0, 1), snr, betaind )
ngr.data.generator.bsplines( n, nknots, norder, p, domain = c(0, 1), snr, betaind )
n |
Number of curves |
nknots |
Number of knots |
norder |
Degree |
p |
Number of time points |
domain |
Domain of time |
snr |
Signal to noise ratio |
betaind |
Numeric index for function |
X: The generated X matrix of curve sampled at each timepoint
Y: The generated dependent variable
Calculates a functional regression model using the penalized B-splines method.
PenS(Y, X, alpha, M, d, domain)
PenS(Y, X, alpha, M, d, domain)
Y |
Vector of length n. |
X |
Matrix of n x p, covariate matrix, should be dense. |
alpha |
Vector. |
M |
Integer, t1,..., tM are M equally spaced knots. |
d |
Integer, the degree of B-Splines. |
domain |
The range over which the function X(t) is evaluated and the coefficient function |
beta: Estimated (t) at discrete points.
extra: List containing other values which may be of use:
b: Estimated B-spline coefficients.
Ymean: Mean of the Y values.
Xmean: Mean of all X values.
Optalpha: Optimal alpha value chosen.
M: Integer representing the number of knots used in the model calculation.
d: Integer, degree of B-Splines used.
domain: The range over which the function X(t) was evaluated and the coefficient function (t) was expanded by the B-spline basis functions.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain)
Plots coefficient function of objects of class "flirti".
## S3 method for class 'flirti' plot(x, ...)
## S3 method for class 'flirti' plot(x, ...)
x |
An object of class "flirti". |
... |
Other parameters to be passed through to plotting functions. |
A line graph of the beta values versus time.
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) plot(fltyfit)
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) plot(fltyfit)
Plots coefficient function for objects of the class "ngr".
## S3 method for class 'ngr' plot(x, ...)
## S3 method for class 'ngr' plot(x, ...)
x |
An object of class "ngr". |
... |
Other parameters to be passed through to plotting functions. |
A line graph of the beta values over time.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) plot(ngrfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) plot(ngrfit)
Plots coefficient function of objects of class "ps".
## S3 method for class 'ps' plot(x, ...)
## S3 method for class 'ps' plot(x, ...)
x |
An object of class "ps". |
... |
Other parameters to be passed through to plotting functions. |
A line graph of the beta values versus time.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) plot(psfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) plot(psfit)
Plots coefficient function for objects of class "slos".
## S3 method for class 'slos' plot(x, ...)
## S3 method for class 'slos' plot(x, ...)
x |
An object of class "slos". |
... |
Other parameters to be passed through to plotting functions. |
A line graph of the beta values versus time.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) plot(slosfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) plot(slosfit)
Predicted values based on objects of the class "flirti".
## S3 method for class 'flirti' predict(object, Xnew, ...)
## S3 method for class 'flirti' predict(object, Xnew, ...)
object |
An object of class "flirti". |
Xnew |
New covariate matrix for prediction, should be dense, centred. |
... |
Not applicable |
Predicted values.
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) predict(fltyfit,(X[1:n,,1]))
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) predict(fltyfit,(X[1:n,,1]))
Predicted values based on "ngr" class objects.
## S3 method for class 'ngr' predict(object, Xnew, ...)
## S3 method for class 'ngr' predict(object, Xnew, ...)
object |
An object of class "ngr". |
Xnew |
New covariate matrix for prediction, should be dense, centred. |
... |
Not applicable |
Estimated Y hat value.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) predict(ngrfit,X[1:n,,1])
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) predict(ngrfit,X[1:n,,1])
Predicted values based on objects of class "ps".
## S3 method for class 'ps' predict(object, Xnew, ...)
## S3 method for class 'ps' predict(object, Xnew, ...)
object |
An object of class "ps". |
Xnew |
New covariate matrix for prediction, should be dense, centred. |
... |
Not applicable |
Predicted values.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) predict(psfit,X[1:n,,1])
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) predict(psfit,X[1:n,,1])
Predicted values based on objects of class "slos".
## S3 method for class 'slos' predict(object, Xnew, ...)
## S3 method for class 'slos' predict(object, Xnew, ...)
object |
An object of class "slos". |
Xnew |
New covariate matrix for prediction, should be dense, centred. |
... |
Not applicable |
Predicted values.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) predict(slosfit,(X[1:n,,1]))
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) predict(slosfit,(X[1:n,,1]))
Calculates functional regression using the Smooth and Locally Sparse (SLoS) method.
SLoS( Y, X, M, d, domain, extra = list(Maxiter = 100, lambda = exp(seq(-20, -12, length.out = 10)), gamma = 10^(-9:0), absTol = 10^(-10), Cutoff = 10^(-6)) )
SLoS( Y, X, M, d, domain, extra = list(Maxiter = 100, lambda = exp(seq(-20, -12, length.out = 10)), gamma = 10^(-9:0), absTol = 10^(-10), Cutoff = 10^(-6)) )
Y |
Vector, length n, centred response. |
X |
Matrix of n x p, covariate matrix, should be dense, centred. |
M |
Integer, t1,..., tM are M equally spaced knots. |
d |
Integer, the degree of B-Splines. |
domain |
The range over which the function X(t) is evaluated and the coefficient function |
extra |
List of parameters which have default values:
|
beta: Estimated (t) at discrete points.
extra: List containing other values which may be of use:
X: Matrix of n x p used for model.
Y: Vector of length n used for model.
M: Integer representing the number of knots used in the model calculation.
d: Integer, degree of B-Splines used.
domain: The range over which the function X(t) was evaluated and the coefficient function (t) was expanded by the B-spline basis functions.
b: Estimated b values.
delta: Estimated cutoff point.
Optgamma: Optimal smoothing parameter selected by BIC.
Optlambda: Optimal shrinkage parameter selected by BIC.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = fda::create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = fda::create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra)
Summarizes the values of an object of class "flirti".
## S3 method for class 'flirti' summary(object, ...)
## S3 method for class 'flirti' summary(object, ...)
object |
An object of class "flirti". |
... |
Not applicable |
Prints a 5 number summary of the beta values, delta, OptM, and Optlambda
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) summary(fltyfit)
library(fda) betaind = 1 snr = 2 nsim = 200 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) lambda = seq(0.0005,0.01,length.out = 10) Mf = 6:13 extra=list(Mf=Mf,lambda=lambda) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } fltyfit = FLiRTI(Y=Y[1:n,1],(X[1:n,,1]),d=3,cons=4,domain=domain,extra=extra) summary(fltyfit)
Summarizes objects of class "ngr".
## S3 method for class 'ngr' summary(object, ...)
## S3 method for class 'ngr' summary(object, ...)
object |
An object of class "ngr". |
... |
Not applicable |
Prints the 5 number summaries of beta and b values. Prints delta, Optkappa, and Opttau values.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) summary(ngrfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 tobs = seq(domain[1],domain[2],length.out = p) knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) basismat = eval.basis(tobs, basis) h = (domain[2]-domain[1])/M cef = c(1, rep(c(4,2), (M-2)/2), 4, 1) V = eval.penalty(basis,int2Lfd(2)) alphaPS = 10^(-(10:3)) kappa = 10^(-(8:7)) tau = exp(seq(-35,-28,len=20)) gamma = 0.5 for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=1) Y[,itersim] = dat$Y X[,,itersim] = dat$X } ngrfit = ngr(Y=Y[1:n,1],X=(X[1:n,,1]),M,d,domain,extra= list(alphaPS=alphaPS, kappa=kappa, tau=tau)) summary(ngrfit)
Summarizes the values of an object of class "ps".
## S3 method for class 'ps' summary(object, ...)
## S3 method for class 'ps' summary(object, ...)
object |
An object of class "ps". |
... |
Not applicable |
Prints a 5 number summary of the beta values and coefficient values, and the optimal alpha.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) summary(psfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 alpha = 10^(-(10:3)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } psfit = PenS(Y=Y[1:n,1],X=(X[1:n,,1]), alpha=alpha, M=M, d=d, domain=domain) summary(psfit)
Summarizes values of an object of class "slos".
## S3 method for class 'slos' summary(object, ...)
## S3 method for class 'slos' summary(object, ...)
object |
An object of class "slos". |
... |
Not applicable |
Prints five number summary of beta values, delta, Optgamma, and Optlambda.
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) summary(slosfit)
library(fda) betaind = 1 snr = 2 nsim = 1 n = 50 p = 21 Y = array(NA,c(n,nsim)) X = array(NA,c(n,p,nsim)) domain = c(0,1) M = 20 d = 3 norder = d+1 nknots = M+1 knots = seq(domain[1],domain[2],length.out = nknots) nbasis = nknots + norder - 2 basis = create.bspline.basis(knots,nbasis,norder) V = eval.penalty(basis,int2Lfd(2)) extra=list(lambda=exp(seq(-18,-12, length.out = 10)),gamma=10^(-8:-6)) for(itersim in 1:nsim) { dat = ngr.data.generator.bsplines(n=n,nknots=64,norder=4,p=p,domain=domain,snr=snr,betaind=betaind) Y[,itersim] = dat$Y X[,,itersim] = dat$X } slosfit = SLoS(Y=Y[1:n,1],(X[1:n,,1]),M=M,d=d,domain=domain,extra=extra) summary(slosfit)
The particulate matter emissions data, taken from the Coordinating Research Councils E55/E59 research project (Clark et al. 2007). In the project, trucks were placed on the chassis dynamometer bed to mimic inertia and particulate matter was measured by an emission analyzer on standard test cycles. The engine acceleration of diesel trucks was also recorded.
truck
truck
A data frame with 108 rows and 91 columns:
Emmission
Acceleration at each second
Clark, N., Gautam, M., Wayne, W., Lyons, D., Thompson, G., and Zielinska, B. (2007), “Heavy-Duty Vehicle Chassis Dynamometer Testing for Emissions Inventory, Air Quality Modeling, Source Apportionment and Air Toxics Emissions Inventory: E55/59 All Phases,” Coordinating Research Council, Alpharetta