Skip to content

Commit

Permalink
fixed export import
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossD committed Aug 14, 2015
1 parent 2ce1e98 commit 1175c9f
Show file tree
Hide file tree
Showing 29 changed files with 272 additions and 96 deletions.
13 changes: 9 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
Package: tPACE
Type: Package
Title: PACE package for Functional Data Analysis and Empirical Dynamics
URL: https://github.com/hadjipantelis/tPACE
Version: 0.0.0.9000
Date: 2015-05-22
Author: Dai, Hadjipantelis, Hao, Mueller and Wang
Date: 2015-08-14
Author: Xiongtao Dai,
Pantelis Z. Hadjipantelis,
Hao Ji,
Hans-Georg Mueller,
Jane-Ling Wang
Maintainer: Pantelis Z. Hadjipantelis <[email protected]>
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.1), rARPACK, gtools, Hmisc, caret, plot3D, MASS, pracma, numDeriv
Depends: R (>= 3.1.1)
License: BSD_3_clause
LazyData: false
Imports: Rcpp (>= 0.11.5)
Imports: Rcpp (>= 0.11.5), RcppEigen, rARPACK, gtools, Hmisc, caret, plot3D, MASS, pracma, numDeriv
LinkingTo: Rcpp, RcppEigen
Suggests: testthat, rgl
NeedsCompilation: yes
40 changes: 27 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
exportPattern("^[[:alpha:]]+")
useDynLib(tPACE)
importFrom(Rcpp, evalCpp)
importFrom("grDevices", "dev.new")
importFrom("graphics", "abline", "barplot", "grid", "legend", "lines",
"matplot", "par", "plot", "points")
importFrom("stats", "approx", "cov", "dist", "lm", "median", "na.omit",
"predict", "rnorm", "spline", "var")
importFrom("utils", "installed.packages")
# Generated by roxygen2 (4.1.1): do not edit by hand



export(FPCA)
S3method(fitted, FPCA)
S3method(print,FPCA)
export(CheckData)
export(CheckOptions)
export(FPCA)
export(FPCAder)
export(createCorrPlot)
export(createDesignPlot)
export(createDiagnosticsPlot)
export(createScreePlot)
export(makePACEinputs)
export(sparsify)
export(wiener)
import(Hmisc)
import(MASS)
import(Rcpp)
import(RcppEigen)
import(caret)
import(gtools)
import(plot3D)
import(rARPACK)
importFrom(numDeriv,grad)
importFrom(pracma,meshgrid)
importFrom(pracma,midpoint)
importFrom(pracma,mod)
importFrom(pracma,ones)
importFrom(pracma,uniq)
useDynLib(tPACE)
3 changes: 3 additions & 0 deletions R/CheckData.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#' Check data format
#'
#' Check the form and basic structure of the functional data 'y' and the recorded times 'tt'.
#'
#' @param y is a n-by-1 list of vectors
#' @param tt is a n-by-1 list of vectors
#' @return logical
#' @examples
#' 1 + 3
#' @export

