-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from sfcheung/devel
Fix some typos
- Loading branch information
Showing
19 changed files
with
365 additions
and
40 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
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,68 @@ | ||
#'@title confint method for \code{std_selected} class output | ||
#' | ||
#'@description Return the confidence intervals of estimates | ||
#' in a \code{std_selected} class output | ||
#' | ||
#'@details If bootstrapping is used to form the confidence interval, | ||
#' users can request the percentile confidence intervals of | ||
#' the bootstrap estimates. | ||
#' | ||
#'@return | ||
#' A matrix of the confidence intervals. | ||
#' | ||
#'@param object The output of the class \code{std_selected}. | ||
#'@param parm The parameters for which confidence intervals should be returned. | ||
#' If missing, the confidence intervals of all parameters will be | ||
#' returned. | ||
#'@param level The level of confidence. For the confidence intervals returned | ||
#' by [lm], default is .95. For the bootstrapping confidence | ||
#' intervals, default is the level used in calling | ||
#' [std_selected_boot]. If a level different from that in the | ||
#' original | ||
#' call is specified, `full_output` needs to be set in the call | ||
#' to [std_selected_boot] such that the original bootstrap output | ||
#' is stored. | ||
#'@param type The type of the confidence intervals. Default is "lm", | ||
#' returned by the [confint] method of [lm]. If set to "boot", | ||
#' the bootstrap percentile confidence intervals are | ||
#' returned. | ||
#'@param ... Arguments to be passed to \code{summary.lm}. | ||
#' | ||
#'@examples | ||
#' # See examples for std_selected. | ||
#' @export | ||
|
||
|
||
confint.std_selected <- function(object, parm, level = .95, type = "lm", ...) { | ||
if (!(type %in% c("lm", "boot"))) { | ||
stop("type must be either lm or boot.") | ||
} | ||
if (type == "boot") { | ||
if (is.null(object$boot_est)) { | ||
stop("Bootstrap estimates not available in the object.") | ||
} | ||
if ((level != object$conf) && is.null(object$boot_out)) { | ||
stop("level is different form conf in std_selected_boot but full_output is FALSE.") | ||
} | ||
if (level == object$conf) { | ||
out <- object$boot_ci | ||
} else { | ||
p <- nrow(object$boot_ci) | ||
out <- t(sapply(seq_len(p), function(x) { | ||
boot::boot.ci(object$boot_out, conf = level, | ||
type = "perc", index = x)$percent[4:5] | ||
})) | ||
rownames(out) <- names(object$boot_out$t0) | ||
} | ||
tmp <- object | ||
class(tmp) <- "lm" | ||
colnames(out) <- colnames(stats::confint(tmp, level = level)) | ||
if (!missing(parm)) { | ||
out <- out[rownames(out) %in% parm, , drop = FALSE] | ||
} | ||
return(out) | ||
} | ||
if (type == "lm") { | ||
NextMethod() | ||
} | ||
} |
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,38 @@ | ||
#'@title vcov method for \code{std_selected} class output | ||
#' | ||
#'@description Compute the variance-covariance matrix | ||
#' of estimates in a \code{std_selected} class output | ||
#' | ||
#'@details If bootstrapping is used to form the confidence interval, | ||
#' users can request the variance-covariance matrix of the bootstrap estimates. | ||
#' | ||
#'@return | ||
#' A matrix of the variances and covariances. | ||
#' | ||
#'@param object The output of the class \code{std_selected}. | ||
#'@param type The type of variance-covariance matrix. Default is "lm", | ||
#' returned by the [vcov] method of [lm]. If set to "boot", | ||
#' the variance-covariance matrix of the bootstrap estimates | ||
#' is returned. | ||
#'@param ... Arguments to be passed to \code{summary.lm}. | ||
#' | ||
#'@examples | ||
#' # See examples for std_selected. | ||
#' @export | ||
|
||
|
||
vcov.std_selected <- function(object, type = "lm", ...) { | ||
if (!(type %in% c("lm", "boot"))) { | ||
stop("type must be either lm or boot.") | ||
} | ||
if (type == "boot") { | ||
if (is.null(object$boot_est)) { | ||
stop("Bootstrap estimates not available in the object.") | ||
} | ||
out <- stats::cov(object$boot_est) | ||
return(out) | ||
} | ||
if (type == "lm") { | ||
NextMethod() | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
library(testthat) | ||
library(stdmod) | ||
|
||
context("Check setting confint in summary if bootstrapping is done") | ||
|
||
dat <- test_x_1_w_1_v_1_cat1_n_500 | ||
|
||
lm_raw <- lm(dv ~ iv*mod + v1 + cat1, dat) | ||
|
||
set.seed(649831074) | ||
stdmod_wy <- std_selected_boot(lm_raw, to_scale = ~ mod + dv, to_center = ~ mod + dv, | ||
nboot = 100, | ||
full_output = TRUE) | ||
confint_def <- confint(stdmod_wy) | ||
confint_boot <- confint(stdmod_wy, type = "boot") | ||
confint_lm <- confint(stdmod_wy, type = "lm") | ||
confint_boot_parm <- confint(stdmod_wy, parm = "iv:mod", type = "boot") | ||
confint_boot_conf90 <- confint(stdmod_wy, parm = "iv:mod", level = .90, type = "boot") | ||
|
||
stdmod_wy_lm <- std_selected(lm_raw, to_scale = ~ mod + dv, to_center = ~ mod + dv) | ||
confint_lm_no_boot <- confint(stdmod_wy_lm) | ||
|
||
confint_boot_check <- summary(stdmod_wy)$coefficients[, c("CI Lower", "CI Upper")] | ||
confint_boot_conf90_check <- boot::boot.ci(stdmod_wy$boot_out, conf = .90, | ||
type = "perc", index = 7)$percent[4:5] | ||
|
||
test_that("confint_def == confint by lm", { | ||
expect_equivalent( | ||
confint_def, confint_lm_no_boot | ||
) | ||
}) | ||
|
||
test_that("confint_boot == confint from summary", { | ||
expect_equivalent( | ||
confint_boot, confint_boot_check | ||
) | ||
}) | ||
|
||
test_that("confint_boot != confint from lm", { | ||
expect_false( | ||
identical(confint_boot, confint_lm_no_boot) | ||
) | ||
}) | ||
|
||
test_that("confint_boot with user confidence level", { | ||
expect_true( | ||
all(confint_boot_conf90 == confint_boot_conf90_check) | ||
) | ||
}) | ||
|
Oops, something went wrong.