Skip to content

Commit

Permalink
Pull request #37: Added documentation. Added RandomFields data sets. …
Browse files Browse the repository at this point in the history
…Fixed R CMD issues

Merge in STAT/prestogp from master to to-git

Squashed commit of the following:

commit 7e330f3
Merge: 13a6f44 f49d076
Author: sciome-bot <software.tools@sciome.com>
Date:   Wed Feb 7 23:25:05 2024 -0500

    Merge branch 'master' of ssh://sciome-bot/stat/prestogp

commit f49d076
Merge: 439790c 59baf72
Author: Eric Bair <eric.bair@sciome.com>
Date:   Wed Feb 7 23:19:54 2024 -0500

    Pull request #35: Eb dev

    Merge in STAT/prestogp from eb-dev to master

    * commit '59baf720737abe59a04c98705c950ef1c7b63321':
      Fixed some documentation issues
      Removed C++11 compiler flag
      Added RandomFields data sets to PrestoGP
      Added knitr to Suggests in DESCRIPTION
      Documentation, R-cmd-check fixes, binomial regression

commit 59baf72
Author: Eric Bair <eric.bair@sciome.com>
Date:   Tue Feb 6 17:49:48 2024 -0500

    Fixed some documentation issues

commit d857d8b
Author: Eric Bair <eric.bair@sciome.com>
Date:   Thu Feb 1 02:16:44 2024 -0500

    Removed C++11 compiler flag

commit 662907d
Author: Eric Bair <eric.bair@sciome.com>
Date:   Wed Jan 31 15:36:37 2024 -0500

    Added RandomFields data sets to PrestoGP

commit cf2aadb
Author: Eric Bair <eric.bair@sciome.com>
Date:   Wed Jan 31 13:40:24 2024 -0500

    Added knitr to Suggests in DESCRIPTION

commit ef5f2c9
Author: Eric Bair <eric.bair@sciome.com>
Date:   Wed Jan 31 01:31:53 2024 -0500

    Documentation, R-cmd-check fixes, binomial regression

commit 13a6f44
Merge: 439790c 8ffb20b
Author: sciome-bot <software.tools@sciome.com>
Date:   Sun Jan 14 11:46:17 2024 -0500

    Merge branch 'main-sciome' of sciome-bot-git:Spatiotemporal-Exposures-and-Toxicology/PrestoGP

commit 439790c
Merge: f4af0d1 56f881f
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sun Jan 14 10:58:49 2024 -0500

    Pull request #32: Fixed some testthat issues

    Merge in STAT/prestogp from eb-dev to master

    * commit '56f881f96a0e55e60bca3c8a840ec31291665594':
      Fixed some testthat issues

commit 56f881f
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sat Jan 13 14:05:12 2024 -0500

    Fixed some testthat issues

commit f4af0d1
Merge: db6cd4f ee193de
Author: sciome-bot <software.tools@sciome.com>
Date:   Sat Jan 13 12:37:28 2024 -0500

    Merge branch 'main-sciome' of sciome-bot-git:Spatiotemporal-Exposures-and-Toxicology/PrestoGP

commit db6cd4f
Merge: 55607e2 7da2588
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sat Jan 13 12:11:56 2024 -0500

    Pull request #29: Fixed some bugs caused by the linter

    Merge in STAT/prestogp from eb-dev to master

    * commit '7da2588abba4491c1ff490de95e834d00f5df88e':
      Fixed some bugs caused by the linter

commit 7da2588
Author: Eric Bair <eric.bair@sciome.com>
Date:   Sat Jan 13 01:37:58 2024 -0500

    Fixed some bugs caused by the linter

commit 55607e2
Merge: c7ed481 81b675d
Author: Shail Choksi <shail.choksi@sciome.com>
Date:   Fri Jan 12 19:37:55 2024 -0500

    Pull request #28: Final linting fixes

    Merge in STAT/prestogp from build-workflow to master

    * commit '81b675dda9b57f2a362c34876364adf5bcf45560':
      Fix remaining linting issues
      Fix all indentation errors
      Add indentation_linter configuration to lintr config file

commit 81b675d
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 19:36:05 2024 -0500

    Fix remaining linting issues

commit 06673a4
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 19:23:11 2024 -0500

    Fix all indentation errors