CheckData = function(y,t){

Expand Down
3 changes: 3 additions & 0 deletions R/CheckOptions.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#' Check option format
#'
#' Check if the options structure is valid and set the ones that are NULL
#'
#' @param n is a total number of sample curves
#' @param p is an initialized option list
#' @return logical
#' @examples
#' 1 + 3
#' @export

CheckOptions = function(t,optns,n){

Expand Down
62 changes: 31 additions & 31 deletions R/CreateOptions.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#' Create the options list used by FPCA
#'
#' @param bwcov : bandwidth value for covariance function; positive numeric - default: determine automatically based on 'bwcovMethod'
#' @param bwcovMethod : bandwidth choice method for covariance function; 'GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV'')
#' @param bwmu : bandwidth value for mean function is using CV or GCV; positive numeric - default: determine automatically based on 'bwmuMethod'
#' @param bwmuMethod : bandwidth choice method for mean function; 'GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV''
#' @param dataType : do we have sparse or dense functional data; 'Sparse', 'Dense', 'DenseWithMV', 'p>>n' - default: determine automatically based on 'IsRegular'
# '@param diagnosticsPlot : make diagnostics plot (design plot, mean, scree plot and first k (<=3) eigenfunctions); logical - default: FALSE}
#' @param error : assume measurement error in the dataset; logical - default: TRUE
#' @param FVEthreshold : Fraction-of-Variance-Explained threshold used during the SVD of the fitted covar. function; numeric (0,1] - default: 0.9999
#' @param kernel : smoothing kernel choice, common for mu and covariance; "rect", "gauss", "epan", "gausvar", "quar" - default: "epan" for dense data else "gauss"
#' @param methodCov : method to estimate covariance; 'PACE','RARE','CrossSectional' - automatically determined, user input ignored
#' @param methodMu : method to estimate mu; 'PACE','RARE','CrossSectional' - automatically determined, user input ignored
#' @param maxK : maximum number of principal components to consider; positive integer - default: min(20, N-1), N : # of curves
#' @param methodXi : method to estimate the PC scores; 'CE', 'IN' - default: 'CE'
#' @param ntest1 : number of curves used for CV when choosing bandwidth; [1,N] - default: min(30, N-1), N : # of curves
#' @param nRegGrid : number of support points in each direction of covariance surface; numeric - default: 51
#' @param numBins : number of bins to bin the data into; positive integer > 10, default: NULL
#' @param selectionMethod : the method of choosing the number of principal components K; 'FVE','AIC','BIC' : default 'FVE' - only 'FVE' avaiable now/ default 'FVE')
#' @param shrink : apply shrinkage to estimates of random coefficients (dense data only); logical - default: FALSE
#' @param outPercent : 2-element vector in [0,1] indicating the outPercent data in the boundary - default (0,1)
#' @param rho : truncation threshold for the iterative residual. 'cv': choose rho by leave-one-observation out cross-validation; 'no': use the iterative sigma2 estimate - default "cv".
#' @param rotationCut : 2-element vector in [0,1] indicating the percent of data truncated during sigma^2 estimation; default (0.25, 0.75))
#' @param useBinnedData : 'FORCE' (Enforce the # of bins), 'AUTO' (Select the # of bins automatically), 'OFF' (Do not bin) - default: 'AUTO'
#' @param useBins: testing purpose: whether to bin the same observed time points when 2D smoothing; logical - default: FALSE
#' @param userCov : user-defined smoothed covariance function; numerical matrix - default: NULL
#' @param userMu : user-defined smoothed mean function; numerical vector - default: NULL
#' @param verbose : display diagnostic messages; logical - default: FALSE
#' @return an option list
#' @examples
#' optLst = CreateOptions(kernel='rect'); # Create options list with rectangular kernel
# #' Create the options list used by FPCA
# #'
# #' @param bwcov : bandwidth value for covariance function; positive numeric - default: determine automatically based on 'bwcovMethod'
# #' @param bwcovMethod : bandwidth choice method for covariance function; 'GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV'')
# #' @param bwmu : bandwidth value for mean function is using CV or GCV; positive numeric - default: determine automatically based on 'bwmuMethod'
# #' @param bwmuMethod : bandwidth choice method for mean function; 'GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV''
# #' @param dataType : do we have sparse or dense functional data; 'Sparse', 'Dense', 'DenseWithMV', 'p>>n' - default: determine automatically based on 'IsRegular'
# # '@param diagnosticsPlot : make diagnostics plot (design plot, mean, scree plot and first k (<=3) eigenfunctions); logical - default: FALSE}
# #' @param error : assume measurement error in the dataset; logical - default: TRUE
# #' @param FVEthreshold : Fraction-of-Variance-Explained threshold used during the SVD of the fitted covar. function; numeric (0,1] - default: 0.9999
# #' @param kernel : smoothing kernel choice, common for mu and covariance; "rect", "gauss", "epan", "gausvar", "quar" - default: "epan" for dense data else "gauss"
# #' @param methodCov : method to estimate covariance; 'PACE','RARE','CrossSectional' - automatically determined, user input ignored
# #' @param methodMu : method to estimate mu; 'PACE','RARE','CrossSectional' - automatically determined, user input ignored
# #' @param maxK : maximum number of principal components to consider; positive integer - default: min(20, N-1), N : # of curves
# #' @param methodXi : method to estimate the PC scores; 'CE', 'IN' - default: 'CE'
# #' @param ntest1 : number of curves used for CV when choosing bandwidth; [1,N] - default: min(30, N-1), N : # of curves
# #' @param nRegGrid : number of support points in each direction of covariance surface; numeric - default: 51
# #' @param numBins : number of bins to bin the data into; positive integer > 10, default: NULL
# #' @param selectionMethod : the method of choosing the number of principal components K; 'FVE','AIC','BIC' : default 'FVE' - only 'FVE' avaiable now/ default 'FVE')
# #' @param shrink : apply shrinkage to estimates of random coefficients (dense data only); logical - default: FALSE
# #' @param outPercent : 2-element vector in [0,1] indicating the outPercent data in the boundary - default (0,1)
# #' @param rho : truncation threshold for the iterative residual. 'cv': choose rho by leave-one-observation out cross-validation; 'no': use the iterative sigma2 estimate - default "cv".
# #' @param rotationCut : 2-element vector in [0,1] indicating the percent of data truncated during sigma^2 estimation; default (0.25, 0.75))
# #' @param useBinnedData : 'FORCE' (Enforce the # of bins), 'AUTO' (Select the # of bins automatically), 'OFF' (Do not bin) - default: 'AUTO'
# #' @param useBins: testing purpose: whether to bin the same observed time points when 2D smoothing; logical - default: FALSE
# #' @param userCov : user-defined smoothed covariance function; numerical matrix - default: NULL
# #' @param userMu : user-defined smoothed mean function; numerical vector - default: NULL
# #' @param verbose : display diagnostic messages; logical - default: FALSE
# #' @return an option list
# #' @examples
# #' optLst = CreateOptions(kernel='rect'); # Create options list with rectangular kernel



Expand Down
5 changes: 3 additions & 2 deletions R/FPCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@
#' res <- FPCA(sampWiener$yList, sampWiener$tList, list(dataType='Sparse', error=FALSE, kernel='epan', verbose=TRUE))
#' createCorrPlot(res, 'Fitted')
#' @references
#' \cite{Yao, Fang, Hans-Georg Müller, and Jane-Ling Wang. "Functional data analysis for sparse longitudinal data." Journal of the American Statistical Association 100, no. 470 (2005): 577-590. (Sparse data FPCA)}
#' \cite{Yao, Fang, Hans-Georg Mueller, and Jane-Ling Wang. "Functional data analysis for sparse longitudinal data." Journal of the American Statistical Association 100, no. 470 (2005): 577-590. (Sparse data FPCA)}
#'
#' \cite{Liu, Bitao, and Hans-Georg Müller. "Estimating derivatives for samples of sparsely observed functions, with application to online auction dynamics." Journal of the American Statistical Association 104, no. 486 (2009): 704-717. (Sparse data FPCA)}
#' \cite{Liu, Bitao, and Hans-Georg Mueller. "Estimating derivatives for samples of sparsely observed functions, with application to online auction dynamics." Journal of the American Statistical Association 104, no. 486 (2009): 704-717. (Sparse data FPCA)}
#'
#' \cite{Castro, P. E., W. H. Lawton, and E. A. Sylvestre. "Principal modes of variation for processes with continuous sample curves." Technometrics 28, no. 4 (1986): 329-337. (Dense data FPCA)}
#' @export

FPCA = function(y, t, optns = list()){

Expand Down
3 changes: 2 additions & 1 deletion R/FPCAder.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' res <- FPCA(sampWiener$yList, sampWiener$tList, list(dataType='Sparse', error=FALSE, kernel='epan', verbose=TRUE))
#' resder <- FPCAder(res)
#' @references
#' \cite{Liu, Bitao, and Hans-Georg Müller. "Estimating derivatives for samples of sparsely observed functions, with application to online auction dynamics." Journal of the American Statistical Association 104, no. 486 (2009): 704-717. (Sparse data FPCA)}
#' \cite{Liu, Bitao, and Hans-Georg Mueller. "Estimating derivatives for samples of sparsely observed functions, with application to online auction dynamics." Journal of the American Statistical Association 104, no. 486 (2009): 704-717. (Sparse data FPCA)}
#' @export


FPCAder <- function (fpcaObj, ...) {
Expand Down
2 changes: 2 additions & 0 deletions R/TruncateObs.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: Roxygen documentation

TruncateObs <- function(y, t, obsGrid, buff=.Machine$double.eps * max(abs(obsGrid)) * 3) {

tmpInd <- mapply(function(yVec, tVec) {
Expand Down
2 changes: 2 additions & 0 deletions R/createCorrPlot.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: Roxygen documentation
#' @export
# This function creates the covariance surface plot based on the
# results from FPCA() or FPCder()
######
Expand Down
4 changes: 4 additions & 0 deletions R/createDesignPlot.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO: Roxygen documentation
#' @export


# This function creates the design plot of the data
######
# Input:
Expand Down
1 change: 1 addition & 0 deletions R/createDiagnosticsPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' sampWiener <- sparsify(sampWiener, pts, 10)
#' res <- FPCA(sampWiener$yList, sampWiener$tList, list(dataType='Sparse', error=FALSE, kernel='epan', verbose=TRUE))
#' createDiagnosticsPlot(sampWiener$tList, res)
#' @export

createDiagnosticsPlot <-function(t, ret, openNewDev = TRUE){
if(openNewDev){
Expand Down
4 changes: 4 additions & 0 deletions R/createScreePlot.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO: Roxygen documentation
#' @export



createScreePlot <-function(ys){

Expand Down
2 changes: 2 additions & 0 deletions R/fitted.FPCA.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: Roxygen documentation

fitted.FPCA <- function (object, objectDer = NULL, ...) {
# Combine the zero-meaned fitted values (ZMFV) and the interpolated mean (IM)
# to get the final estimates
Expand Down
3 changes: 3 additions & 0 deletions R/makePACEinputs.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#' Format FPCA input
#'
#' Turn vector inputs to the list so they can be used in FPCA
#'
#' @param IDs : n-by-1 vector of subject IDs
#' @param tVec : n-by-1 vector of measurement times
#' @param yVec : n-by-1 vector of measurements from the variable of interest
#' @return L : list containing 3 lists each of length 'm', 'm' being the number of unique subject IDs
#' @export

makePACEinputs <- function(IDs, tVec, yVec){

Expand Down
36 changes: 36 additions & 0 deletions R/pkgname.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' PACE: Principal Analysis by Conditional Expectation
#'
#' PACE package for Functional Data Analysis and Empirical Dynamics.
#'
#' 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.
#'
#' Functions on creating, moving, plotting and summarizing BML models are
#' provided in this package. For a list of functions provided in this package
#' see \code{help(package='A4')}.
#'
#' @author
#' Xiongtao Dai \email{dai@@ucdavis.edu},
#' Pantelis Z. Hadjipantelis \email{pantelis@@ucdavis.edu},
#' Hao Ji \email{haoji@@ucdavis.edu}
#'
#' Maintainer: Pantelis Z. Hadjipantelis \email{pantelis@@ucdavis.edu}
#'
#' @docType package
#' @name tPACE
#' @useDynLib tPACE
#' @import rARPACK gtools Hmisc caret plot3D MASS Rcpp RcppEigen
#' @importFrom numDeriv grad
#' @importFrom pracma meshgrid midpoint mod ones uniq
NULL
8 changes: 7 additions & 1 deletion R/print.FPCA.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
print.FPCA <- function(x){
#' Print an FPCA object
#'
#' @param x An FPCA object.
#' @param ... Not used.
#'
#' @export
print.FPCA <- function(x, ...){
obj = x;
cat("Functional Principal Components Object for", tolower(obj$optns$dataType), "data.\n\n")
cat("The optimal number of components selected is:", length(obj$lambda),"and \nthe first k (<=3) corresponding eigenvalues are: ");
Expand Down
2 changes: 2 additions & 0 deletions R/sparsify.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: roxygen comments
#' @export
# sparsify samp
# samp: a matrix of samples, with rows containing the samples
# pts: a vector of grid points, should be from 0 to 1
Expand Down
3 changes: 3 additions & 0 deletions R/wiener.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# TODO: Roxygen documentation
#' @export

# A test on standard Wiener process (brownian motion)
# n: sample sizeDiss
# pts: a vector of grid points, should be from 0 to 1
Expand Down
4 changes: 2 additions & 2 deletions man/CheckData.Rd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
% Generated by roxygen2 (4.1.1.9000): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/CheckData.R
\name{CheckData}
\alias{CheckData}
\title{Check the form and basic structure of the functional data 'y' and the recorded times 'tt'.}
\title{Check data format}
\usage{
CheckData(y, t)
}
Expand Down
4 changes: 2 additions & 2 deletions man/CheckOptions.Rd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
% Generated by roxygen2 (4.1.1.9000): do not edit by hand
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/CheckOptions.R
\name{CheckOptions}
\alias{CheckOptions}
\title{Check if the options structure is valid and set the ones that are NULL}
\title{Check option format}
\usage{
CheckOptions(t, optns, n)
}
Expand Down
Loading

0 comments on commit 1175c9f

Please sign in to comment.