From 6658e0fab55873f2ebe00eceabd766684f115b56 Mon Sep 17 00:00:00 2001 From: Xiongtao Dai Date: Tue, 24 Nov 2015 13:30:36 -0800 Subject: [PATCH] createDesignPlot improved; document lwls2dV2 --- DESCRIPTION | 43 +++++++++++++++----- NAMESPACE | 9 ++++- R/RcppExports.R | 8 ++-- R/Rlwls1d.R | 5 ++- R/createDesignPlot.R | 78 +++++++++++++++++++----------------- R/designPlotCount.R | 21 +++++----- R/lwls2dV2.R | 28 +++++++------ man/CheckData.Rd | 2 +- man/CheckOptions.Rd | 2 +- man/CrCovYX.Rd | 13 +++--- man/CrCovYZ.Rd | 2 +- man/FPCA.Rd | 9 +++-- man/FPCAder.Rd | 2 +- man/FPCAregFunc.Rd | 4 +- man/FPCAregScalar.Rd | 14 +++++-- man/FVPA.Rd | 8 ++-- man/HandleNumericsAndNAN.Rd | 2 +- man/Rlwls1d.Rd | 4 +- man/SetOptions.Rd | 2 +- man/createCovPlot.Rd | 4 +- man/createDesignPlot.Rd | 8 ++-- man/createDiagnosticsPlot.Rd | 2 +- man/createFuncBoxPlot.Rd | 8 ++-- man/createOutliersPlot.Rd | 8 ++-- man/createScreePlot.Rd | 6 +-- man/fitted.FPCA.Rd | 2 +- man/fitted.FregObj.Rd | 2 +- man/makePACEinputs.Rd | 2 +- man/print.FPCA.Rd | 2 +- man/sparsify.Rd | 6 ++- man/tPACE.Rd | 2 +- man/wiener.Rd | 2 +- src/RcppExports.cpp | 26 ++++++------ 33 files changed, 196 insertions(+), 140 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ebef7642..e10c75ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,17 +4,42 @@ Title: PACE package for Functional Data Analysis and Empirical Dynamics URL: https://github.com/hadjipantelis/tPACE Version: 0.0.0.9000 Date: 2015-08-14 -Author: Xiongtao Dai, - Pantelis Z. Hadjipantelis, - Hao Ji, - Hans-Georg Mueller, +Author: Xiongtao Dai, + Pantelis Z. Hadjipantelis, + Hao Ji, + Hans-Georg Mueller, Jane-Ling Wang Maintainer: Pantelis Z. Hadjipantelis -Description: PACE is a versatile package that provides implementation of various methods of Functional Data Analysis (FDA) and Empirical Dynamics. The core of this package is Functional Principal Component Analysis (FPCA), a key technique for functional data analysis, for sparsely or densely sampled random trajectories and time courses, via the Principal Analysis by Conditional Estimation (PACE) algorithm. PACE is useful for the analysis of data that have been generated by a sample of underlying (but usually not fully observed) random trajectories. It does not rely on pre-smoothing of trajectories, which is problematic if functional data are sparsely sampled. PACE provides options for functional regression and correlation, for Longitudinal Data Analysis, the analysis of stochastic processes from samples of realized trajectories, and for the analysis of underlying dynamics. -Depends: R (>= 3.1.0) -License: BSD_3_clause +Description: PACE is a versatile package that provides implementation of + various methods of Functional Data Analysis (FDA) and Empirical Dynamics. + The core of this package is Functional Principal Component Analysis (FPCA), + a key technique for functional data analysis, for sparsely or densely + sampled random trajectories and time courses, via the Principal Analysis by + Conditional Estimation (PACE) algorithm. PACE is useful for the analysis of + data that have been generated by a sample of underlying (but usually not + fully observed) random trajectories. It does not rely on pre-smoothing of + trajectories, which is problematic if functional data are sparsely sampled. + PACE provides options for functional regression and correlation, for + Longitudinal Data Analysis, the analysis of stochastic processes from + samples of realized trajectories, and for the analysis of underlying + dynamics. +Depends: + R (>= 3.1.0) +License: BSD_3_clause LazyData: false -Imports: Rcpp (>= 0.11.5), RcppEigen, gtools, Hmisc, plot3D, MASS, pracma, numDeriv +Imports: + Rcpp (>= 0.11.5), + RcppEigen, + gtools, + Hmisc, + plot3D, + MASS, + pracma, + numDeriv LinkingTo: Rcpp, RcppEigen -Suggests: testthat, rgl, aplpack +Suggests: + testthat, + rgl, + aplpack NeedsCompilation: yes +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index dfcfd83f..81bfc426 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,22 +1,28 @@ -# Generated by roxygen2 (4.1.1): do not edit by hand +# Generated by roxygen2: do not edit by hand S3method(fitted,FPCA) S3method(fitted,FregObj) S3method(print,FPCA) export(CrCovYX) +export(CrCovYXfast) export(CrCovYZ) export(FPCA) export(FPCAder) export(FPCAregFunc) +export(FPCAregFuncExp) export(FPCAregScalar) +export(FPCAregScalarExp) export(FVPA) export(Rlwls1d) +export(createBetaPlots) export(createCovPlot) export(createDesignPlot) export(createDiagnosticsPlot) export(createFuncBoxPlot) +export(createModeOfVarPlot) export(createOutliersPlot) export(createScreePlot) +export(lwls2dV2) export(makePACEinputs) export(sparsify) export(wiener) @@ -32,5 +38,4 @@ importFrom(pracma,midpoint) importFrom(pracma,mod) importFrom(pracma,ones) importFrom(pracma,uniq) -importFrom(rARPACK,eigs) useDynLib(tPACE) diff --git a/R/RcppExports.R b/R/RcppExports.R index 219d7b9a..211962ce 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -21,10 +21,6 @@ interp2lin <- function(xin, yin, zin, xou, you) { .Call('tPACE_interp2lin', PACKAGE = 'tPACE', xin, yin, zin, xou, you) } -RmullwlskCC <- function(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck) { - .Call('tPACE_RmullwlskCC', PACKAGE = 'tPACE', bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck) -} - Rmullwlsk <- function(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp = TRUE) { .Call('tPACE_Rmullwlsk', PACKAGE = 'tPACE', bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp) } @@ -33,6 +29,10 @@ Rmullwlsk_old <- function(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCh .Call('tPACE_Rmullwlsk_old', PACKAGE = 'tPACE', bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp) } +RmullwlskCC <- function(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck) { + .Call('tPACE_RmullwlskCC', PACKAGE = 'tPACE', bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck) +} + Rrotatedmullwlsk <- function(bw, kernel_type, tPairs, cxxn, win, xygrid, npoly, bwCheck) { .Call('tPACE_Rrotatedmullwlsk', PACKAGE = 'tPACE', bw, kernel_type, tPairs, cxxn, win, xygrid, npoly, bwCheck) } diff --git a/R/Rlwls1d.R b/R/Rlwls1d.R index 49e52326..74c0c711 100644 --- a/R/Rlwls1d.R +++ b/R/Rlwls1d.R @@ -18,8 +18,11 @@ Rlwls1d <- function( bw, kernel_type, win, xin, yin, xout, npoly = 1L, nder = 0L){ + if (is.unsorted(xout)) + stop('`xout` needs to be sorted in increasing order') + # Deal with NA/NaN measurement values - NAinY = is.na(yin); + NAinY = is.na(xin) | is.na(yin) | is.na(win) if(any(NAinY)){ win = win[!NAinY] xin = xin[!NAinY] diff --git a/R/createDesignPlot.R b/R/createDesignPlot.R index 665b9394..13399b29 100644 --- a/R/createDesignPlot.R +++ b/R/createDesignPlot.R @@ -21,7 +21,7 @@ #' createDesignPlot(sampWiener$tList, sort(unique(unlist(sampWiener$tList)))) #' @export -createDesignPlot = function(t, obsGrid = NULL, isColorPlot=FALSE, noDiagonal=TRUE, yname = NULL){ +createDesignPlot = function(t, obsGrid = NULL, isColorPlot=TRUE, noDiagonal=TRUE, yname = NULL, ...){ if( is.null(obsGrid)){ obsGrid = sort(unique(unlist(t))) } @@ -41,16 +41,14 @@ createDesignPlot = function(t, obsGrid = NULL, isColorPlot=FALSE, noDiagonal=TRU # xlab = 'Observed time grid', ylab = 'Observed time grid', # main = titleString, col = 'white') + oldpty <- par()[['pty']] + par(pty="s") if(isColorPlot == TRUE){ - par(pty="s") - createColorPlot(res, obsGrid,titleString) - par(pty="m") + createColorPlot(res, obsGrid,titleString, ...) } else { - par(pty="s") createBlackPlot(res, obsGrid,titleString) - par(pty="m") } - + par(pty=oldpty) } createBlackPlot = function(res, obsGrid,titleString ){ @@ -74,39 +72,47 @@ createBlackPlot = function(res, obsGrid,titleString ){ } -createColorPlot = function(res, obsGrid,titleString ){ -# for(i in 1:length(obsGrid)){ -# tmp = res[i,] -# idx = which(tmp > 0) -# if(length(idx) > 0){ -# for(j in 1:length(idx)){ -# points(obsGrid[i], obsGrid[idx[j]], col = searchCol(tmp[idx[j]]), -# pch = 19) -# } -# } -# } -# legend('right', c('1', '2', '3~5', '>=6'), pch = 14, -# col = c('red', 'purple', 'green', 'blue'), title = 'Count') - res[res >4 ] = 4; - resVals = sort(unique(as.vector(res))); - colPalette = c('white', 'black', 'blue', 'green', 'red') - resColPalt = colPalette[resVals+1] - +createColorPlot = function(res, obsGrid,titleString, ... ){ + res[res > 4] = 4; + # resVals = sort(unique(as.vector(res))); + # colPalette = c('white', 'black', 'blue', 'green', 'red') + # resColPalt = colPalette[resVals+1] # image(res, col= resColPalt, axes=FALSE, xlab = 'Observed support points', ylab = 'Observed support points', main = titleString) - u1 = as.vector(res) - u2 = as.vector(t(res)) - t1 = rep(obsGrid, times = length(obsGrid) ) + notZero <- res != 0 + nnres <- res[notZero] + ddd <- list(...) + + colVec <- c(`1`='black', `2`='blue', `3`='green', `4`='red') + if (!is.null(ddd[['col']])) + colVec[] <- ddd[['col']] + + pchVec <- rep(19, length(colVec)) + names(pchVec) <- names(colVec) + if (!is.null(ddd[['pch']])) + pchVec[] <- ddd[['pch']] + + cexVec <- seq(from=0.3, by=0.1, length.out=length(colVec)) + names(cexVec) <- names(colVec) + if (!is.null(ddd[['cex']])) + cexVec[] <- ddd[['cex']] + + if (!is.null(ddd[['xlab']])) + xlab <- ddd[['xlab']] + else + xlab <- 'Observed time grid' + + if (!is.null(ddd[['ylab']])) + ylab <- ddd[['ylab']] + else + ylab <- 'Observed time grid' + + t1 = rep(obsGrid, times = length(obsGrid)) t2 = rep(obsGrid, each = length(obsGrid)) - plot(t1, t2, col= 'black' , t= 'n', xlab = 'Observed time grid', ylab = 'Observed time grid', main = titleString, pch = 19 ) + plot(t1[notZero], t2[notZero], col= colVec[nnres], xlab=xlab, ylab=ylab, main = titleString, pch = pchVec[nnres], cex=cexVec[nnres] ) - points(t1[u1 == 1], t2[u2 ==1], col= 'black', pch = 19, cex =0.3) - points(t1[u1 == 2], t2[u2 ==2], col= 'blue', pch = 19, cex =0.4) - points(t1[u1 == 3], t2[u2 ==3], col= 'green', pch = 19, cex =0.5) - points(t1[u1 == 4], t2[u2 ==4], col= 'red', pch = 19, cex =0.6) -# axis(1, obsGrid[round(seq(1,length(obsGrid), length.out=11))], obsGrid[round(seq(1,length(obsGrid), length.out=11))],col.axis="black") -# axis(2, obsGrid[round(seq(1,length(obsGrid), length.out=11))], obsGrid[round(seq(1,length(obsGrid), length.out=11))],col.axis="black") - legend('right', c('1', '2', '3', '4+'), pch = 19, col = c('black','blue','green','red'), title = 'Count',bg='white' ) + if (!identical(unique(nnres), 1)) + legend('right', c('1', '2', '3', '4+'), pch = pchVec, col=colVec, pt.cex=cexVec, title = 'Count',bg='white' ) } diff --git a/R/designPlotCount.R b/R/designPlotCount.R index 2679fd5d..e6475a33 100644 --- a/R/designPlotCount.R +++ b/R/designPlotCount.R @@ -20,9 +20,8 @@ designPlotCount = function(t, obsGrid, noDiagonal, isColorPlot){ N = length(obsGrid) # number of distinct observed time pts res = matrix(0, nrow = N, ncol = N) - for(i in 1:length(t)){ - cur = t[[i]] - curidx = searchID(cur, obsGrid) + for(cur in t){ + curidx = match(cur, obsGrid) if(isColorPlot == FALSE){ res[curidx, curidx] = 1 } else { @@ -37,11 +36,11 @@ designPlotCount = function(t, obsGrid, noDiagonal, isColorPlot){ return(res) } -searchID = function(cur, obsGrid){ - ni = length(cur) - id = rep(0, ni) - for(i in 1:ni){ - id[i] = which(obsGrid == cur[i]) - } - return(id) -} \ No newline at end of file +# searchID = function(cur, obsGrid){ + # ni = length(cur) + # id = rep(0, ni) + # for(i in 1:ni){ + # id[i] = which(obsGrid == cur[i]) + # } + # return(id) +# } \ No newline at end of file diff --git a/R/lwls2dV2.R b/R/lwls2dV2.R index 60cb0d30..ef65fcbe 100644 --- a/R/lwls2dV2.R +++ b/R/lwls2dV2.R @@ -1,16 +1,18 @@ -# Uses Pantelis' cpp code. -# 2 dimensional local weighted least squares smoother. Only local linear smoother is implemented (no higher order, no derivative). -# bw: bandwidth, a scalar or a vector of length 2. -# kern: kernel used: 'gauss', 'rect', 'gausvar', 'epan' (default), 'quar' -# xin: an n by 2 dataframe or matrix of x-coordinate. -# yin: a vector of y-coordinate. -# win: a vector of weights on the observations. The number of count as in (maybe) raw covariance should be integrated into win. -# xout1: a p1-vector of first output coordinate grid. -# xout2: a p2-vector of second output coordinate grid. If both xout1 and xout2 are unspecified then the output gridpoints are set to the input gridpoints. -# xout: alternative to xout1 and xout2. A matrix of p by 2 specifying the output points. - -# Returns a p1 by p2 matrix of fitted values if xout is not specified. Otherwise a vector of length p. +#' Two dimensional local linear kernel smoother. +#' +#' Two dimensional local weighted least squares smoother. Only local linear smoother for estimating the original curve is available (no higher order, no derivative). +#' @param bw A scalar or a vector of length 2 specifying the bandwidth. +#' @param kern Kernel used: 'gauss', 'rect', 'gausvar', 'epan' (default), 'quar'. +#' @param xin An n by 2 dataframe or matrix of x-coordinate. +#' @param yin A vector of y-coordinate. +#' @param win A vector of weights on the observations. +#' @param xout1: a p1-vector of first output coordinate grid. Defaults to the input gridpoints if left unspecified. +#' @param xout2: a p2-vector of second output coordinate grid. Defaults to the input gridpoints if left unspecified. +#' @param xout: alternative to xout1 and xout2. A matrix of p by 2 specifying the output points (may be inefficient if the size of \code{xout} is small). +#' @return a p1 by p2 matrix of fitted values if xout is not specified. Otherwise a vector of length p corresponding to the rows of xout. +#' @export +# Uses Pantelis' cpp code. lwls2dV2 <- function(bw, kern='epan', xin, yin, win=NULL, xout1=NULL, xout2=NULL, xout=NULL, subset=NULL, crosscov = FALSE, userNumCores = NULL ) { if (length(bw) == 1){ bw <- c(bw, bw) @@ -30,7 +32,7 @@ lwls2dV2 <- function(bw, kern='epan', xin, yin, win=NULL, xout1=NULL, xout2=NULL } if (!is.null(xout1) && !is.null(xout2) && !is.null(xout)) { - stop('Either xout1/xout2 or xout should be specified.') + stop('Either xout1/xout2 or xout should be specified, but not both.') } if (is.null(xout1)) diff --git a/man/CheckData.Rd b/man/CheckData.Rd index 9dd9bef4..37b75419 100644 --- a/man/CheckData.Rd +++ b/man/CheckData.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/CheckData.R \name{CheckData} \alias{CheckData} diff --git a/man/CheckOptions.Rd b/man/CheckOptions.Rd index 6033e3b5..995edca4 100644 --- a/man/CheckOptions.Rd +++ b/man/CheckOptions.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/CheckOptions.R \name{CheckOptions} \alias{CheckOptions} diff --git a/man/CrCovYX.Rd b/man/CrCovYX.Rd index 8f4afebc..98b2ac46 100644 --- a/man/CrCovYX.Rd +++ b/man/CrCovYX.Rd @@ -1,17 +1,16 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/CrCovYX.R \name{CrCovYX} \alias{CrCovYX} \title{Functional Cross Covariance between longitudinal variable Y and longitudinal variable X} \usage{ CrCovYX(bw1 = NULL, bw2 = NULL, Ly1, Lt1 = NULL, Ymu1 = NULL, Ly2, - Lt2 = NULL, Ymu2 = NULL) + Lt2 = NULL, Ymu2 = NULL, fast = FALSE) } \arguments{ \item{bw1}{Scalar bandwidth for smoothing the cross-covariance function (if NULL it will be automatically estimated) (Y)} -\item{bw2}{Scalar bandwidth for smoothing the cross-covariance function (if NULL it will be automatically estimated) (X) -If the variables Ly1 and Ly2 are in matrix form the data are assumed dense and only the raw cross-covariance is returned.} +\item{bw2}{Scalar bandwidth for smoothing the cross-covariance function (if NULL it will be automatically estimated) (X)} \item{Ly1}{List of N vectors with amplitude information (Y)} @@ -24,6 +23,9 @@ If the variables Ly1 and Ly2 are in matrix form the data are assumed dense and o \item{Lt2}{List of N vectors with timing information (X)} \item{Ymu2}{Vector Q-1 Vector of length nObsGrid containing the mean function estimate (You can get that from FPCA) (X)} + +\item{fast}{Indicator to use gam smoothing instead of local-linear smoothing (semi-parametric option) +If the variables Ly1 and Ly2 are in matrix form the data are assumed dense and only the raw cross-covariance is returned.} } \value{ A list containing: @@ -39,11 +41,12 @@ Calculate the raw and the smoothed cross-covariance between functional predictor \examples{ Ly1= list( rep(2.1,7), rep(2.1,3),2.1 ); Lt1 = list(1:7,1:3, 1); -Ly2 = list( rep(1.1,7), rep(1.1,3),1.1); +Ly2 = list( rep(1.1,7), rep(1.1,3),1.1); Lt2 = list(1:7,1:3, 1); Ymu1 = rep(55,7); Ymu2 = rep(1.1,7); AA<-CrCovYX(Ly1 = Ly1, Ly2= Ly2, Lt1=Lt1, Lt2=Lt2, Ymu1=Ymu1, Ymu2=Ymu2) + } \references{ \cite{Yang, Wenjing, Hans‐Georg Müller, and Ulrich Stadtmüller. "Functional singular component analysis." Journal of the Royal Statistical Society: Series B (Statistical Methodology) 73.3 (2011): 303-324} diff --git a/man/CrCovYZ.Rd b/man/CrCovYZ.Rd index a92a54ee..d3369a7f 100644 --- a/man/CrCovYZ.Rd +++ b/man/CrCovYZ.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/CrCovYZ.R \name{CrCovYZ} \alias{CrCovYZ} diff --git a/man/FPCA.Rd b/man/FPCA.Rd index 81f4c4b8..fed47834 100644 --- a/man/FPCA.Rd +++ b/man/FPCA.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/FPCA.R \name{FPCA} \alias{FPCA} @@ -18,7 +18,7 @@ A list containing the following fields: \item{sigma2}{Variance for measure error.} \item{lambda}{A vector of length \emph{K} containing eigenvalues.} \item{phi}{An nWorkGrid by \emph{K} matrix containing eigenfunctions, supported on workGrid.} -\item{xiEst}{A \emph{n} by \emph{K} matrix containing the FPC estimates.} +\item{xiEst}{A \emph{n} by \emph{K} matrix containing the FPC estimates.} \item{xiVar}{A list of length \emph{n}, each entry containing the variance estimates for the FPC estimates.} \item{obsGrid}{The (sorted) grid points where all observation points are pooled.} \item{mu}{A vector of length nObsGrid containing the mean function estimate.} @@ -31,17 +31,18 @@ A list containing the following fields: \item{rho}{A regularizing scalar for the measurement error variance estimate.} \item{cumFVE}{A vector with the percentages of the total variance explained by each FPC. Increase to almost 1.} \item{FVE}{A percentage indicating the total variance explained by chosen FPCs with corresponding 'FVEthreshold'.} +\item{inputData}{A list containting the original 'y' and 't' lists used as inputs to FPCA.} } \description{ FPCA for dense or sparse functional data. } \details{ -Available control options are +Available control options are \describe{ \item{bwcov}{The bandwidth value for the smoothed covariance function; positive numeric - default: determine automatically based on 'bwcovMethod'} \item{bwcovMethod}{The bandwidth choice method for the smoothed covariance function; 'GMeanAndGCV','CV','GCV' - default: 'GMeanAndGCV'')} \item{bwmu}{The bandwidth value for the smoothed mean function (using 'CV' or 'GCV'); positive numeric - default: determine automatically based on 'bwmuMethod'} -\item{bwmuMethod}{The bandwidth choice method for the mean function; 'GMeanAndGCV','CV','GCV' - default: 'GMeanAndGCV''} +\item{bwmuMethod}{The bandwidth choice method for the mean function; 'GMeanAndGCV','CV','GCV' - default: 'GMeanAndGCV''} \item{dataType}{The type of design we have (usually distinguishing between sparse or dense functional data); 'Sparse', 'Dense', 'DenseWithMV', 'p>>n' - default: determine automatically based on 'IsRegular'} \item{diagnosticsPlot}{Make diagnostics plot (design plot, mean, scree plot and first k (<=3) eigenfunctions); logical - default: FALSE} \item{error}{Assume measurement error in the dataset; logical - default: TRUE} diff --git a/man/FPCAder.Rd b/man/FPCAder.Rd index fd66d565..36b856cd 100644 --- a/man/FPCAder.Rd +++ b/man/FPCAder.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/FPCAder.R \name{FPCAder} \alias{FPCAder} diff --git a/man/FPCAregFunc.Rd b/man/FPCAregFunc.Rd index b9edd2bb..ddfbf4bb 100644 --- a/man/FPCAregFunc.Rd +++ b/man/FPCAregFunc.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/FPCAregFunc.R \name{FPCAregFunc} \alias{FPCAregFunc} @@ -38,7 +38,7 @@ FPCAregFunc(depVar, expVarScal = NULL, expVarFunc = NULL, Functional regression for dense or sparse functional data. } \references{ -\cite{Yao, F., Mueller, H.G., Wang, J.L. "Functional Linear Regression Analysis for Longitudinal Data." Annals of Statistics 33, (2005): 2873-2903.(Dense data)} +\cite{Yao, F., Mueller, H.G., Wang, J.L. "Functional Linear Regression Analysis for Longitudinal Data." Annals of Statistics 33, (2005): 2873-2903.(Dense data)} \cite{Senturk, D., Nguyen, D.V. "Varying Coefficient Models for Sparse Noise-contaminated Longitudinal Data", Statistica Sinica 21(4), (2011): 1831-1856. (Sparse data)} } diff --git a/man/FPCAregScalar.Rd b/man/FPCAregScalar.Rd index fc8502f2..160c350e 100644 --- a/man/FPCAregScalar.Rd +++ b/man/FPCAregScalar.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/FPCAregScalar.R \name{FPCAregScalar} \alias{FPCAregScalar} @@ -6,7 +6,7 @@ \usage{ FPCAregScalar(fpcaObjList, extVar = NULL, depVar, varSelect = NULL, bootStrap = FALSE, regressionType = NULL, y = NULL, t = NULL, - lambda = 1e-09, ...) + lambda = 1e-09, bwYZ = NULL, ...) } \arguments{ \item{extVar}{A data.frame holding external explanatory variables; NAs will be omitted internally.} @@ -23,15 +23,21 @@ FPCAregScalar(fpcaObjList, extVar = NULL, depVar, varSelect = NULL, \item{lambda}{A scalar for the ridge correction in the sparse regression} +\item{bwYZ}{A scalar for bandwidth used among along function-to-scalar cross-covariance estimations} + \item{...}{Additional arguments} \item{fpcaObj}{A object of class FPCA returned by the function FPCA().} + +\item{bwYX}{A scalar for bandwidth used among along function-to-function cross-covariance estimations} } \description{ Functional regression for dense or sparse functional data. } \references{ -\cite{Yao, F., Mueller, H.G., Wang, J.L. "Functional Linear Regression Analysis for Longitudinal Data." Annals of Statistics 33, (2005): 2873-2903.(Dense data)} -\cite{Senturk, D., Nguyen, D.V. "Varying Coefficient Models for Sparse Noise-contaminated Longitudinal Data", Statistica Sinica 21(4), (2011): 1831-1856. (Sparse data)} +\cite{Yao, F., Mueller, H.G., Wang, J.L. +"Functional Linear Regression Analysis for Longitudinal Data." Annals of Statistics 33, (2005): 2873-2903.(Dense data)} +\cite{Senturk, D., Nguyen, D.V. "Varying Coefficient Models for Sparse Noise-contaminated Longitudinal Data", +Statistica Sinica 21(4), (2011): 1831-1856. (Sparse data)} } diff --git a/man/FVPA.Rd b/man/FVPA.Rd index ec1ec404..72e49378 100644 --- a/man/FVPA.Rd +++ b/man/FVPA.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/FVPA.R \name{FVPA} \alias{FVPA} @@ -17,8 +17,8 @@ FVPA(y, t, q = 0.1, optns = list()) } \value{ A list containing the following fields: -\item{sigma2}{Variance estimator of the functional variance process.} -\item{fpcaObjY}{FPCA object for the original data.} +\item{sigma2}{Variance estimator of the functional variance process.} +\item{fpcaObjY}{FPCA object for the original data.} \item{fpcaObjR}{FPCA object for the functional variance process associated with the original data.} } \description{ @@ -29,7 +29,7 @@ set.seed(1) n <- 20 pts <- seq(0, 1, by=0.05) sampWiener <- wiener(n, pts) -sampWiener <- sparsify(sampWiener, pts, 10) +sampWiener <- sparsify(sampWiener, pts, 10) fvpaObj <- FVPA(sampWiener$yList, sampWiener$tList) } \references{ diff --git a/man/HandleNumericsAndNAN.Rd b/man/HandleNumericsAndNAN.Rd index d22d6b72..b1034780 100644 --- a/man/HandleNumericsAndNAN.Rd +++ b/man/HandleNumericsAndNAN.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/HandleNumericsAndNAN.R \name{HandleNumericsAndNAN} \alias{HandleNumericsAndNAN} diff --git a/man/Rlwls1d.Rd b/man/Rlwls1d.Rd index 59a9d1e0..335453a7 100644 --- a/man/Rlwls1d.Rd +++ b/man/Rlwls1d.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/Rlwls1d.R \name{Rlwls1d} \alias{Rlwls1d} @@ -27,6 +27,6 @@ Rlwls1d(bw, kernel_type, win, xin, yin, xout, npoly = 1L, nder = 0L) Vector of length M with measurement values at the the point speficied by 'xout' } \description{ -One dimensional local linear kernel smoother for sparse data. +One dimensional local linear kernel smoother for longitudinal data. } diff --git a/man/SetOptions.Rd b/man/SetOptions.Rd index 87421661..3c9955f7 100644 --- a/man/SetOptions.Rd +++ b/man/SetOptions.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/SetOptions.R \name{SetOptions} \alias{SetOptions} diff --git a/man/createCovPlot.Rd b/man/createCovPlot.Rd index e4bcc6e4..9be6caf9 100644 --- a/man/createCovPlot.Rd +++ b/man/createCovPlot.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createCovPlot.R \name{createCovPlot} \alias{createCovPlot} @@ -10,7 +10,7 @@ createCovPlot(yy, covPlotType = "Fitted", isInteractive = FALSE) \item{yy}{returned object from FPCA().} \item{covPlotType}{a string specifying the type of covariance surface to be plotted: -'Smoothed': plot the smoothed cov surface +'Smoothed': plot the smoothed cov surface 'Fitted': plot the fitted cov surface 'Raw': plot the raw covariance scatter plot} diff --git a/man/createDesignPlot.Rd b/man/createDesignPlot.Rd index 5402bf0e..683b2a91 100644 --- a/man/createDesignPlot.Rd +++ b/man/createDesignPlot.Rd @@ -1,18 +1,18 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createDesignPlot.R \name{createDesignPlot} \alias{createDesignPlot} \title{Create the design plot of the functional data.} \usage{ -createDesignPlot(t, obsGrid = NULL, isColorPlot = FALSE, - noDiagonal = TRUE, yname = NULL) +createDesignPlot(t, obsGrid = NULL, isColorPlot = TRUE, noDiagonal = TRUE, + yname = NULL, ...) } \arguments{ \item{t}{a list of observed time points for functional data} \item{obsGrid}{a vector of sorted observed time points} -\item{isColorPlot}{an option for colorful plot: +\item{isColorPlot}{an option for colorful plot: TRUE: create color plot with color indicating counts FALSE: create black and white plot with dots indicating observed time pairs} diff --git a/man/createDiagnosticsPlot.Rd b/man/createDiagnosticsPlot.Rd index 1eb665d1..3d5e004c 100644 --- a/man/createDiagnosticsPlot.Rd +++ b/man/createDiagnosticsPlot.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createDiagnosticsPlot.R \name{createDiagnosticsPlot} \alias{createDiagnosticsPlot} diff --git a/man/createFuncBoxPlot.Rd b/man/createFuncBoxPlot.Rd index 2178cb0a..34f7bf3a 100644 --- a/man/createFuncBoxPlot.Rd +++ b/man/createFuncBoxPlot.Rd @@ -1,10 +1,10 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createFuncBoxPlot.R \name{createFuncBoxPlot} \alias{createFuncBoxPlot} \title{Create functional boxplot using 'bagplot' or 'pointwise' methodology} \usage{ -createFuncBoxPlot(fpcaObj, addIndx = NULL, variant = "bagplot") +createFuncBoxPlot(fpcaObj, addIndx = NULL, variant = "bagplot", ...) } \arguments{ \item{fpcaObj}{A object of class FPCA returned by the function FPCA().} @@ -12,6 +12,8 @@ createFuncBoxPlot(fpcaObj, addIndx = NULL, variant = "bagplot") \item{variant}{A character variable indicating which methodology should be used ('bagplot' or 'pointwise')to create the functional box-plot (Default: 'bagplot')} \item{addInx}{A vector of indeces corresponding to which samples one should overlay (Default: NULL)} + +\item{titleString}{a string variable to be used as title} } \description{ Using an FPCA object create a functional box-plot based on the function scores. @@ -23,7 +25,7 @@ pts <- seq(0, 1, by=0.05) sampWiener <- wiener(n, pts) sampWiener <- sparsify(sampWiener, pts, 10) res <- FPCA(sampWiener$yList, sampWiener$tList, list(dataType='Sparse', error=FALSE, kernel='epan', verbose=TRUE)) -createFuncBoxPlot(res, addIndx=c(1:3)) +createFuncBoxPlot(res, addIndx=c(1:3)) } \references{ \cite{P. J. Rousseeuw, I. Ruts, J. W. Tukey (1999): The bagplot: a bivariate boxplot, The American Statistician, vol. 53, no. 4, 382-387} diff --git a/man/createOutliersPlot.Rd b/man/createOutliersPlot.Rd index 528de289..be026092 100644 --- a/man/createOutliersPlot.Rd +++ b/man/createOutliersPlot.Rd @@ -1,13 +1,15 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createOutliersPlot.R \name{createOutliersPlot} \alias{createOutliersPlot} \title{Functional Principal Component Scores Plot} \usage{ -createOutliersPlot(fpcaObj) +createOutliersPlot(fpcaObj, titleString = NULL) } \arguments{ -\item{ret}{An FPCA class object returned by FPCA().} +\item{fpcaObj}{An FPCA class object returned by FPCA().} + +\item{titleString}{String for plot title} } \description{ This function will create using the first two FPC scores a set of convex hulls of the scores as these hulls are defined by the references. diff --git a/man/createScreePlot.Rd b/man/createScreePlot.Rd index 1f12ca90..ac9869c8 100644 --- a/man/createScreePlot.Rd +++ b/man/createScreePlot.Rd @@ -1,13 +1,13 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/createScreePlot.R \name{createScreePlot} \alias{createScreePlot} \title{Create the scree plot for the fitted eigenvalues} \usage{ -createScreePlot(ys) +createScreePlot(fpcaObj, ...) } \arguments{ -\item{ys}{a vector of FVE (functional variation explained) from FPCA object} +\item{fpcaObj}{A object of class FPCA returned by the function FPCA().} } \description{ This function will open a new device if not instructed otherwise. diff --git a/man/fitted.FPCA.Rd b/man/fitted.FPCA.Rd index a7fc0f5f..f64e2b2d 100644 --- a/man/fitted.FPCA.Rd +++ b/man/fitted.FPCA.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fitted.FPCA.R \name{fitted.FPCA} \alias{fitted.FPCA} diff --git a/man/fitted.FregObj.Rd b/man/fitted.FregObj.Rd index d1c568b6..6b24dfc7 100644 --- a/man/fitted.FregObj.Rd +++ b/man/fitted.FregObj.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/fitted.FRegObj.R \name{fitted.FregObj} \alias{fitted.FregObj} diff --git a/man/makePACEinputs.Rd b/man/makePACEinputs.Rd index 44a8e2d3..c67680cd 100644 --- a/man/makePACEinputs.Rd +++ b/man/makePACEinputs.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/makePACEinputs.R \name{makePACEinputs} \alias{makePACEinputs} diff --git a/man/print.FPCA.Rd b/man/print.FPCA.Rd index fa032a0a..1fd4ef91 100644 --- a/man/print.FPCA.Rd +++ b/man/print.FPCA.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/print.FPCA.R \name{print.FPCA} \alias{print.FPCA} diff --git a/man/sparsify.Rd b/man/sparsify.Rd index 7742e65c..e2d7a159 100644 --- a/man/sparsify.Rd +++ b/man/sparsify.Rd @@ -1,10 +1,10 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/sparsify.R \name{sparsify} \alias{sparsify} \title{Sparsify densely observed functional data} \usage{ -sparsify(samp, pts, sparsity, aggressive = FALSE) +sparsify(samp, pts, sparsity, aggressive = FALSE, fragment = FALSE) } \arguments{ \item{samp}{A matrix of densely observed functional data, with each row containing one sample.} @@ -14,6 +14,8 @@ sparsify(samp, pts, sparsity, aggressive = FALSE) \item{sparsity}{A vector of integers. The number of observation per sample is chosen to be one of the elements in sparsity with equal chance.} \item{aggressive}{Sparsify in an "aggressive" manner making sure that near-by readings are excluded.} + +\item{fragment}{Sparsify the observations into fragments, which are (almost) uniformly distributed in the time domain. Default to FALSE as not fragmenting. Otherwise a positive number specifying the approximate length of each fragment.} } \value{ A list of length 2, containing the following fields: diff --git a/man/tPACE.Rd b/man/tPACE.Rd index b607701a..86fc8776 100644 --- a/man/tPACE.Rd +++ b/man/tPACE.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pkgname.R \docType{package} \name{tPACE} diff --git a/man/wiener.Rd b/man/wiener.Rd index a5217f7a..993cb114 100644 --- a/man/wiener.Rd +++ b/man/wiener.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/wiener.R \name{wiener} \alias{wiener} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index badbf222..c1c9679f 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -84,9 +84,9 @@ BEGIN_RCPP return __result; END_RCPP } -// RmullwlskCC -Eigen::MatrixXd RmullwlskCC(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck); -RcppExport SEXP tPACE_RmullwlskCC(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP) { +// Rmullwlsk +Eigen::MatrixXd Rmullwlsk(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck, const bool& transp); +RcppExport SEXP tPACE_Rmullwlsk(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP, SEXP transpSEXP) { BEGIN_RCPP Rcpp::RObject __result; Rcpp::RNGScope __rngScope; @@ -98,13 +98,14 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const Eigen::Map& >::type xgrid(xgridSEXP); Rcpp::traits::input_parameter< const Eigen::Map& >::type ygrid(ygridSEXP); Rcpp::traits::input_parameter< const bool& >::type bwCheck(bwCheckSEXP); - __result = Rcpp::wrap(RmullwlskCC(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck)); + Rcpp::traits::input_parameter< const bool& >::type transp(transpSEXP); + __result = Rcpp::wrap(Rmullwlsk(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp)); return __result; END_RCPP } -// Rmullwlsk -Eigen::MatrixXd Rmullwlsk(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck, const bool& transp); -RcppExport SEXP tPACE_Rmullwlsk(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP, SEXP transpSEXP) { +// Rmullwlsk_old +Eigen::MatrixXd Rmullwlsk_old(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck, const bool& transp); +RcppExport SEXP tPACE_Rmullwlsk_old(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP, SEXP transpSEXP) { BEGIN_RCPP Rcpp::RObject __result; Rcpp::RNGScope __rngScope; @@ -117,13 +118,13 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const Eigen::Map& >::type ygrid(ygridSEXP); Rcpp::traits::input_parameter< const bool& >::type bwCheck(bwCheckSEXP); Rcpp::traits::input_parameter< const bool& >::type transp(transpSEXP); - __result = Rcpp::wrap(Rmullwlsk(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp)); + __result = Rcpp::wrap(Rmullwlsk_old(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp)); return __result; END_RCPP } -// Rmullwlsk_old -Eigen::MatrixXd Rmullwlsk_old(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck, const bool& transp); -RcppExport SEXP tPACE_Rmullwlsk_old(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP, SEXP transpSEXP) { +// RmullwlskCC +Eigen::MatrixXd RmullwlskCC(const Eigen::Map& bw, const std::string kernel_type, const Eigen::Map& tPairs, const Eigen::Map& cxxn, const Eigen::Map& win, const Eigen::Map& xgrid, const Eigen::Map& ygrid, const bool& bwCheck); +RcppExport SEXP tPACE_RmullwlskCC(SEXP bwSEXP, SEXP kernel_typeSEXP, SEXP tPairsSEXP, SEXP cxxnSEXP, SEXP winSEXP, SEXP xgridSEXP, SEXP ygridSEXP, SEXP bwCheckSEXP) { BEGIN_RCPP Rcpp::RObject __result; Rcpp::RNGScope __rngScope; @@ -135,8 +136,7 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const Eigen::Map& >::type xgrid(xgridSEXP); Rcpp::traits::input_parameter< const Eigen::Map& >::type ygrid(ygridSEXP); Rcpp::traits::input_parameter< const bool& >::type bwCheck(bwCheckSEXP); - Rcpp::traits::input_parameter< const bool& >::type transp(transpSEXP); - __result = Rcpp::wrap(Rmullwlsk_old(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck, transp)); + __result = Rcpp::wrap(RmullwlskCC(bw, kernel_type, tPairs, cxxn, win, xgrid, ygrid, bwCheck)); return __result; END_RCPP }