Skip to content

Commit

Permalink
some cmdcheck updates; better handling of numeric by variables in gp's
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Nov 11, 2024
1 parent c23c75e commit e96368e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 47 deletions.
3 changes: 2 additions & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ utils::globalVariables(c("y", "year", "smooth_vals", "smooth_num",
"matches", "time.", "file_name", ".data",
"horizon", "target", "Series", "evd", "mean_evd",
"total_evd", "smooth_label", "by_variable",
"gr", "tot_subgrs", "subgr"))
"gr", "tot_subgrs", "subgr", "lambda",
"level", "sim_hilbert_gp", "trend_model"))
6 changes: 4 additions & 2 deletions R/gp.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ make_gp_additions = function(gp_details,
series = newdata$series,
time = newdata$index..time..index)
for(i in seq_along(terms_needed)){
brms_fake_df_new <- cbind(brms_fake_df_new, data[[terms_needed[i]]])
brms_fake_df_new <- cbind(brms_fake_df_new, newdata[[terms_needed[i]]])
}
colnames(brms_fake_df_new) <- c('.fake_gp_y',
'series',
Expand Down Expand Up @@ -348,7 +348,9 @@ eigenfunc_list = function(stan_data,
full_eigens[(seq_along(sorted_by))[
sorted_by == level[x]],] <- eigenfuncs[[x]]
} else {
full_eigens <- eigenfuncs[[x]]
# Numeric by variables should be multiplied by the
# spectral eigenfunctions
full_eigens <- eigenfuncs[[x]] * mock_df[[by[x]]]
}
} else {
full_eigens <- eigenfuncs[[x]]
Expand Down
12 changes: 6 additions & 6 deletions R/mvgam_formulae.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
#' \cr
#' The formulae supplied to \code{\link{mvgam}} are exactly like those supplied to
#' \code{\link{glm}} except that smooth terms,
#' \code{\link[mgcv]{s()}},
#' \code{\link[mgcv]{te()}},
#' \code{\link[mgcv]{ti()}} and
#' \code{\link[mgcv]{t2()}},
#' time-varying effects using \code{\link{dynamic()}},
#' \code{\link[mgcv]{s}},
#' \code{\link[mgcv]{te}},
#' \code{\link[mgcv]{ti}} and
#' \code{\link[mgcv]{t2}},
#' time-varying effects using \code{\link{dynamic}},
#' monotonically increasing (using `s(x, bs = 'moi')`)
#' or decreasing splines (using `s(x, bs = 'mod')`;
#' see \code{\link{smooth.construct.moi.smooth.spec}} for
#' details), as well as
#' Gaussian Process functions using \code{\link[brms]{gp()}},
#' Gaussian Process functions using \code{\link[brms]{gp}},
#' can be added to the right hand side (and \code{.} is not supported in \code{mvgam} formulae).
#' \cr
#' \cr
Expand Down
26 changes: 12 additions & 14 deletions R/residual_cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,29 @@
#' If `TRUE`, the median is used instead. Only used if `summary` is `TRUE`
#' @param ... ignored
#' @return If `summary = TRUE`, a `list` with the following components:
#' \itemize{
#' \item{cor, cor_lower, cor_upper}{: A set of \eqn{p \times p} correlation matrices,
#' \item{cor, cor_lower, cor_upper}{A set of \eqn{p \times p} correlation matrices,
#' containing either the posterior median or mean estimate, plus lower and upper limits
#' of the corresponding credible intervals supplied to `probs`}
#' \item{sig_cor}{: A \eqn{p \times p} correlation matrix containing only those correlations whose credible
#' \item{sig_cor}{A \eqn{p \times p} correlation matrix containing only those correlations whose credible
#' interval does not contain zero. All other correlations are set to zero}
#' \item{prec, prec_lower, prec_upper}{: A set of \eqn{p \times p} precision matrices,
#' \item{prec, prec_lower, prec_upper}{A set of \eqn{p \times p} precision matrices,
#' containing either the posterior median or mean estimate, plus lower and upper limits
#' of the corresponding credible intervals supplied to `probs`}
#' \item{sig_prec}{: A \eqn{p \times p} precision matrix containing only those precisions whose credible
#' \item{sig_prec}{A \eqn{p \times p} precision matrix containing only those precisions whose credible
#' interval does not contain zero. All other precisions are set to zero}
#' \item{cov}{: A \eqn{p \times p} posterior median or mean covariance matrix}
#' \item{trace}{: The median/mean point estimator of the trace (sum of the diagonal elements)
#' \item{cov}{A \eqn{p \times p} posterior median or mean covariance matrix}
#' \item{trace}{The median/mean point estimator of the trace (sum of the diagonal elements)
#' of the residual covariance matrix `cov`}
#' }
#'
#' If `summary = FALSE`, this function returns a `list` containing the following components:
#' \itemize{
#' \item{all_cormat}{: A \eqn{n_{draws} \times p \times p} `array` of posterior
#' \item{all_cormat}{A \eqn{n_{draws} \times p \times p} `array` of posterior
#' residual correlation matrix draws}
#' \item{all_covmat}{: A \eqn{n_{draws} \times p \times p} `array` of posterior
#' \item{all_covmat}{A \eqn{n_{draws} \times p \times p} `array` of posterior
#' residual covariance matrix draws}
#' \item{all_presmat}{: A \eqn{n_{draws} \times p \times p} `array` of posterior
#' \item{all_presmat}{A \eqn{n_{draws} \times p \times p} `array` of posterior
#' residual precision matrix draws}
#' \item{all_trace}{: A \eqn{n_{draws}} `vector` of posterior covariance trace draws}
#' }
#' \item{all_trace}{A \eqn{n_{draws}} `vector` of posterior covariance trace draws}
#'
#' @details
#' Hui (2016) provides an excellent description of the quantities that this function calculates, so this passage
#' is heavily paraphrased from his associated `boral` package.
Expand Down
12 changes: 6 additions & 6 deletions man/mvgam_formulae.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/mvgam_marginaleffects.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 11 additions & 14 deletions man/residual_cor.jsdgam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/RcppExports.o
Binary file not shown.
Binary file modified src/trend_funs.o
Binary file not shown.
3 changes: 1 addition & 2 deletions tests/testthat/test-gp.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ test_that("gp_to_s is working properly for multidimensional gps", {
test_that("unidimensional gp for observation models working properly", {
gaus_data$data_train$y[is.na(gaus_data$data_train$y)] <- 0
mod <- mvgam(formula = y ~ s(series, bs = 're') +
gp(time, by = series, k = 10, c = 5/4,
cov = 'exponential') +
gp(time, by = series, k = 10, c = 5/4) +
year:season,
data = gaus_data$data_train,
family = gaussian(),
Expand Down

0 comments on commit e96368e

Please sign in to comment.