Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
### New features
- New `vcov` method

### Bug fixes
- Adapts `smooth_scam` function to new version of package `gratia`
- Fixes names in confidence intervals from `confint.cgaim`
  • Loading branch information
PierreMasselot committed Apr 3, 2024
1 parent a6166b7 commit dcae67f
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 112 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ MASTER.R
TODO.*
cran-comments.md
^CRAN-SUBMISSION$
revdep
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.0.0
Date: 2022-07-07 17:31:28 UTC
SHA: f25c091cb14623d70c2ce89f349d8e338ae4e71d
Version: 1.0.1
Date: 2024-03-29 15:33:13 UTC
SHA: a6166b74bbd812f1e28652612228db1a837c6e8a
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cgaim
Title: Constrained Groupwise Additive Index Models
Version: 1.0.0
Version: 1.0.1
Authors@R:
person(given = "Pierre",
family = "Masselot",
Expand All @@ -13,7 +13,7 @@ Encoding: UTF-8
LazyData: true
Suggests:
testthat (>= 2.1.0)
RoxygenNote: 7.2.0
RoxygenNote: 7.3.1
Imports:
graphics,
stats,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ S3method(confint,cgaim)
S3method(plot,cgaim)
S3method(predict,cgaim)
S3method(print,cgaim)
S3method(vcov,boot.cgaim)
S3method(vcov,cgaim)
export(boot.cgaim)
export(build_constraints)
export(cgaim)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.0.1

### New features
- New `vcov` method

### Bug fixes
- Adapts `smooth_scam` function to new version of package `gratia`
- Fixes names in confidence intervals from `confint.cgaim`

## 1.0.0

### Changes
Expand Down
2 changes: 1 addition & 1 deletion R/confint.boot.cgaim.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ confint.boot.cgaim <- function(object, parm, level = 0.95, ...)
alims, na.rm = TRUE))