commit c7ed481
Merge: 723c3eb 7bcfa1a
Author: Shail Choksi <shail.choksi@sciome.com>
Date:   Fri Jan 12 19:02:59 2024 -0500

    Pull request #27: Lintr fixes. Added release and sanitizer actions

    Merge in STAT/prestogp from build-workflow to master

    * commit '7bcfa1aca78cc6b994cc0227c083357c58d50ca0': (21 commits)
      Add R_LINTR_LINTER_FILE to lint action to point to global .lintr file
      More lintr fixes for 1:length, 1:nrow and line length. Disabled object_length_linter
      WIP: Fix linter warnings for 1:nrow, 1:ncol and 1:length. Increase line length to 160 chars
      Don't build vignettes during the release action
      Move release action file to correct directory
      Add release action
      Reorder imports in RcppExports file
      Add missing dependency in Namespace/Description
      Remove unneeded exports from NAMESPACE
      Add missing comma in Imports section of DESCRIPTION
      Add missing comma in imports section of DESCRIPTION
      Rerun auto-formatter
      WIP - linting
      Add ignore rules for .lintr and .github for R build
      remove linter options from lint action as we have added .lintr project file. Fix all vector_logic_linter warnings
      Remove line length linter to see the remaining errors/warnings
      workaround for lintr bug: REditorSupport/languageserver#89
      Run auto-lint on vscode
      enable linting on build-workflow
      Add missing imports in DESCRIPTION
      ...

commit 29d82cd
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 18:40:17 2024 -0500

    Add indentation_linter configuration to lintr config file

commit 7bcfa1a
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 18:16:01 2024 -0500

    Add R_LINTR_LINTER_FILE to lint action to point to global .lintr file

commit b6df473
Author: sciome-bot <software.tools@sciome.com>
Date:   Fri Jan 12 17:54:50 2024 -0500

    More lintr fixes for 1:length, 1:nrow and line length. Disabled object_length_linter

... and 21 more commits
  • Loading branch information
shail-choksi committed Feb 8, 2024
1 parent 8ffb20b commit 076c0a1
Show file tree
Hide file tree
Showing 62 changed files with 1,937 additions and 77,559 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ code/mitchell_tests/
# Insang's negative value exploration script
tools/negative_exploration

# data files
data

