| Title: | Functional Regression Estimation |
|---|---|
| Description: | This package is complementary to the fda package. It includes function to choose smoothing parameters and to estimate models with multiple functional regressors. |
| Authors: | Pierre Chausse <[email protected]> |
| Maintainer: | Pierre Chausse <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.0-1 |
| Built: | 2026-09-25 18:58:16 UTC |
| Source: | https://codeberg.org/pchausse/funcreg |
These are the main functions to fit a functional data object to a dataset. The model can be linear or nonlinear. The smoothing parameter and the number of basis is assumed to be known.
coefEst(y, t, lam, k, L=2, create_basis=create.bspline.basis, ...) nlCoefEst(y, t, lam, k, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, typels=c("brent","grid"), addDat=FALSE, rangeval=NULL, ...) makeLinFda(obj, npoints=200) logFda(obj) ## S3 method for class 'myfda' as.fd(x, fdnames=NULL, npoints=200, ...) ## S3 method for class 'myfda' fitted(object, t=NULL, ...)coefEst(y, t, lam, k, L=2, create_basis=create.bspline.basis, ...) nlCoefEst(y, t, lam, k, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, typels=c("brent","grid"), addDat=FALSE, rangeval=NULL, ...) makeLinFda(obj, npoints=200) logFda(obj) ## S3 method for class 'myfda' as.fd(x, fdnames=NULL, npoints=200, ...) ## S3 method for class 'myfda' fitted(object, t=NULL, ...)
y |
A |
t |
A numeric vector of time units. In |
lam |
The regularization parameter that penalizes for the absence of smoothness. |
k |
The number of basis. |
L |
Either a nonnegative integer defining an order of a
derivative or a linear differential operator (see
|
create_basis |
The function used to create the basis object (see
|
maxit |
The maximum number of iteration for the Newton method |
tol |
The tolerance parameter for the stopping rule of the Newton method |
... |
Other argument that is passed to |
obj |
Object of class "myfda" |
npoints |
Number of points to fit the linear FDA to the non-linear one |
x |
Object of class "myfda" |
object |
Object of class "myfda" |
fdnames |
Names of elements of the "fd" object (see
|
typels |
The |
addDat |
If TRUE, fake observations are added before and after assuming stationarity. for the estimation, the time span is expanded accordingly. |
rangeval |
This can be set if the basis is defined on a range other
than |
In coefEst, the functional data is a linear combination of the
basis, while in nlCoefEst it is the exponential of the linear
combination of the basis. The latter is used when we want to force the
functional data curve to be positive,
makeLinFda will transform the nonlinear fit to a linear FDA by
fitting the nonlinear curve to a linear combination of the same
basis. The curve is almost identical and it is transformed this way
by funcreg
logFDA transforms the non-linear FDA into a linear FDA. It only
redefine the link equation and take the log of the observed data.
It returns an object of 'class' "myfda"
The object of class "myfda" is a list containing at least:
coefficients |
|
y |
The dataset matrix |
t |
The input vector |
basis |
The basis object |
link |
The function that links |
lambda |
The value of |
convergence |
Information on the convergence of the Newton method. |
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) res cbind(data=GDPv56[,1], fitted=fitted(res)[,1]) ## Nonlinear Estimation res <- nlCoefEst(y=GDPv56, t=t, lam=0.003, k=15) res resLin <- makeLinFda(res) resLin ## Take the logarithm of the non-linear functional data logres <- logFda(res) plot(res,1:2) ## Transform the myfda object into an fd object resfd <- as.fd(resLin) ## Nonlinear Estimation with zeros data(simData) t <- seq(0,1,length.out=5) res <- nlCoefEst(y=simData, t=t, lam=0.003, k=7) res res <- nlCoefEst(y=simData, t=t, lam=0.003, k=7, addDat=TRUE) resdata(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) res cbind(data=GDPv56[,1], fitted=fitted(res)[,1]) ## Nonlinear Estimation res <- nlCoefEst(y=GDPv56, t=t, lam=0.003, k=15) res resLin <- makeLinFda(res) resLin ## Take the logarithm of the non-linear functional data logres <- logFda(res) plot(res,1:2) ## Transform the myfda object into an fd object resfd <- as.fd(resLin) ## Nonlinear Estimation with zeros data(simData) t <- seq(0,1,length.out=5) res <- nlCoefEst(y=simData, t=t, lam=0.003, k=7) res res <- nlCoefEst(y=simData, t=t, lam=0.003, k=7, addDat=TRUE) res
It computes the cross-validation for a given lambda and k or find the optimal lambda for a given k (see below).
funcregCV(form, create_basis=create.bspline.basis, LD=2, lambda, k, CstInt=FALSE, regularized=TRUE, alpha=1e-5, data=NULL, obj=NULL, ...) getFuncregLam(form, create_basis=create.bspline.basis, LD=2, lam0, k, regularized=TRUE, CstInt=FALSE, data=NULL, loglam=FALSE, method="BFGS", alpha=1e-5, optimArg=list(), ...)funcregCV(form, create_basis=create.bspline.basis, LD=2, lambda, k, CstInt=FALSE, regularized=TRUE, alpha=1e-5, data=NULL, obj=NULL, ...) getFuncregLam(form, create_basis=create.bspline.basis, LD=2, lam0, k, regularized=TRUE, CstInt=FALSE, data=NULL, loglam=FALSE, method="BFGS", alpha=1e-5, optimArg=list(), ...)
obj |
An object of class "funcreg". If |
form |
A formula for the functional regression. Arguments are
objects of class "myfda" obtained either by |
create_basis |
The function used to create the basis object (see
|
LD |
Either a nonnegative integer defining an order of a
derivative or a linear differential operator (see
|
data |
An optional list of |
lambda |
A vector of regularization parameters that penalizes for the absence of
smoothness. The dimention is 2 times the number of regressors plus 1
if there is an intercept and if |
lam0 |
Initial value of lambda for the minimization of the cross-validation |
k |
A vector of integers representing the number of basis for each
functional parameter. The first is for the intercept (if there is an
intercept and that |
regularized |
If |
CstInt |
If |
loglam |
If |
method |
The algorithm used by |
optimArg |
A list of additional arguments to pass to
|
alpha |
The regularization parameter. The value is added to the diagonal of the regression matrix to make sure it is positive definite. |
... |
Additional arguments to be passed to |
'funregCV' returns the value of the leave-one-out cross-validation. The attributes 'convergence', returns convergence code for each estimation.
'getFuncregLam' returns the fitted object of class 'funcreg' using the
optimal lambda. The argument 'optimRes' gives the optim
output from the minimization of the cross-validation.
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## with the object res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) funcregCV(obj=res) ## without object funcregCV(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) ## With the default values getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001)) ## With upper and lower bound getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001), method="L-BFGS-B", optimArg=list(lower=c(0,0,0),upper=c(200,200,200))) ## With loglam res <- getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(-3,-3,-3), loglam=TRUE) res ## Get info about the optim() res$optimResdata(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## with the object res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) funcregCV(obj=res) ## without object funcregCV(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) ## With the default values getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001)) ## With upper and lower bound getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(.001,.001,.001), method="L-BFGS-B", optimArg=list(lower=c(0,0,0),upper=c(200,200,200))) ## With loglam res <- getFuncregLam(yfd~xfd, k=c(5,5), lam0=c(-3,-3,-3), loglam=TRUE) res ## Get info about the optim() res$optimRes
The functions compute the leave-one-out cross-validation of functional data. It applies also to already estimated models.
nlFdaCV(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, obj=NULL, typels=c("brent","grid"), addDat=FALSE, ...) fdaCV(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, obj=NULL, ...)nlFdaCV(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, obj=NULL, typels=c("brent","grid"), addDat=FALSE, ...) fdaCV(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, obj=NULL, ...)
y |
A |
t |
A numeric vector of time units. The number of elements is equal to the
number of rows of |
lamvec |
A vector of regularization parameters that penalizes for the absence of smoothness. |
kvec |
A vector of integers that indicates the number of basis. |
L |
Either a
nonnegative integer defining an order of a derivative or a linear
differential operator (see |
create_basis |
The function used to create the basis object (see
|
maxit |
The maximum number of iteration for the Newton method |
tol |
The tolerance parameter for the stopping rule of the Newton method |
obj |
Object of class "myfda" if we want the cross-validation of an already fitted model |
typels |
The |
addDat |
If TRUE, fake observations are added before and after assuming stationarity. for the estimation, the time span is expanded accordingly. |
... |
Other argument that is passed to |
It returns a matrix of cross-validations. The rows are for the lambda, and the columns for the number of basis.
fdaCV returns a matrix of cross-validations. The rows are for the lambda,
and the columns for the number of basis.
nlFdaCV returns a list with the following items:
cv |
The cross-validation matrix (see details) |
convergence |
A matrix returning |
kvec |
The vector of integers that indicates the number of basis. |
lamvec |
The vector of regularization parameters. |
info |
An array of convergence codes for all estimations in the process of computing the cross-validations |
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation #################### # From an object res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) fdaCV(obj=res) # CV with the estimation cv <- fdaCV(y=GDPv56,t,10^seq(-5,1,len=4), k=5:7) cv ## Nonlinear Estimation ####################### res <- nlCoefEst(y=GDPv56, t=t, lam=0.003, k=10) nlFdaCV(obj=res) # CV with the estimation cv <- nlFdaCV(y=GDPv56,t,10^seq(-5,1,len=4), k=5:7) ## Nonlinear Estimation with zeros ################################## data(simData) t <- seq(0,1,length.out=5) cv <- nlFdaCV(y=simData, t=t, lam=c(1e-5, 1e-2), k=c(6:8), addDat=TRUE) print(cv, conv=TRUE)data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation #################### # From an object res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) fdaCV(obj=res) # CV with the estimation cv <- fdaCV(y=GDPv56,t,10^seq(-5,1,len=4), k=5:7) cv ## Nonlinear Estimation ####################### res <- nlCoefEst(y=GDPv56, t=t, lam=0.003, k=10) nlFdaCV(obj=res) # CV with the estimation cv <- nlFdaCV(y=GDPv56,t,10^seq(-5,1,len=4), k=5:7) ## Nonlinear Estimation with zeros ################################## data(simData) t <- seq(0,1,length.out=5) cv <- nlFdaCV(y=simData, t=t, lam=c(1e-5, 1e-2), k=c(6:8), addDat=TRUE) print(cv, conv=TRUE)
Estimation of the functional parameters in a multiple functional regression. The smoothing parameters and the number of basis is assumed to be known.
funcreg(form, create_basis=create.bspline.basis, LD=2, lambda, k, regularized=TRUE, CstInt=FALSE, CV=FALSE, data=NULL, alpha=1e-5, optAlpha=FALSE, controlAlpha=list(), ...) ## S3 method for class 'funcreg' print(x, ...) ## S3 method for class 'funcreg' summary(object, ...) ## S3 method for class 'funcreg' fitted(object, ...) ## S3 method for class 'funcreg' residuals(object, ...)funcreg(form, create_basis=create.bspline.basis, LD=2, lambda, k, regularized=TRUE, CstInt=FALSE, CV=FALSE, data=NULL, alpha=1e-5, optAlpha=FALSE, controlAlpha=list(), ...) ## S3 method for class 'funcreg' print(x, ...) ## S3 method for class 'funcreg' summary(object, ...) ## S3 method for class 'funcreg' fitted(object, ...) ## S3 method for class 'funcreg' residuals(object, ...)
x |
An object of class "funcreg" |
object |
An object of class "funcreg" |
form |
A formula for the functional regression. Arguments are
objects of class "myfda" obtained either by |
create_basis |
The function used to create the basis object (see
|
LD |
Either a nonnegative integer defining an order of a
derivative or a linear differential operator (see
|
lambda |
A vector of regularization parameters that penalizes for the absence of
smoothness. The dimention is 2 times the number of regressors plus 1
if there is an intercept and if |
k |
A vector of integers representing the number of basis for each
functional parameter. The first is for the intercept (if there is an
intercept and that |
regularized |
If |
CstInt |
If |
CV |
if |
data |
An optional list of |
alpha |
The regularization parameter. The value is added to the diagonal of the regression matrix to make sure it is positive definite. |
optAlpha |
If |
controlAlpha |
A list of tuning parameter for the choice of the
optimal |
... |
For |
It returns an object of 'class' "funcreg"
The object of class "funcreg" is a list containing at least:
X |
The list of functional regressors. |
Y |
The functional response. |
data |
A list with element "t" for time units of the observed data and "Y" for the matrix of observed response varable. |
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) res summary(res) plot(fitted(res)) plot(residuals(res)) ## Getting the optimal regularization parameter res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001), optAlpha=TRUE) resdata(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) res summary(res) plot(fitted(res)) plot(residuals(res)) ## Getting the optimal regularization parameter res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001), optAlpha=TRUE) res
The dataset includes GDP's of 90 countries from 1960 to 1980. The frequency is yearly.
data(GDPv56)data(GDPv56)
A matrix containing 90 columns, one per country. Dates are reported as rownames().
GDP of ARGENTINA
GDP of AUSTRALIA
GDP of AUSTRIA
GDP of BURUNDI
GDP of BELGIUM
GDP of BENIN
GDP of BURKINA FASO
GDP of BOLIVIA
GDP of BRAZIL
GDP of CANADA
GDP of SWITZERLAND
GDP of CHILE
GDP of COTE D'IVOIRE
GDP of CAMEROON
GDP of CONGO REPUBLIC OF
GDP of COLOMBIA
GDP of COMOROS
GDP of CAPE VERDE
GDP of COSTA RICA
GDP of DENMARK
GDP of DOMINICAN REPUBLIC
GDP of ALGERIA
GDP of ECUADOR
GDP of EGYPT
GDP of SPAIN
GDP of FINLAND
GDP of FRANCE
GDP of GABON
GDP of UNITED KINGDOM
GDP of GHANA
GDP of GUINEA
GDP of GAMBIA THE
GDP of GUINEA-BISSAU
GDP of GREECE
GDP of GUATEMALA
GDP of HONG KONG
GDP of HONDURAS
GDP of INDONESIA
GDP of INDIA
GDP of IRELAND
GDP of IRAN
GDP of ICELAND
GDP of ISRAEL
GDP of ITALY
GDP of JAMAICA
GDP of JORDAN
GDP of JAPAN
GDP of KENYA
GDP of KOREA REPUBLIC OF
GDP of SRI LANKA
GDP of LESOTHO
GDP of LUXEMBOURG
GDP of MOROCCO
GDP of MADAGASCAR
GDP of MEXICO
GDP of MALI
GDP of MOZAMBIQUE
GDP of MAURITIUS
GDP of MALAWI
GDP of MALAYSIA
GDP of NIGERIA
GDP of NICARAGUA
GDP of NETHERLANDS
GDP of NORWAY
GDP of NEW ZEALAND
GDP of PAKISTAN
GDP of PANAMA
GDP of PERU
GDP of PHILIPPINES
GDP of PORTUGAL
GDP of PARAGUAY
GDP of RWANDA
GDP of SENEGAL
GDP of SINGAPORE
GDP of EL SALVADOR
GDP of SWEDEN
GDP of SYRIA
GDP of CHAD
GDP of TOGO
GDP of THAILAND
GDP of TRINIDAD AND TOBAGO
GDP of TURKEY
GDP of TAIWAN
GDP of UGANDA
GDP of URUGUAY
GDP of UNITED STATES
GDP of VENEZUELA
GDP of SOUTH AFRICA
GDP of ZAMBIA
GDP of ZIMBABWE
TBA
Several functions that computes the leave-one-out cross-validation of functional data. They include cases of linear and nonlinear fit.
nlGetLam(y, t, lamInt, k, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, maxitalgo=100, tolalgo=1e-7, type=c("Brent","GS"), typels=c("brent","grid"), addDat=FALSE, ...) nlGetLandKopt(y, t, lamInt, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-7, maxitalgo=100, tolalgo=1e-6, type=c("Brent", "GS"), typels=c("brent","grid"), addDat=FALSE, ...) nlGetLandK(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, typels=c("brent","grid"), addDat=FALSE, ...) getLam(y, t, lamInt, k, L=2, create_basis=create.bspline.basis, maxitalgo=100, tolalgo=1e-7, type=c("Brent","GS"), ...) getLandK(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, ...) getLandKopt(y, t, lamInt, kvec, L=2, create_basis=create.bspline.basis, maxitalgo=100, tolalgo=1e-6, type=c("Brent", "GS"), ...)nlGetLam(y, t, lamInt, k, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, maxitalgo=100, tolalgo=1e-7, type=c("Brent","GS"), typels=c("brent","grid"), addDat=FALSE, ...) nlGetLandKopt(y, t, lamInt, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-7, maxitalgo=100, tolalgo=1e-6, type=c("Brent", "GS"), typels=c("brent","grid"), addDat=FALSE, ...) nlGetLandK(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, maxit=100, tol=1e-8, typels=c("brent","grid"), addDat=FALSE, ...) getLam(y, t, lamInt, k, L=2, create_basis=create.bspline.basis, maxitalgo=100, tolalgo=1e-7, type=c("Brent","GS"), ...) getLandK(y, t, lamvec, kvec, L=2, create_basis=create.bspline.basis, ...) getLandKopt(y, t, lamInt, kvec, L=2, create_basis=create.bspline.basis, maxitalgo=100, tolalgo=1e-6, type=c("Brent", "GS"), ...)
y |
A |
t |
A numeric vector of time units. The number of elements is equal to the
number of rows of |
lamvec |
A vector of regularization parameters that penalizes for the absence of smoothness. |
lamInt |
A vector that contains the lower and upper bounds for Lambda that is passed to the Brent or Golden Section method. |
kvec |
A vector of integers that indicates the number of basis. |
k |
A scalar that indicates the number of basis. |
L |
Either a
nonnegative integer defining an order of a derivative or a linear
differential operator (see |
create_basis |
The function used to create the basis object (see
|
maxit |
The maximum number of iteration for the Newton method |
tol |
The tolerance parameter for the stopping rule of the Newton method |
maxitalgo |
Maximum number of iteration for the brent and Golden-Section methods |
tolalgo |
Tolerance level for the stopping rule of the Brent or Golden-Section method. |
type |
Which algorithm should we use to get the lambda. |
typels |
The |
addDat |
If TRUE, fake observations are added before and after assuming stationarity. for the estimation, the time span is expanded accordingly. |
... |
Other argument that is passed to |
(see
create.bspline.basis).
Function that starts with 'nl' are the nonlinear functional
data (see coefEst).
getLam and nlGetLam, finds the Lambda that
minimizes the cross-validation for a given k using either the
Brent method or the Golden-Section method.
nlGetLandK and getLandK find the optimal Lambda and
k using a grid search. The grid is provided by the user through
lamvec and kvec.
getLandKopt and nlGetLandKopt find the optimal Lambda and
k using a grid search for k only. Lambda is obtained
using the Brent or Golden-Section method.
getLam and nlGetLam returns a list with the
following items:
lam |
The optimal Lambda |
info |
A convergence code for the optimization method (0 for normal convergence). |
iter |
The number of iterations for the Brent or Golden-Section method. |
cv |
The minimum cross-validation |
getLandK, codenlGetLandK, getLandKopt, and
codenlGetLandKopt, returns an object of class "myfda" (see
coefEst). In addition to the usual element, the list
inludes information about the search.
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation #################### # Using a grid nlam <- 5 lamvec <- 10^seq(-5,1,length.out=nlam) kvec <- 5:7 res1 <- getLandK(GDPv56, t, lamvec, kvec) res1 # Using Brent res2 <- getLandKopt(GDPv56, t, lamvec, kvec, tolalgo=1e-5) res2 ## Nonlinear estimation ########################### # Using a grid res3 <- nlGetLandK(GDPv56, t, lamvec, kvec) res3 # Using Brent res4 <- nlGetLandKopt(GDPv56, t, lamvec, kvec, tolalgo=1e-5) res3data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation #################### # Using a grid nlam <- 5 lamvec <- 10^seq(-5,1,length.out=nlam) kvec <- 5:7 res1 <- getLandK(GDPv56, t, lamvec, kvec) res1 # Using Brent res2 <- getLandKopt(GDPv56, t, lamvec, kvec, tolalgo=1e-5) res2 ## Nonlinear estimation ########################### # Using a grid res3 <- nlGetLandK(GDPv56, t, lamvec, kvec) res3 # Using Brent res4 <- nlGetLandKopt(GDPv56, t, lamvec, kvec, tolalgo=1e-5) res3
These are the plot and print methods which are associated with the objects of class "myfda".
## S3 method for class 'myfda' plot(x, which=NULL, addpoints=TRUE, npoints=100, add=FALSE, ...) ## S3 method for class 'myfda' print(x, ...) ## S3 method for class 'myfdaCV' print(x, digits=4, conv=FALSE, ...) ## S3 method for class 'myfda' x[i=NULL]## S3 method for class 'myfda' plot(x, which=NULL, addpoints=TRUE, npoints=100, add=FALSE, ...) ## S3 method for class 'myfda' print(x, ...) ## S3 method for class 'myfdaCV' print(x, digits=4, conv=FALSE, ...) ## S3 method for class 'myfda' x[i=NULL]
x |
Object of class "myfda" (see |
which |
Which curve shall we plot |
addpoints |
If |
npoints |
The number of points used to plot the curves |
digits |
The number of digits to be printed |
conv |
Shall the information about convergence be printed |
add |
If |
i |
The selection index. |
... |
Other argument that is passed to the |
data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) print(res) plot(res) plot(res,which=1:3) ## Using the operator [] plot(res[1:4]) res2 <- coefEst(y=GDPv56, t=t, lam=0.3, k=15) plot(res,which=1) plot(res2,which=1, add=TRUE, col=2, lty=3)data(GDPv56) t <- seq(0,1,len=nrow(GDPv56)) ## Linear estimation res <- coefEst(y=GDPv56, t=t, lam=0.003, k=15) print(res) plot(res) plot(res,which=1:3) ## Using the operator [] plot(res[1:4]) res2 <- coefEst(y=GDPv56, t=t, lam=0.3, k=15) plot(res,which=1) plot(res2,which=1, add=TRUE, col=2, lty=3)
It plot the estimated functional coefficients with confidence
bands. The coefficients are estimated by funcreg.
plotCoef(obj, which, n = c(50, 50), fixeds=NULL, fixedt=NULL, plotWF=TRUE, ...) plotConfInt(obj, which, type = c("beta_t", "beta_s", "beta_st"), n = c(50, 50), level = 0.95, plotWF = TRUE, beta=NULL)plotCoef(obj, which, n = c(50, 50), fixeds=NULL, fixedt=NULL, plotWF=TRUE, ...) plotConfInt(obj, which, type = c("beta_t", "beta_s", "beta_st"), n = c(50, 50), level = 0.95, plotWF = TRUE, beta=NULL)
obj |
An object of class "funcreg" |
which |
Which functional coefficient we want to plot. 0 for the intercept, 1 for the first functional slope and so on. |
n |
The number of grid points for the plot. The first element is for
the |
fixeds |
If |
fixedt |
If |
plotWF |
If |
type |
The type of plot (see details). |
level |
The level for the confidence interval |
beta |
A one or two argument function (see details). |
... |
Other argument. to pass to either |
If type="beta_t", the default, the integral with respect to
s is shown with pointwise confidence bands. It is simply the functional
intercept with its pointwise confidence bands if which=0.
If type="beta_s" (not applicable for which=0), the
integral with respect to t is shown with its pointwise confidence bands.
If type="beta_st" (not applicable for which=0), the whole
three dimensional curve is shown with its pointwise confidence
surfaces.
If beta is provided, the estimated curve is replaced by the one
produced by the function beta, but the same confidence bands are
produced. Useful for pointwise hypothesis testing. If
type="beta_s" or type="beta_t", beta must be a
function of t or s. If type="beta_st", it must be a
function of both.
If plotWF=FALSE and the expected plot is a surface, it returns an
object of class "trellis" produced by wireframe.
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) plotCoef(res, 1, type="beta_st") plotConfInt(res, 1, type="beta_t") ## Assume we what to do pointwise hypothesis testing plotConfInt(res, 1, type="beta_t", beta=function(t) .6-.7*t) ## Nice 3-D confidence interval plotConfInt(res, 1, type="beta_st")data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) plotCoef(res, 1, type="beta_st") plotConfInt(res, 1, type="beta_t") ## Assume we what to do pointwise hypothesis testing plotConfInt(res, 1, type="beta_t", beta=function(t) .6-.7*t) ## Nice 3-D confidence interval plotConfInt(res, 1, type="beta_st")
This dataset is used to show how the nonlinear fit can be used when some observations are zero.
data(simData)data(simData)
A matrix containing 293 columns, and 5 time units.
It computes the functional variance of the estimated functional
parameters obtained by funcreg
## S3 method for class 'funcreg' vcov(object, which, type = c("beta", "beta_t", "beta_s", "beta_st"), s = NULL, t = NULL, ...)## S3 method for class 'funcreg' vcov(object, which, type = c("beta", "beta_t", "beta_s", "beta_st"), s = NULL, t = NULL, ...)
object |
An object of class "funcreg" |
which |
The variance of which functional parameters shall we compute? 0 for the intercept, 1 for the first functional slope and so on. |
type |
What type of variance to compute (see details). |
s |
If type is "beta_s", the variance is computed at each element
of |
t |
If type is "beta_t", the variance is computed at each element
of |
... |
Argument to pass to other objects |
The function computed the variance of the integral of the functional
parameters (single for the intercept and double for the slopes) when
type='beta'.
If type='beta_t', it is the pointwise variance of the functional
intercept if which=0 and the pointwise variance of the integral
of the slopes which respect to s. By default (t=NULL) the
time units of the observed data is used. Alternatively, we can provide
a vector of points.
If type='beta_s', (not available for which=0) it is the
pointwise variance of the integral of the slopes which respect to
y. By default (s=NULL), equally spaced grid points are
generated using the range of s-basis and the number of time units equals
to the one from the observed observations.
If type='beta_st' (not available for which=0), a two
dimensional pointwise variance is computed.
For the last three cases, vcov returns either a one dimension
functional data object or a two-dimensional one.
It returns a list containing at least:
V |
Either a numeric value when |
Ramsay, James O., & Silverman, Bernard W. (2005), Functional Data Analysis, Springer, New York.
data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) vcov(res, which=0) plot(vcov(res, 1, type="beta_t")$V)data(GDPv56) ## We just create response and a covariate artificialy from the GDP ## series y <- GDPv56[,1:30] x <- GDPv56[,31:60] t <- seq(0,1,len=nrow(y)) ## First we create the "myfda" objects yfd <- coefEst(y, t, .0004, 15, 2) xfd <- coefEst(x, t, .0004, 15, 2) ## we just set lambda and k to arbitrary values res <- funcreg(yfd~xfd, k=c(5,5), lambda=c(.001,.001,.001)) vcov(res, which=0) plot(vcov(res, 1, type="beta_t")$V)