# Names
rownames(res$alpha) <- names(unlist(object$alpha))
rownames(res$alpha) <- names(unlist(object$obs$alpha))
colnames(res$alpha) <- level.labels
}
if (2 %in% parm){
Expand Down
6 changes: 3 additions & 3 deletions R/smooth_scam.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ smooth_scam <- function(x, y, formula, Xcov, ...)
# print("scam"); flush.console()
} else {
gfit <- mgcv::gam(formula, data = scam_data, ...)
derivs <- as.data.frame(gratia::derivatives(gfit, newdata = scam_data))
derivs <- as.data.frame(gratia::derivatives(gfit, data = scam_data))
# print("gam"); flush.console()
}
# Extract estimated terms
Expand All @@ -43,8 +43,8 @@ smooth_scam <- function(x, y, formula, Xcov, ...)
if (iscons){
dgx[,j] <- scam::derivative.scam(gfit, jind)$d
} else {
dgx[,j] <- derivs[derivs$smooth == gfit$smooth[[jind]]$label,
"derivative"]
dgx[,j] <- derivs[derivs$.smooth == gfit$smooth[[jind]]$label,
".derivative"]
}
} else {
if (is.numeric(scam_data[j])){
Expand Down
39 changes: 39 additions & 0 deletions R/vcov.boot.cgaim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @rdname vcov.cgaim
#' @order 2
#'
#' @export
vcov.boot.cgaim <- function(object, parm = c("alpha", "beta"), complete = TRUE,
...)
{
#----- Header

# Check parm
parm <- match.arg(parm)

#----- Create variance covariane matrix

# Compute vcov
vres <- stats::var(t(object$boot[[parm]]))

# Set names
rownames(vres) <- colnames(vres) <- names(unlist(object$obs[[parm]]))

#----- Complete for potentially aliased coefficients
if (isTRUE(complete)){

# Check if any aliased coefficients
aliased <- is.na(unlist(object$obs[[parm]]))

# Complete
vresa <- matrix(NA, length(aliased), length(aliased),
dimnames = list(names(unlist(object$obs[[parm]])),
names(unlist(object$obs[[parm]]))))
vresa[!aliased, !aliased] <- vres

#----- Return
return(vresa)
} else {
return(vres)
}

}
124 changes: 124 additions & 0 deletions R/vcov.cgaim.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#' Calculate Variance-Covariance Matrix for a Fitted CGAIM Object
#'
#' Returns the variance covariance matrix of the main parameters of a fitted \code{cgaim} object. These parameters correspond to the index weights \code{alpha} and the scaling coefficients \code{beta}.
#'
#' @param object A \code{cgaim} or \code{boot.cgaim} object.
#' @param parm The model components for which to get confidence intervals.
#' Either \code{"alpha"} (the default) for index weights or \code{"beta"} for scaling coefficients.
#' @param type The type of confidence intervals. Either \code{"normal"} (the default)
#' or \code{"bootstrap"}. See details.
#' @param B The number of samples to be simulated.
#' @param complete Indicates whether the full variance-covariance matrix should be returned when some of the parameters could not be estimated. If so, the matrix is padded with \code{NA}s.
#' @param ... Additional parameters to be passed to \code{\link{boot.cgaim}} for bootstrap replications.
#'
#' @details
#' Two types of computation are currently implemented in the function.
#' When \code{type = "normal"}, variance-covariance matrices are computed assuming
#' components are normally distributed. Beta coefficients are treated as
#' regular linear regression coefficients and alpha
#' coefficients are assumed to follow a Truncated Multivariate Normal distribution.
#' The latter is obtained by simulating from TMVN (see \code{\link[TruncatedNormal]{tmvnorm}})
#' and computing the empirical variance covariance matrix from these simulations. The parameter \code{B} controls the number of simulations from the TMVN (and is not used when \code{parm = "beta"}).
#'
#' When \code{type = "bootstrap"}, the variance-covariance matrix is computed on Bootstrap replications. In this case \code{\link{boot.cgaim}} is called internally and \code{B} corresponds to the number of replications. Alternatively, the user can directly call \code{\link{boot.cgaim}} and feed the result into \code{vcov.boot.cgaim} (see examples).
#'
#' @returns A variance-covariance matrix object.
#'
#' @seealso \code{\link{boot.cgaim}} for bootstrapping and \code{\link{confint.cgaim}} for confidence intervals.
#'
#' @references
#' Masselot, P. and others, 2022. Constrained groupwise additive index models.
#' Biostatistics.
#'
#' Pya, N., Wood, S.N., 2015. Shape constrained additive models.
#' Stat. Comput. 25, 543–559.
#'
#' Wood, S.N., 2017. Generalized Additive Models: An Introduction with R,
#' 2nd ed, Texts in Statistical Science. Chapman and Hall/CRC.
#'
#' @examples
#' # A simple CGAIM
#' n <- 200
#' x1 <- rnorm(n)
#' x2 <- x1 + rnorm(n)
#' z <- x1 + x2
#' y <- z + rnorm(n)
#' df1 <- data.frame(y, x1, x2)
#' ans <- cgaim(y ~ g(x1, x2, acons = list(monotone = 1)), data = df1)
#'
#' # (Truncated) Normal variance-covariance matrix
#' set.seed(1)
#' vcov(ans, B = 1000)
#' set.seed(1)
#' vcov(ans, parm = "alpha", B = 1000) # Same result
#' vcov(ans, parm = "beta", B = 1000)
#'
#' # Confidence intervals by bootstrap (more computationally intensive, B should be increased)
#' set.seed(2)
#' vcov(ans, type = "boot", B = 10)
#'
#' # Alternatively, bootstrap samples can be performed beforehand
#' set.seed(2)
#' boot1 <- boot.cgaim(ans, B = 10)
#' vcov(boot1)
#'
#' @order 1
#' @export
vcov.cgaim <- function(object, parm = c("alpha", "beta"),
type = c("normal", "bootstrap"), B = 100, complete = TRUE, ...)
{
#----- Header

# Check parm
parm <- match.arg(parm)

# Check type
type <- match.arg(type)

#----- Compute vcov if "normal"
if (type == "normal"){
# For alpha: simulate from truncated normal
if(parm == "alpha"){

# Simulate alpha from truncated multivariate normal
simures <- simul_tmvnorm(object, B = B)

# Compute vcov
vres <- stats::var(simures)
}

# For beta
if (parm == "beta"){

# use the usual vcov matrix
vres <- vcov_beta(object)
}

# Set names
rownames(vres) <- colnames(vres) <- names(unlist(object[[parm]]))

# Fill potentially for aliased coefficients
if (isTRUE(complete)){

# Check if any aliased coefficients
aliased <- is.na(unlist(object[[parm]]))

# Complete
vresa <- matrix(NA, length(aliased), length(aliased),
dimnames = list(names(unlist(object[[parm]])),
names(unlist(object[[parm]]))))
vresa[!aliased, !aliased] <- vres
vres <- vresa
}
} else {

# Simulate
simures <- boot.cgaim(object, B = B, ...)

# Compute CI
vres <- vcov.boot.cgaim(simures, parm = parm, complete = complete)
}

#----- Return
return(vres)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ The package is available for installation from the usual CRAN repository. Altern

## Functions

The main function of the package is the eponymous `cgaim` that fits the model. Then, the `print.cgaim` method allows displaying the results. The `confint.cgaim` method allows computing confidence intervals, either using normal approximation or through bootstrap. Ridge functions can be displayed using the `plot.cgaim` method, with the possibility to add confidence intervals. Finally, `predict.cgaim` allows computing the indices and perform prediction on new observations.
The main function of the package is the eponymous `cgaim` that fits the model. Then, the `print.cgaim` method allows displaying the results. The `confint.cgaim` and `vcov.cgaim` methods allow computing confidence intervals and variance-covariance matrix using various approaches. Ridge functions can be displayed using the `plot.cgaim` method, with the possibility to add confidence intervals. Finally, `predict.cgaim` allows computing the indices and perform prediction on new observations.
See the help of each function.
34 changes: 4 additions & 30 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
# 1.0.0
# 1.0.1

## Resubmission
This is a resubmission. In this version I have:

* Added a \donttest statement for R CMD check to ignore the most computationally expensive example.
* Added the reference to the methodological paper in the DESCRIPTION file.
* Replaced the T and F that previously escaped me by TRUE and FALSE.
* Added \value fields to the documentation of exported functions missing one.
Package update after check errors from 27/04/2024. Fixes error induced by the update of the `gratia` dependency.

## R CMD check results
There were no ERRORs or WARNINGs.

There was one NOTE on winbuilder only:

* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Pierre Masselot <pierre.masselot@lshtm.ac.uk>'

New submission

Possibly misspelled words in DESCRIPTION:
Campagna (10:182)
Chebana (10:173)
Gosselin (10:209)
Groupwise (2:20)
Lavigne (10:192)
Masselot (10:163)
Ouarda (10:201)
groupwise (10:31, 10:238)

I believe these notes are just flagging the fact it is a new submission.
Regarding misspelled words, this is how these words are spelled and used in associated publications and are therefore correct (groupwise) and the names of authors in the citation.
0 errors | 0 warnings | 0 notes

## Downstream dependencies
There are currently no downstream dependencies for this package.
Only bug fix and addition of new convenience functions, no change in the specification nor output of the existing function.
14 changes: 7 additions & 7 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
citHeader("To cite cgaim in publications use:")

citEntry(entry = "Article",
bibentry(bibtype = "Article",
title = "Constrained groupwise additive index models",
author = personList(as.person("Pierre Masselot"),
author = c(as.person("Pierre Masselot"),
as.person("Fateh Chebana"),
as.person("Céline Campagna"),
as.person("Éric Lavigne"),
as.person("Taha B.M.J. Ouarda"),
as.person("Pierre Gosselin")),
journal = "Biostatistics",
year = "2022",
volume = "00",
number = "00",
pages = "1--19",
volume = "24",
number = "4",
pages = "1066–1084",
url = "https://doi.org/10.1093/biostatistics/kxac023",

textVersion =
paste("Pierre Masselot, Fateh Chebana, Céline Campagna, Éric Lavigne, Taha B M J Ouarda, Pierre Gosselin (2022).",
paste("Pierre Masselot, Fateh Chebana, Céline Campagna, Éric Lavigne, Taha B.M.J. Ouarda, Pierre Gosselin (2022).",
"Constrained groupwise additive index models.",
"Biostatistics, 00(00), 1-19.",
"Biostatistics, 24(4), 1066–1084.",
"URL https://doi.org/10.1093/biostatistics/kxac023.")
)
Loading

0 comments on commit dcae67f

Please sign in to comment.