diff --git a/R/Log_Likelihood.R b/R/Log_Likelihood.R index 6b9fce0..9b66d60 100755 --- a/R/Log_Likelihood.R +++ b/R/Log_Likelihood.R @@ -12,8 +12,7 @@ #' #' @examples #' @noRd -negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, - scaling, nscale) { +negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, scaling, nscale) { parms <- unlog.params(logparms, param.seq, 1) locs.scaled <- vecchia.approx$locsord for (j in 1:nscale) { @@ -141,8 +140,7 @@ mvnegloglik <- function(logparams, vecchia.approx, y, param.seq, P) { ############################################################################## ### Flexible Spatiotemporal Multivariate Matern Negative Loglikelihood Function ########### -mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling, - nscale) { +mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling, nscale) { # Input- # logparams: A numeric vector of length (4*P)+(4*choose(P,2)). # To construct these parameters we unlist a list of the 7 covariance @@ -235,8 +233,7 @@ mvnegloglik.full <- function(logparams, locs, y, param.seq) { } ############################################################################## -create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth, - nugget, R.corr) { +create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth, nugget, R.corr) { # Create the symmetrical marginal+cross-covariance flexible matern from the # given parameters. Output is a list of the 4 Matern parameters as matrices sig2.mat <- diag(marg.var, P, P) @@ -337,8 +334,7 @@ cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) { ############################################################################## ### Create the likelihood initial values ######### -create.initial.values.flex <- function(marg.var, marg.range, marg.smooth, - nugget, R.corr, P) { +create.initial.values.flex <- function(marg.var, marg.range, marg.smooth, nugget, R.corr, P) { # Log-transform the covariance parameters and arrange in the proper order # for the likelihood function logparams.init <- c( diff --git a/R/PrestoGP_CreateU_Multivariate.R b/R/PrestoGP_CreateU_Multivariate.R index c486541..0bdcf24 100755 --- a/R/PrestoGP_CreateU_Multivariate.R +++ b/R/PrestoGP_CreateU_Multivariate.R @@ -66,8 +66,7 @@ max_min_ordering <- function(locs, dist_func) { #' @param dist_func Any distance function with a signature of dist(query_location, locations_matrix) #' #' @return A vector containing the indices of the neighbors -knn_indices <- function(ordered_locs, query, n_neighbors, - dist_func, dist_func_code) { +knn_indices <- function(ordered_locs, query, n_neighbors, dist_func, dist_func_code) { if (dist_func_code == "custom") { dists <- dist_func(query, ordered_locs) dists_order <- order(dists) @@ -92,8 +91,7 @@ knn_indices <- function(ordered_locs, query, n_neighbors, #' #' @return A list containing two matrices, each with one row per location: #' an indices matrix with the indices of nearest neighbors for each location, and a distance matrix with the associated distances -sparseNN <- function(ordered_locs, n_neighbors, - dist_func, dist_func_code, ordered_locs_pred = NULL) { +sparseNN <- function(ordered_locs, n_neighbors, dist_func, dist_func_code, ordered_locs_pred = NULL) { ee <- min(apply(ordered_locs, 2, stats::sd)) n <- nrow(ordered_locs) ordered_locs <- ordered_locs + matrix( @@ -197,9 +195,9 @@ calc.q <- function(nn.obj, firstind.pred) { #' @export vecchia_Mspecify <- function(locs.list, m, locs.list.pred = NULL, - dist.func = NULL, - ordering.pred = c("obspred", "general"), - pred.cond = c("independent", "general")) { + dist.func = NULL, + ordering.pred = c("obspred", "general"), + pred.cond = c("independent", "general")) { ordering.pred <- match.arg(ordering.pred) pred.cond <- match.arg(pred.cond) diff --git a/R/PrestoGP_Model.R b/R/PrestoGP_Model.R index dab605f..62727c0 100755 --- a/R/PrestoGP_Model.R +++ b/R/PrestoGP_Model.R @@ -71,16 +71,16 @@ setGeneric("show_theta", function(object, Y_names) standardGeneric("show_theta") setGeneric( "prestogp_fit", function(model, Y, X, locs, scaling = NULL, apanasovich = FALSE, - covparams = NULL, beta.hat = NULL, tol = 0.999999, max_iters = 100, verbose = FALSE, - optim.method = "Nelder-Mead", optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000), - parallel = FALSE, foldid = NULL) { + covparams = NULL, beta.hat = NULL, tol = 0.999999, max_iters = 100, verbose = FALSE, + optim.method = "Nelder-Mead", optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000), + parallel = FALSE, foldid = NULL) { standardGeneric("prestogp_fit") } ) setGeneric( "prestogp_predict", function(model, X = "matrix", locs = "matrix", m = "numeric", ordering.pred = c("obspred", "general"), - pred.cond = c("independent", "general"), return.values = c("mean", "meanvar")) { + pred.cond = c("independent", "general"), return.values = c("mean", "meanvar")) { standardGeneric("prestogp_predict") } ) @@ -215,10 +215,10 @@ setMethod( setMethod( "prestogp_fit", "PrestoGPModel", function(model, Y, X, locs, scaling = NULL, apanasovich = NULL, - covparams = NULL, beta.hat = NULL, tol = 0.999999, - max_iters = 100, verbose = FALSE, optim.method = "Nelder-Mead", - optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000), - parallel = FALSE, foldid = NULL) { + covparams = NULL, beta.hat = NULL, tol = 0.999999, + max_iters = 100, verbose = FALSE, optim.method = "Nelder-Mead", + optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000), + parallel = FALSE, foldid = NULL) { model <- check_input(model, Y, X, locs) if (!is.null(beta.hat)) { if (!is.vector(beta.hat) | !is.numeric(beta.hat)) { @@ -284,10 +284,7 @@ setMethod( parallel = parallel, foldid = foldid ) - beta.hat <- as.matrix(predict(beta0.glmnet, - type = "coefficients", - s = beta0.glmnet$lambda.1se - )) + beta.hat <- as.matrix(predict(beta0.glmnet, type = "coefficients", s = beta0.glmnet$lambda.1se)) } Y.hat <- beta.hat[1, 1] + model@X_train %*% beta.hat[-1, ] diff --git a/R/PrestoGP_Util_Functions.R b/R/PrestoGP_Util_Functions.R index 3213bb0..8e62898 100644 --- a/R/PrestoGP_Util_Functions.R +++ b/R/PrestoGP_Util_Functions.R @@ -150,7 +150,7 @@ transform_iid <- function(data, vecchia.approx, covparms, nuggets) { # return to original ordering orig.order <- order(U.obj$ord) - transformed.data <- transform.ord[orig.order, ] # TODO: @Eric.Bair is this a required variable? + transformed.data <- transform.ord[orig.order, ] # nolint # TODO: @Eric.Bair is this a required variable? return(transform.ord) } @@ -180,7 +180,7 @@ transform_miid <- function(data, vecchia.approx, params) { # return to original ordering orig.order <- order(U.obj$ord) - transformed.data <- transform.ord[orig.order, ] # TODO: @Eric.Bair is this a required variable? + transformed.data <- transform.ord[orig.order, ] # nolint TODO: @Eric.Bair is this a required variable? return(transform.ord) } diff --git a/R/PrestoGP_Vecchia.R b/R/PrestoGP_Vecchia.R index eda0117..df66061 100755 --- a/R/PrestoGP_Vecchia.R +++ b/R/PrestoGP_Vecchia.R @@ -100,8 +100,8 @@ setMethod("prestogp_predict", "VecchiaModel", } else { warning("Variance estimates do not include model fitting variance and are anticonservative. Use with caution.") # TODO: @Eric.Bair is this a typo/bug? Capital 'V' in Vec.sds but 'vec.sds' in return.list - Vec.sds <- sqrt(pred$var.pred + model@covparams[4]) - return.list <- list(means = Vec.mean, sds = vec.sds) + Vec.sds <- sqrt(pred$var.pred + model@covparams[4]) # nolint + return.list <- list(means = Vec.mean, sds = vec.sds) # nolint } return(return.list)