-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### 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
1 parent
a6166b7
commit dcae67f
Showing
16 changed files
with
398 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ MASTER.R | |
TODO.* | ||
cran-comments.md | ||
^CRAN-SUBMISSION$ | ||
revdep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
) |
Oops, something went wrong.