Skip to content

Commit

Permalink
Writing up the doc for CreateOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hadjipantelis committed Jul 6, 2015
1 parent 34bda7d commit 8215857
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 48 deletions.
10 changes: 5 additions & 5 deletions R/CheckOptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CheckOptions = function(t,optns,n){

bwmu = optns$bwmu; bwmuGcv = optns$bwmuGcv;
bwuserCov = optns$bwuserCov; bwuserCovGcv = optns$bwuserCovGcv;
ntest1 = optns$ntest1; ngrid1 = optns$ngrid1;
ntest1 = optns$ntest1; # ngrid1 = optns$ngrid1;
selectionMethod = optns$selectionMethod; FVEthreshold = optns$FVEthreshold;
maxK = optns$maxK;
dataType = optns$dataType; error = optns$error;
Expand Down Expand Up @@ -54,11 +54,11 @@ CheckOptions = function(t,optns,n){
cat("Error: FPCA is aborted because the argument: ntest1 is invalid!\n");
return(TRUE);
}
if( !( (length(optns$ngrid1)==1) && is.numeric(optns$ngrid1) && (1<=optns$ngrid1) && (optns$ngrid1<90) ) ){
# if( !( (length(optns$ngrid1)==1) && is.numeric(optns$ngrid1) && (1<=optns$ngrid1) && (optns$ngrid1<90) ) ){
# number of support points for the covariance surface
cat("Error: FPCA is aborted because the argument: ngrid1 is invalid!\n");
return(TRUE);
}
# cat("Error: FPCA is aborted because the argument: ngrid1 is invalid!\n");
# return(TRUE);
# }
if( !(any(optns$selectionMethod == c('FVE','AIC','BIC')))){
if ( !( is.numeric(optns$selectionMethod) && (length(optns$selectionMethod)==1) && (1>=optns$selectionMethod) && (optns$selectionMethod<n) )){
# the method of choosing the number of principal components K
Expand Down
42 changes: 39 additions & 3 deletions R/CreateOptions.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
## To be merged into FPCA.R
#' Create the options list used by FPCA
#'
#' @param bwcov : bandwidth value for covariance function (positive numeric - default: determine automatically based on 'bwcovGcv')
#' @param bwcovGcv : bandwidth choice method for covariance function ('GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV'')
#' @param bwmu : bandwidth choice for mean function is using CV or GCV (positive numeric - default: determine automatically based on 'bwmuGcv')
#' @param bwmuGcv : bandwidth choice method for mean function ('GMeanAndGCV','CV','GCV - default: 'GMeanAndGCV'')
#' @param corrPlot : make correlation plot (logical - default: FALSE)
#' @param corrPlotType: which type of correlation plot to show ('Fitted', 'Raw', 'Smoothed' - default : 'Fitted')
#' @param dataType : do we have sparse or dense functional data ('Sparse', 'Dense', 'DenseWithMV', 'p>>n' - default : determine automatically based on 'IsRegular')
#' @param designPlot : make design plot (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 method : method to estimate the PC scores. Either 'CE' (default) or 'IN'
#' @param newdata : new data points to estimate (numeric - default : NULL )
#' @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 (default : NULL)
#' @param screePlot : make scree plot (logical - default : FALSE )
#' @param selectionMethod : the method of choosing the number of principal components K ('FVE','AIC','BIC' : default 'FVE' - only 'FVE' avaiable now)
#' @param shrink : apply shrinkage to estimates of random coefficients (dataType data only)
#' @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. Either 'cv': choose rho by leave-one-observation out cross-validation; 'no': for not using the iterative sigma2 estimate, or a numerical value.
#' @param rotationCut : 2-element vector in [0,1] indicating the percent of data truncated during sigma^2 estimation (default c(1/4,3/4))
#' @param useBinnedData : 'FORCE' (Enforce the # of bins), 'AUTO' (Select the # of bins automatically), 'OFF' (Do not bin)
#' @param useBins: testing purpose: whether to bin the same observed time points when 2D smoothing
#' @param userCov : user-defined smoothed covariance function
#' @param userMu : user-defined smoothed mean function
#' @param verbose : display diagnostic messages (default = FALSE)
#' @return an option list
#' @examples
#' optLst = CreateOptions(kernel='rect'); # Create options list with rectangular kernel



CreateOptions = function(bwmu = NULL, bwmuGcv = NULL, bwuserCov = NULL, bwuserCovGcv = NULL,
ntest1 = NULL, ngrid1 = NULL, selectionMethod = NULL, FVEthreshold = NULL,
ntest1 = NULL, selectionMethod = NULL, FVEthreshold = NULL,
maxK = NULL, dataType = NULL, error = NULL, nRegGrid = NULL,
method = NULL, shrink = NULL, newdata = NULL, kernel = NULL,
numBins = NULL, yname = NULL, screePlot = NULL, designPlot = NULL,
corrPlot = NULL, corrPlotType =NULL, rho = NULL, verbose = NULL, userMu = NULL, userCov = NULL, methodCov = NULL,
methodMu = NULL, outPercent = NULL, useBinnedData = NULL, rotationCut = NULL){

return( list(bwmu = bwmu, bwmuGcv = bwmuGcv, bwuserCov = bwuserCov, bwuserCovGcv = bwuserCovGcv,
ntest1 = ntest1, ngrid1 = ngrid1, selectionMethod = selectionMethod, FVEthreshold = FVEthreshold,
ntest1 = ntest1, selectionMethod = selectionMethod, FVEthreshold = FVEthreshold,
maxK = maxK, dataType = dataType, error = error, nRegGrid = nRegGrid,
method = method, shrink = shrink, newdata = newdata, kernel = kernel, corrPlot = corrPlot, corrPlotType = corrPlotType,
numBins = numBins, yname = yname, screePlot = screePlot, designPlot = designPlot, rho = rho, rotationCut = rotationCut,
Expand Down
50 changes: 11 additions & 39 deletions R/SetOptions.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,12 @@
#' Set the PCA option list
#'
#' @param bwmu : bandwidth choice for mean function is using CV or GCV
#' @param bwmuGcv : bandwidth choice method for mean function is GCV if bwmu = 0
#' @param bwcov : bandwidth choice for covariance function is CV or GCV
#' @param bwcovGcv : bandwidth choice method for covariance function is GCV if bwuserCov = 0
#' @param ntest1 : number of curves used for CV when choosing bandwidth
#' @param ngrid1 : number of support points for the covariance surface
#' @param selectionMethod : the method of choosing the number of principal components K
#' @param FVEthreshold : Fraction-of-Variance-Explained
#' @param maxK : maximum number of principal components to consider
#' @param dataType : do we have dataType or sparse functional data ('Sparse', 'Dense', 'DenseWithMV', 'p>>n')
#' @param error : having measurement error
#' @param nRegGrid : number of support points in each direction of covariance surface
#' @param method : method to estimate the PC scores. Either 'CE' (default) or 'IN'
#' @param shrink : apply shrinkage to estimates of random coefficients (dataType data only)
#' @param newdata : new data points to estimate
#' @param kernel : smoothing kernel choice
#' @param numBins : number of bins
#' @param useBins: testing purpose: whether to bin the same observed time points when 2D smoothing
#' @param screePlot : make scree plot
#' @param designPlot : make design plot
#' @param corrPlotType: which correlation plot ('Fitted', 'Raw', 'Smoothed')
#' @param corrPlot : make correlation plot
#' @param rho : truncation threshold for the iterative residual. Either 'cv': choose rho by leave-one-observation out cross-validation; 'no': for not using the iterative sigma2 estimate, or a numerica value.
#' @param verbose : display diagnostic messages (default = FALSE)
#' @param userMu : user-defined smoothed mean function
#' @param userCov : user-defined smoothed covariance function
#' @param methodMu : method to estimate mu ('PACE','RARE','CrossSectional')
#' @param methodCov : method to estimate covariance ('PACE','RARE','CrossSectional')
#' @param outPercent : 2-element vector in [0,1] indicating the outPercent data in the boundary default(0,1)
#' @param rotationCut : 2-element vector in [0,1] indicating the percent of data truncated during sigma^2 estimation (default c(1/4,3/4))
#' @param useBinnedData : 'FORCE' (Enforce the # of bins), 'AUTO' (Select the # of bins automatically), 'OFF' (Do not bin)
#' @return an option list
#' @examples
#' 1 + 3
#' See '?CreateOptions for more details

SetOptions = function(y, t, optns){

bwmu =optns[['bwmu']]; bwmuGcv =optns[['bwmuGcv']];
bwuserCov =optns[['bwuserCov']]; bwuserCovGcv =optns[['bwuserCovGcv']];
ntest1 =optns[['ntest1']]; ngrid1 =optns[['ngrid1']];
ntest1 =optns[['ntest1']]; # ngrid1 =optns[['ngrid1']];
selectionMethod =optns[['selectionMethod']]; FVEthreshold =optns[['FVEthreshold']];
maxK =optns[['maxK']];
dataType =optns[['dataType']]; error =optns[['error']];
Expand Down Expand Up @@ -69,9 +36,9 @@ SetOptions = function(y, t, optns){
if(is.null(ntest1)){ # number of curves used for CV when choosing bandwidth
ntest1 = min(30, length(y)-1);
}
if(is.null(ngrid1)){ # number of support points for the covariance surface
ngrid1 = 30;
}
#if(is.null(ngrid1)){ # number of support points for the covariance surface
# ngrid1 = 30;
#}
if(is.null(selectionMethod)){ # the method of choosing the number of principal components K
# TODO : Possibly have user-defined selection methods for the # of FPCs and we keep
# an internal FVE-based method for us
Expand All @@ -97,6 +64,11 @@ SetOptions = function(y, t, optns){
nRegGrid = 51;
}
}
methodNames = c("IN", "CE");
if(!is.null(method) && !(method %in% methodNames)){ # Check suitability of kernel
cat(paste('method', kernel, 'is unrecognizable! Reset to automatic selection now!\n'));
method = NULL;
}
if(is.null(method)){ # method to estimate the PC scores
if(dataType == 'Dense'){
shrink = FALSE;
Expand Down Expand Up @@ -203,7 +175,7 @@ SetOptions = function(y, t, optns){
}

return( list(bwmu = bwmu, bwmuGcv = bwmuGcv, bwuserCov = bwuserCov, bwuserCovGcv = bwuserCovGcv,
ntest1 = ntest1, ngrid1 = ngrid1, selectionMethod = selectionMethod, FVEthreshold = FVEthreshold,
ntest1 = ntest1, selectionMethod = selectionMethod, FVEthreshold = FVEthreshold,
maxK = maxK, dataType = dataType, error = error, nRegGrid = nRegGrid, rotationCut = rotationCut,
method = method, shrink = shrink, newdata = newdata, kernel = kernel, corrPlot = corrPlot, corrPlotType = corrPlotType,
numBins = numBins, useBins = useBins, yname = yname, screePlot = screePlot, designPlot = designPlot, rho = rho,
Expand Down
2 changes: 1 addition & 1 deletion src/Rlwls1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::export]]

Eigen::VectorXd Rlwls1d( const double & bw, const std::string kernel_type, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xin, const Eigen::Map<Eigen::VectorXd> & yin, const Eigen::Map<Eigen::VectorXd> & xout, const int & npoly = 1, const int & nder = 0){
Eigen::VectorXd Rlwls1d( const double & bw, const std::string kernel_type, const Eigen::Map<Eigen::VectorXd> & win, const Eigen::Map<Eigen::VectorXd> & xin, const Eigen::Map<Eigen::VectorXd> & yin, const Eigen::Map<Eigen::VectorXd> & xout, const unsigned int & npoly = 1, const unsigned int & nder = 0){


// Convenient constants
Expand Down

0 comments on commit 8215857

Please sign in to comment.