Library: | fda |
See also: | inprod createfdbasis evalfd getbasismatrix |
Quantlet: | data2fd | |
Description: | converts an array of function values and a matrix of argument values into an fd object. |
Usage: | fd = data2fd(y,argvals,basisfd{,Lfd{,W{,lambda}}}) | |
Input: | ||
y | p1 x p2 x p3 array, (observed) functional values used to compute the functional data object. p1 is the number of observed values per replication, p2 is the number of replications, p3 is the number of variables. | |
argvals | n x m matrix, argument values where m = 1 or m = p2, respectively. If m = 1 the same arguments are applied to all replications and variables. Otherwise m = p2 must hold (each replication is applied to a specific vector of arguments). | |
basisfd | list, fdbasis object | |
Lfd | list, optional, identifies the penalty term. This can be a scalar (>= 1) containing the order of derivative to penalize, or an LDO object if an LDO with variable coefficients is to be penalized (see createldo.xpl). When applying an LDO with constant coefficients, Lfd is a (r x 2) matrix, where the first column contains the coefficients, the second one the orders of derivatives. The default value is Lfd = 2. | |
W | matrix, optional, weight matrix (see getbasismatrix.xpl), default value is the identity matrix. | |
lambda | scalar, optional, parameter for roughness penalty smoothing. If lambda is not specified it will be estimated by the data for each replication separately. | |
Output: | ||
fd | list, contains the (nbasis x p2 x p3) array of estimated coefficients and the underlying fdbasis object. nbasis is the number of basis functions as indicated in the fdbasis object. |
library("fda") tvec = #(0, 2, 3, 6, 10) bspl = createfdbasis("bspline", #(0, 10), 7, tvec) ; one example for an LDO with constant coefficients: lfd = #(0.5, 1) ~ #(2, 3) proc(wt) = LDO1(evalarg) wt = matrix(2, rows(evalarg), cols(evalarg)) wt[1] = 1.25 .* evalarg wt[2] = 0.5 .* evalarg^2 endp LDO = createldo("LDO1", #(1, 3)) y = #(1, 2, 3, 4, 5)~#(0, 2, 3.97, NaN, 10.5)~#(9, 7, 5, 4,-3) tvec2 = tvec ~ tvec - 1 ~ tvec - 2 fdo = data2fd(y, tvec2, bspl, LDO) fdo.coef
Contents of coef [1,] 1 0.74783 7 [2,] -0.13273 0.85752 4.9123 [3,] 1.7809 3.9261 4.3442 [4,] 3.7239 5.6581 5.4914 [5,] 3.8744 9.5958 -1.142 [6,] 4.7922 10.791 -4.2965 [7,] 5 10.407 -3.8023