# Automatic Emacs backup files
**/*~

Expand Down
25 changes: 10 additions & 15 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: PrestoGP
Type: Package
Title: Penalized Regression for Spatio-Temporal Outcomes via Gaussian Processes
Version: 0.2.0.9023
Version: 0.2.0.9025
Authors@R: c(
person(given = "Eric",
family = "Bair",
Expand All @@ -26,33 +26,24 @@ LinkingTo:
Rcpp, RcppArmadillo
Imports:
GPvecchia,
Matrix,
fields,
ncvreg,
readxl,
scoringRules,
MASS,
aod,
knitr,
dplyr,
glmnet,
gtools,
geoR,
RANN,
stats,
methods,
foreach,
rlang,
mvtnorm,
spam,
psych,
doParallel,
covr,
mvtnorm
MASS,
Matrix,
methods
License: GPL-3
Encoding: UTF-8
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Collate:
'Log_Likelihood.R'
'PrestoGP-package.R'
Expand All @@ -64,9 +55,13 @@ Collate:
'PrestoGP_Util_Functions.R'
'RcppExports.R'
'Visualization.R'
'package.R'
'datadocs.R'
'utils-tidy-eval.R'
Suggests:
roxygen2,
covr,
knitr,
GpGp,
geoR,
testthat (>= 3.0.0)
Config/testthat/edition: 3
15 changes: 5 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,26 @@
export(":=")
export(.data)
export(FullModel)
export(Kr_pred)
export(MultivariateVecchiaModel)
export(PrestoGPModel)
export(ST_Krig_Param_Avg)
export(VecchiaModel)
export(as_label)
export(as_name)
export(create.param.sequence)
export(createUMultivariate)
export(enquo)
export(enquos)
export(negloglik.full)
export(negloglik_full_ST)
export(negloglik_vecchia)
export(negloglik_vecchia_ST)
export(max_min_ordering)
export(prestogp_predict)
export(vecchia_Mlikelihood)
export(vecchia_Mprediction)
export(vecchia_Mspecify)
exportMethods(prestogp_fit)
exportMethods(prestogp_predict)
import(GPvecchia)
import(MASS)
import(Matrix)
import(fields)
import(glmnet)
import(ncvreg)
import(readxl)
import(scoringRules)
importFrom(aod,wald.test)
importFrom(dplyr,"%>%")
importFrom(foreach,"%dopar%")
Expand All @@ -46,4 +40,5 @@ importFrom(stats,coef)
importFrom(stats,optim)
importFrom(stats,predict)
importFrom(stats,var)
importFrom(utils,getFromNamespace)
useDynLib(PrestoGP)
141 changes: 72 additions & 69 deletions R/Log_Likelihood.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#' negloglik_vecchia_ST
#'
#' Spatiotemporal Vecchia negative loglikelihood.
#'
#' @param logparms
#' @param locs
#' @param res
#' @param vecchia.approx
#'
#' @return
#' @export
#'
#' @examples
#' @noRd
# Spatiotemporal Vecchia negative log likelihood.

negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, scaling, nscale) {
parms <- unlog.params(logparms, param.seq, 1)
locs.scaled <- vecchia.approx$locsord
Expand All @@ -29,20 +17,8 @@ negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, scali
)
}

#' negloglik_vecchia
#'
#' Spatial Vecchia negative loglikelihood.
#'
#' @param logparms
#' @param locs
#' @param res
#' @param vecchia.approx
#'
#' @return
#' @export
#'
#' @examples
#' @noRd
# Spatial Vecchia negative log likelihood.

negloglik_vecchia <- function(logparms, res, vecchia.approx, param.seq) {
parms <- unlog.params(logparms, param.seq, 1)
-vecchia_likelihood(
Expand All @@ -51,20 +27,8 @@ negloglik_vecchia <- function(logparms, res, vecchia.approx, param.seq) {
)
}

#' negloglik_full_ST
#'
#' Spatiotemporal Full Kriging negative loglikelihood.
#'
#' @param logparms
#' @param locs
#' @param y
#' @param N
#'
#' @return
#' @export
#'
#' @examples
#' @noRd
# Spatiotemporal Full Kriging negative log likelihood.

negloglik_full_ST <- function(logparms, locs, y, param.seq, scaling, nscale) {
parms <- unlog.params(logparms, param.seq, 1)
locs.scaled <- locs
Expand All @@ -82,23 +46,10 @@ negloglik_full_ST <- function(logparms, locs, y, param.seq, scaling, nscale) {
return(-1 * mvtnorm::dmvnorm(y, rep(0, N), cov.mat, log = TRUE))
}

#' negloglik.full
#'
#' Spatial Full Kriging negative loglikelihood
#'
#' @param logparms
#' @param locs
#' @param y
#' @param N
#'
#' @return
#' @export
#'
#' @examples
#' @noRd
# Spatial Full Kriging negative log likelihood

negloglik.full <- function(logparams, d, y, param.seq) {
params <- unlog.params(logparams, param.seq, 1)
# d <- fields::rdist(locs)
N <- nrow(d)
cov.mat <- params[1] * fields::Matern(d,
range = params[2],
Expand All @@ -108,6 +59,60 @@ negloglik.full <- function(logparams, d, y, param.seq) {
return(-1 * mvtnorm::dmvnorm(y, rep(0, N), cov.mat, log = TRUE))
}

#' Evaluation of the multivariate Vecchia likelihood
#'
#' This function is used to evaluate the multivariate Vecchia likelihood.
#'
#' @param z The observed data.
#' @param vecchia.approx A Vecchia object returned by
#' \code{\link{vecchia_Mspecify}}.
#' @param covparams Vector of covariance parameters. See
#' \code{\link{create.param.sequence}} or the examples below for details
#' about the format of this vector.
#'
#' @return The log likelihood implied by the multivariate Vecchia
#' approximation.
#'
#' @seealso \code{\link[GPvecchia]{vecchia_likelihood}},
#' \code{\link{vecchia_Mspecify}}, \code{\link{create.param.sequence}}
#'
#' @references
#' \itemize{
#' \item Katzfuss, M., and Guinness, J. "A general framework for Vecchia
#' approximations of Gaussian processes", Statistical Science (2021)
#' 36(1):124-141.
#' }
#'
#' @export
#' @examples
#' data(soil)
#' soil <- soil[!is.na(soil[,5]),] # remove rows with NA's
#' locs <- as.matrix(soil[,1:2])
#' locsm <- list()
#' locsm[[1]] <- locsm[[2]] <- locs
#' soil.va <- vecchia_Mspecify(locsm, m=10)
#'
#' pseq <- create.param.sequence(2)
#' # Initialize the vector of covariance parameters
#' params <- rep(NA, pseq[5,2])
#' # Sigma parameters:
#' params[pseq[1,1]:pseq[1,2]] <- c(100, 80)
#' # Scale parameters:
#' params[pseq[2,1]:pseq[2,2]] <- c(60, 50)
#' # Smoothness parameters:
#' params[pseq[3,1]:pseq[3,2]] <- c(0.5, 0.5)
#' # Nuggets:
#' params[pseq[4,1]:pseq[4,2]] <- c(30, 30)
#' # Correlation:
#' params[pseq[5,1]:pseq[5,2]] <- -0.9
#'
#' vecchia_Mlikelihood(rnorm(nrow(locs)), soil.va, params)
vecchia_Mlikelihood <- function(z, vecchia.approx, covparams) {
U.obj <- createUMultivariate(vecchia.approx, covparams)
vecchia_likelihood_U <- getFromNamespace("vecchia_likelihood_U", "GPvecchia")
vecchia_likelihood_U(z, U.obj)
}


##############################################################################
### Flexible Multivariate Matern Negative Loglikelihood Function ###########
Expand All @@ -133,8 +138,7 @@ mvnegloglik <- function(logparams, vecchia.approx, y, param.seq, P) {
# P <- length(y)
# transform the postively constrained parameters from log-space to normal-space
params <- unlog.params(logparams, param.seq, P)
U.obj <- createUMultivariate(vecchia.approx, params)
-1 * GPvecchia:::vecchia_likelihood_U(y, U.obj)
-1 * vecchia_Mlikelihood(y, vecchia.approx, params)
}

##############################################################################
Expand Down Expand Up @@ -171,12 +175,11 @@ mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling,
}
vecchia.approx$locsord <- locs.scaled

U.obj <- createUMultivariate(vecchia.approx, c(
-1 * vecchia_Mlikelihood(y, vecchia.approx, c(
params[1:param.seq[1, 2]],
rep(1, param.seq[2, 2] - param.seq[2, 1] + 1),
params[param.seq[3, 1]:param.seq[5, 2]]
))
-1 * GPvecchia:::vecchia_likelihood_U(y, U.obj)
}

##############################################################################
Expand All @@ -201,7 +204,7 @@ mvnegloglik.full <- function(logparams, locs, y, param.seq) {
# index locations of each parameter.

# P <- length(y)
# transform the postively constrained parameters from log-space to normal-space
# transform the positively constrained parameters from log-space to normal-space
P <- length(locs)
params <- unlog.params(logparams, param.seq, P)
sig2 <- params[param.seq[1, 1]:param.seq[1, 2]]
Expand Down Expand Up @@ -234,7 +237,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 the symmetrical marginal+cross-covariance flexible matern from the
# 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)
range.mat <- diag(marg.range, P, P)
Expand Down Expand Up @@ -271,7 +274,7 @@ create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth, nugget,
### Calculate the Matern marginal and cross-covariance super-matrix #########

cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) {
# cat.covariance: This functions takes the locations and flexible matern parameters
# cat.covariance: This functions takes the locations and flexible Matern parameters
# and pieces together the marginal+cross-covariance matrix
#
# Inputs: locs- P dimension list of the locations,
Expand All @@ -293,15 +296,15 @@ cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) {
d <- fields::rdist(locs.list[[i]], locs.list[[j]])
# Calculate the covariance matrix - if/then based on its location in the super-matrix
N <- nrow(d)
if (i == j) { # To accomodate varying size outcomes- the nugget is not included on cross-covariances
cov.mat.ij <- sig2[i, j] * geoR::matern(d,
phi = range[i, j], kappa =
if (i == j) { # To accommodate varying size outcomes- the nugget is not included on cross-covariances
cov.mat.ij <- sig2[i, j] * fields::Matern(d,
range = range[i, j], smoothness =
smoothness[i, j]
) +
nugget[i, j] * diag(N)
} else {
cov.mat.ij <- sig2[i, j] * geoR::matern(d,
phi = range[i, j], kappa =
cov.mat.ij <- sig2[i, j] * fields::Matern(d,
range = range[i, j], smoothness =
smoothness[i, j]
)
}
Expand Down
5 changes: 5 additions & 0 deletions R/PrestoGP-package.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"_PACKAGE"

## usethis namespace: start
#' @import GPvecchia Matrix fields MASS glmnet
#' @importFrom foreach %dopar%
#' @importFrom foreach foreach
#' @importFrom methods callNextMethod
#' @importFrom methods new
#' @importFrom methods validObject
#' @importFrom stats coef
#' @importFrom utils getFromNamespace
#' @importFrom stats optim predict var
#' @importFrom aod wald.test
#' @importFrom dplyr %>%
## usethis namespace: end
NULL
Loading

0 comments on commit 076c0a1

Please sign in to comment.