A S3 class for univariate functional data on a common grid
A S3 class for univariate functional data on a common grid
The hmatrix class represents data for a functional historical effect. The class is basically a matrix containing the time and the id for the observations of the functional response. The functional covariate is contained as attribute.
time: set of argument values of the response in long format, i.e. at which t the response curve is observed
id: specify to which curve the point belongs to, id from 1, 2, ..., n.
x: matrix of functional covariate, each trajectory is in one row
argvals: set of argument values, i.e., the common gird at which the functional covariate is observed, by default 1:ncol(x)
timeLab: name of the time axis, by default t
idLab: name of the id variable, by default wideIndex
xLab: name of the functional variable, by default NULL
argvalsLab: name of the argument for the covariate by default s
Returns
An matrix object of type "hmatrix"
Details
In the hmatrix class the id has to run from i=1, 2, ..., n including all integers from 1 to n. The rows of the functional covariate x correspond to those observations.
Examples
## Example for a hmatrix objectt1 <- rep((1:5)/2, each =3)id1 <- rep(1:3,5)x1 <- matrix(1:15, ncol =5)s1 <-(1:5)/2myhmatrix <- hmatrix(time = t1, id = id1, x = x1, argvals = s1, timeLab ="t1", argvalsLab ="s1", xLab ="test")# extract with [ keeps attributes # select observations of subjects 2 and 3myhmatrixSub <- myhmatrix[id1 %in% c(2,3),]str(myhmatrixSub)getX(myhmatrixSub)getX(myhmatrix)# get timemyhmatrix[,1]# as column matrix as drop = FALSEgetTime(myhmatrix)# as vector# get idmyhmatrix[,2]# as column matrix as drop = FALSEgetId(myhmatrix)# as vector# subset hmatrix on the basis of an index, which is defined on the curve levelreweightData(data = list(hmat = myhmatrix), vars ="hmat", index = c(1,1,2))# this keeps only the unique x values in attr(,'x') but multiplies the corresponding# ids and times in the time id matrix # for bhistx baselearner, there may be an additional id variable for the tensor productnewdat <- reweightData(data = list(hmat = myhmatrix, repIDx = rep(1:nrow(attr(myhmatrix,'x')), length(attr(myhmatrix,"argvals")))), vars ="hmat", index = c(1,1,2), idvars="repIDx")length(newdat$repIDx)## use hmatrix within a data.framemydat <- data.frame(I(myhmatrix), z=rnorm(3)[id1])str(mydat)str(mydat[id1 %in% c(2,3),])str(myhmatrix[id1 %in% c(2,3),])
See Also
getTime.hmatrix to extract attributes, and ?"[.hmatrix" for the extract method.