├── inst ├── lib │ └── python │ │ ├── __init__.py │ │ └── make_utils.py ├── test │ ├── output │ │ └── monte_carlo.log │ └── code │ │ ├── make_test.py │ │ └── monte_carlo.R └── make.py ├── .gitignore ├── LICENSE ├── .Rbuildignore ├── NAMESPACE ├── suptCriticalValue.Rproj ├── DESCRIPTION ├── LICENSE.md ├── man └── suptCriticalValue.Rd ├── R └── suptCriticalValue.R ├── README.Rmd └── README.md /inst/lib/python/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user/ 2 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2023 2 | COPYRIGHT HOLDER: suptCriticalValue authors 3 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(suptCriticalValue) 4 | -------------------------------------------------------------------------------- /inst/test/output/monte_carlo.log: -------------------------------------------------------------------------------- 1 | [1] "POINTWISE COVERAGE WITH SINGLE REGRESSOR:" 2 | [1] 0.9544 3 | [1] "SIMULTANEOUS SUP-T COVERAG WITH SINGLE REGRESSOR:" 4 | [1] 0.9496 5 | [1] "POINTWISE COVERAGE WITH MULTIPLE REGRESSORS:" 6 | [1] 0.8484 7 | [1] "SIMULTANEOUS SUP-T COVERAG WITH MULTIPLE REGRESSORS:" 8 | [1] 0.9604 9 | -------------------------------------------------------------------------------- /inst/test/code/make_test.py: -------------------------------------------------------------------------------- 1 | import os, sys, subprocess, shutil 2 | 3 | python_lib_path = '../../lib/python/' 4 | shutil.copytree(python_lib_path, './python_lib/') 5 | from python_lib.make_utils import * 6 | 7 | clear_dirs(['../output/']) 8 | 9 | run_rbatch(program = 'monte_carlo.R') 10 | 11 | shutil.rmtree('python_lib') -------------------------------------------------------------------------------- /suptCriticalValue.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /inst/make.py: -------------------------------------------------------------------------------- 1 | import os, sys, subprocess, shutil 2 | 3 | python_lib_path = './lib/python/' 4 | shutil.copytree(python_lib_path, './python_lib/') 5 | from python_lib.make_utils import * 6 | 7 | root = os.getcwd() 8 | 9 | # UNIT TESTS 10 | os.chdir('./test/code/') 11 | run_python(program = 'make_test.py') 12 | os.chdir(root) 13 | 14 | # EXAMPLE 15 | os.chdir('./example/code/') 16 | run_python(program = 'make_example.py') 17 | os.chdir(root) 18 | 19 | shutil.rmtree('python_lib') 20 | raw_input('\n Press to exit') -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: suptCriticalValue 2 | Type: Package 3 | Title: Computes critical values underlying simultaneous sup-t confidence bands 4 | Version: 0.1.0 5 | Authors@R: c(person("Ryan", "Kessler", email = "ryan.edmund.kessler@gmail.com", role = c("aut","cre"))) 6 | Description: This package computes the critical values underlying the simultaneous sup-t confidence bands proposed in Montiel Olea and Plagborg-Møller (2019) . 7 | Encoding: UTF-8 8 | LazyData: true 9 | Imports: 10 | MASS 11 | Depends: 12 | R (>= 3.0) 13 | RoxygenNote: 7.2.3.9000 14 | License: MIT + file LICENSE 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2023 suptCriticalValue authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /inst/lib/python/make_utils.py: -------------------------------------------------------------------------------- 1 | import os, sys, subprocess, shutil 2 | 3 | LOG_DIR_DEFAULT = '../output/' 4 | 5 | def run_python(program, log_dir = './'): 6 | 7 | cmd = 'python {0}'.format(program) 8 | 9 | print('\nExecuting: {0}'.format(cmd)) 10 | subprocess.call(cmd, shell = True) 11 | 12 | def run_stata(program, log_dir = LOG_DIR_DEFAULT): 13 | 14 | log_file = program.replace('.do', '.log') 15 | cmd = 'stata-se -b {0}'.format(program) 16 | 17 | print('\n Executing: {0}'.format(cmd)) 18 | 19 | subprocess.call(cmd, shell = True) 20 | os.rename(log_file, log_dir + log_file) 21 | 22 | def run_rbatch(program, log_dir = LOG_DIR_DEFAULT): 23 | 24 | log_file = program.replace('.R', '.log') 25 | cmd = 'Rscript --no-save --no-restore --verbose {0} > {1}'.format(program, log_file) 26 | 27 | print('\n Executing: {0}'.format(cmd)) 28 | 29 | subprocess.call(cmd, shell = True) 30 | os.rename(log_file, log_dir + log_file) 31 | 32 | def clear_dirs(dir_list): 33 | 34 | for dir in dir_list: 35 | if os.path.exists(dir): 36 | shutil.rmtree(dir) 37 | os.mkdir(dir) 38 | 39 | -------------------------------------------------------------------------------- /man/suptCriticalValue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/suptCriticalValue.R 3 | \name{suptCriticalValue} 4 | \alias{suptCriticalValue} 5 | \title{Create sup t critical value} 6 | \usage{ 7 | suptCriticalValue(vcov_matrix, num_sim = 1000, conf_level = 0.95, seed = NULL) 8 | } 9 | \arguments{ 10 | \item{vcov_matrix}{Variance-covariance matrix} 11 | 12 | \item{num_sim}{Number of bootstrap simulations. Default is 1000.} 13 | 14 | \item{conf_level}{Confidence level. Default is 0.95.} 15 | 16 | \item{seed}{Random seed if provided. Default is NULL.} 17 | } 18 | \value{ 19 | Numeric. Sup t critical value. Multiple by the standard error to get the confidence interval length. 20 | } 21 | \description{ 22 | Create sup t critical value 23 | } 24 | \examples{ 25 | library(MASS) 26 | data(Cars93, package = "MASS") 27 | conf_level <- 0.95 28 | model <- lm(Price ~ Weight + Wheelbase + Cylinders, data=Cars93) 29 | 30 | beta <- matrix(coef(model)) 31 | vcov_matrix <- vcov(model) 32 | std_error <- sqrt(diag(vcov_matrix)) 33 | 34 | pw_crit <- qt(1 - ((1 - conf_level) / 2), model$df.residual) 35 | supt_crit <- suptCriticalValue(vcov_matrix = vcov_matrix) 36 | 37 | pw_ci_lb <- beta - pw_crit * std_error 38 | pw_ci_ub <- beta + pw_crit * std_error 39 | supt_ci_lb <- beta - supt_crit * std_error 40 | supt_ci_ub <- beta + supt_crit * std_error 41 | 42 | print("POINTWISE 95 PERCENT CONFIDENCE INTERVAL: ") 43 | print(paste0( 44 | "[", pw_ci_lb, ", ", pw_ci_ub, "]" 45 | )) 46 | 47 | print("SIMULTANEOUS SUP-T 95 PERCENT CONFIDENCE INTERVAL: ") 48 | print(paste0( 49 | "[", supt_ci_lb, ", ", supt_ci_ub, "]" 50 | )) 51 | 52 | } 53 | -------------------------------------------------------------------------------- /R/suptCriticalValue.R: -------------------------------------------------------------------------------- 1 | #' Create sup t critical value 2 | #' 3 | #' @param vcov_matrix Variance-covariance matrix 4 | #' @param num_sim Number of bootstrap simulations. Default is 1000. 5 | #' @param conf_level Confidence level. Default is 0.95. 6 | #' @param seed Random seed if provided. Default is NULL. 7 | #' 8 | #' @return Numeric. Sup t critical value. Multiple by the standard error to get the confidence interval length. 9 | #' 10 | #' @examples 11 | #' library(MASS) 12 | #' data(Cars93, package = "MASS") 13 | #' conf_level <- 0.95 14 | #' model <- lm(Price ~ Weight + Wheelbase + Cylinders, data=Cars93) 15 | #' 16 | #' beta <- matrix(coef(model)) 17 | #' vcov_matrix <- vcov(model) 18 | #' std_error <- sqrt(diag(vcov_matrix)) 19 | #' 20 | #' pw_crit <- qt(1 - ((1 - conf_level) / 2), model$df.residual) 21 | #' supt_crit <- suptCriticalValue(vcov_matrix = vcov_matrix) 22 | #' 23 | #' pw_ci_lb <- beta - pw_crit * std_error 24 | #' pw_ci_ub <- beta + pw_crit * std_error 25 | #' supt_ci_lb <- beta - supt_crit * std_error 26 | #' supt_ci_ub <- beta + supt_crit * std_error 27 | #' 28 | #' print("POINTWISE 95 PERCENT CONFIDENCE INTERVAL: ") 29 | #' print(paste0( 30 | #' "[", pw_ci_lb, ", ", pw_ci_ub, "]" 31 | #' )) 32 | #' 33 | #' print("SIMULTANEOUS SUP-T 95 PERCENT CONFIDENCE INTERVAL: ") 34 | #' print(paste0( 35 | #' "[", supt_ci_lb, ", ", supt_ci_ub, "]" 36 | #' )) 37 | #' 38 | #' @export 39 | suptCriticalValue <- function(vcov_matrix, num_sim = 1000, conf_level = 0.95, seed = NULL) { 40 | if (!is.null(seed)) { 41 | if (exists(".Random.seed")) { 42 | seed_before_call <- .Random.seed 43 | on.exit({ 44 | .Random.seed <<- seed_before_call 45 | }) 46 | } 47 | set.seed(seed) 48 | } 49 | 50 | if (conf_level <= 0 | conf_level >= 1) { 51 | stop("Confidence level must live in (0, 1)") 52 | } 53 | 54 | std_errors <- t(sqrt(diag(vcov_matrix))) 55 | draws <- MASS::mvrnorm(n = num_sim, mu = rep(0, nrow(vcov_matrix)), Sigma = vcov_matrix) 56 | 57 | t <- apply(draws, 1, FUN = function(x) max(abs(x / std_errors))) 58 | critical_value <- as.numeric(stats::quantile(t, probs = conf_level)) 59 | 60 | return(critical_value) 61 | } 62 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # Computing Simultaneous Confidence Bands in R 17 | 18 | Simultaneous confidence bands are versatile tools for visualizing estimation uncertainty for parameter vectors ([Montiel Olea and Plagborg-Møller 2019](https://doi.org/10.1002/jae.2656)). 19 | 20 | This repository houses a [R](https://www.r-project.org/) package that computes the critical values underlying the simultaneous sup-t confidence bands proposed in [Montiel Olea and Plagborg-Møller (2019)](https://doi.org/10.1002/jae.2656). 21 | 22 | ## Installation 23 | 24 | You can install the package from [GitHub](https://github.com/): 25 | 26 | ``` r 27 | # install.packages("devtools") 28 | devtools::install_github("ryanedmundkessler/suptCriticalValue") 29 | ``` 30 | 31 | The following example shows how to calculate sup-t critical values and, in turn, construct sup-t confidence bands: 32 | 33 | ```{r} 34 | library(suptCriticalValue) 35 | library(MASS) 36 | data(Cars93, package = "MASS") 37 | conf_level <- 0.95 38 | model <- lm(Price ~ Weight + Wheelbase + Cylinders, data=Cars93) 39 | 40 | beta <- matrix(coef(model)) 41 | vcov_matrix <- vcov(model) 42 | std_error <- sqrt(diag(vcov_matrix)) 43 | 44 | pw_crit <- qt(1 - ((1 - conf_level) / 2), model$df.residual) 45 | supt_crit <- suptCriticalValue(vcov_matrix = vcov_matrix) 46 | 47 | pw_ci_lb <- beta - pw_crit * std_error 48 | pw_ci_ub <- beta + pw_crit * std_error 49 | supt_ci_lb <- beta - supt_crit * std_error 50 | supt_ci_ub <- beta + supt_crit * std_error 51 | 52 | print("POINTWISE 95 PERCENT CONFIDENCE INTERVAL: ") 53 | print(paste0( 54 | "[", pw_ci_lb, ", ", pw_ci_ub, "]" 55 | )) 56 | 57 | print("SIMULTANEOUS SUP-T 95 PERCENT CONFIDENCE INTERVAL: ") 58 | print(paste0( 59 | "[", supt_ci_lb, ", ", supt_ci_ub, "]" 60 | )) 61 | ``` 62 | 63 | ## Unit Tests 64 | 65 | [`monte_carlo.R`](./inst/test/code/monte_carlo.R) asserts that the resulting sup-t confidence bands have expected coverage under select data generating processes 66 | 67 | ## Author 68 | 69 | Ryan Kessler 70 |
Email: ryan.edmund.kessler@gmail.com 71 | 72 | ## License 73 | 74 | This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details 75 | 76 | ## References 77 | 78 | Montiel Olea, José Luis and Mikkel Plagborg-Møller. 2019. Simultaneous Confidence Bands: Theory, Implementation, and an Application to SVARs. Journal of Applied Econometrics. https://doi.org/10.1002/jae.2656 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Computing Simultaneous Confidence Bands in R 5 | 6 | Simultaneous confidence bands are versatile tools for visualizing 7 | estimation uncertainty for parameter vectors ([Montiel Olea and 8 | Plagborg-Møller 2019](https://doi.org/10.1002/jae.2656)). 9 | 10 | This repository houses a [R](https://www.r-project.org/) package that 11 | computes the critical values underlying the simultaneous sup-t 12 | confidence bands proposed in [Montiel Olea and Plagborg-Møller 13 | (2019)](https://doi.org/10.1002/jae.2656). 14 | 15 | ## Installation 16 | 17 | You can install the package from [GitHub](https://github.com/): 18 | 19 | ``` r 20 | # install.packages("devtools") 21 | devtools::install_github("ryanedmundkessler/suptCriticalValue") 22 | ``` 23 | 24 | The following example shows how to calculate sup-t critical values and, 25 | in turn, construct sup-t confidence bands: 26 | 27 | ``` r 28 | library(suptCriticalValue) 29 | library(MASS) 30 | data(Cars93, package = "MASS") 31 | conf_level <- 0.95 32 | model <- lm(Price ~ Weight + Wheelbase + Cylinders, data=Cars93) 33 | 34 | beta <- matrix(coef(model)) 35 | vcov_matrix <- vcov(model) 36 | std_error <- sqrt(diag(vcov_matrix)) 37 | 38 | pw_crit <- qt(1 - ((1 - conf_level) / 2), model$df.residual) 39 | supt_crit <- suptCriticalValue(vcov_matrix = vcov_matrix) 40 | 41 | pw_ci_lb <- beta - pw_crit * std_error 42 | pw_ci_ub <- beta + pw_crit * std_error 43 | supt_ci_lb <- beta - supt_crit * std_error 44 | supt_ci_ub <- beta + supt_crit * std_error 45 | 46 | print("POINTWISE 95 PERCENT CONFIDENCE INTERVAL: ") 47 | #> [1] "POINTWISE 95 PERCENT CONFIDENCE INTERVAL: " 48 | print(paste0( 49 | "[", pw_ci_lb, ", ", pw_ci_ub, "]" 50 | )) 51 | #> [1] "[-21.330171843335, 46.83621403265]" 52 | #> [2] "[0.00251094532423298, 0.016128208267558]" 53 | #> [3] "[-0.690962683241204, 0.212504357845869]" 54 | #> [4] "[-8.40398530927412, 9.84209118926257]" 55 | #> [5] "[-11.7914298114545, 18.1682526011994]" 56 | #> [6] "[-7.00047790888086, 15.8049479269484]" 57 | #> [7] "[-1.15493094107966, 25.1081284937888]" 58 | #> [8] "[-1.38976348129131, 32.8553708816936]" 59 | 60 | print("SIMULTANEOUS SUP-T 95 PERCENT CONFIDENCE INTERVAL: ") 61 | #> [1] "SIMULTANEOUS SUP-T 95 PERCENT CONFIDENCE INTERVAL: " 62 | print(paste0( 63 | "[", supt_ci_lb, ", ", supt_ci_ub, "]" 64 | )) 65 | #> [1] "[-33.2487461671825, 58.7547883564975]" 66 | #> [2] "[0.000130030473141085, 0.0185091231186499]" 67 | #> [3] "[-0.848929677383055, 0.37047135198772]" 68 | #> [4] "[-11.5942266000777, 13.0323324800662]" 69 | #> [5] "[-17.0297404093453, 23.4065631990902]" 70 | #> [6] "[-10.9879001451987, 19.7923701632663]" 71 | #> [7] "[-5.74690426962871, 29.7001018223379]" 72 | #> [8] "[-7.37736534532344, 38.8429727457257]" 73 | ``` 74 | 75 | ## Unit Tests 76 | 77 | [`monte_carlo.R`](./inst/test/code/monte_carlo.R) asserts that the 78 | resulting sup-t confidence bands have expected coverage under select 79 | data generating processes 80 | 81 | ## Author 82 | 83 | Ryan Kessler
Email: 84 | 85 | ## License 86 | 87 | This project is licensed under the MIT License. See the 88 | [LICENSE.md](LICENSE.md) file for details 89 | 90 | ## References 91 | 92 | Montiel Olea, José Luis and Mikkel Plagborg-Møller. 2019. Simultaneous 93 | Confidence Bands: Theory, Implementation, and an Application to SVARs. 94 | Journal of Applied Econometrics. 95 | -------------------------------------------------------------------------------- /inst/test/code/monte_carlo.R: -------------------------------------------------------------------------------- 1 | library(MASS) 2 | library(suptCriticalValue) 3 | set.seed(19240) 4 | 5 | main <- function() { 6 | num_reps <- 2500 7 | num_obs <- 100000 8 | conf_level <- 0.95 9 | cov_tolerance <- 0.02 10 | 11 | results <- replicate(num_reps, coverage_simulation(num_obs = num_obs, multiple_regressors = FALSE, 12 | conf_level = conf_level)) 13 | pw_coverage <- mean(unlist(results[1,])) 14 | supt_coverage <- mean(unlist(results[2,])) 15 | 16 | print("POINTWISE COVERAGE WITH SINGLE REGRESSOR:") 17 | print(pw_coverage) 18 | 19 | print("SIMULTANEOUS SUP-T COVERAG WITH SINGLE REGRESSOR:") 20 | print(supt_coverage) 21 | 22 | stopifnot(abs(pw_coverage - conf_level) <= cov_tolerance) 23 | stopifnot(abs(supt_coverage - conf_level) <= cov_tolerance) 24 | 25 | results <- replicate(num_reps, coverage_simulation(num_obs = num_obs, multiple_regressors = TRUE, 26 | conf_level = conf_level)) 27 | pw_coverage <- mean(unlist(results[1,])) 28 | supt_coverage <- mean(unlist(results[2,])) 29 | 30 | print("POINTWISE COVERAGE WITH MULTIPLE REGRESSORS:") 31 | print(pw_coverage) 32 | 33 | print("SIMULTANEOUS SUP-T COVERAG WITH MULTIPLE REGRESSORS:") 34 | print(supt_coverage) 35 | 36 | stopifnot(abs(pw_coverage - conf_level) > 3 * cov_tolerance) 37 | stopifnot(abs(supt_coverage - conf_level) <= cov_tolerance) 38 | } 39 | 40 | coverage_simulation <- function(num_obs, num_reps, multiple_regressors, conf_level = 0.95) { 41 | data <- simulate_data(num_obs = num_obs, multiple_regressors = multiple_regressors) 42 | coverage <- determine_coverage(data, conf_level = conf_level, multiple_regressors = multiple_regressors) 43 | return(coverage) 44 | } 45 | 46 | simulate_data <- function(num_obs, multiple_regressors = TRUE) { 47 | 48 | num_obs <- num_obs 49 | if (multiple_regressors == TRUE) { 50 | vcov_matrix <- matrix(c(1, 0.2, 0.2, 51 | 0.2, 1, 0.2, 52 | 0.2, 0.2, 1), nrow = 3, ncol = 3, byrow = TRUE) 53 | } else { 54 | vcov_matrix <- matrix(1) 55 | } 56 | 57 | true_beta <- rep(1, nrow(vcov_matrix)) 58 | X <- mvrnorm(n = num_obs, mu = rep(0, nrow(vcov_matrix)), Sigma = vcov_matrix) 59 | y <- X %*% true_beta + rnorm(num_obs, 0, 10) 60 | data <- as.data.frame(cbind(y, X)) 61 | 62 | if (multiple_regressors == TRUE) { 63 | colnames(data) <- c("y", "x1", "x2", "x3") 64 | } else { 65 | colnames(data) <- c("y", "x1") 66 | } 67 | 68 | return(data) 69 | } 70 | 71 | determine_coverage <- function(data, multiple_regressors, conf_level = 0.95) { 72 | 73 | if (multiple_regressors == TRUE) { 74 | model <- lm(y ~ x1 + x2 + x3 - 1, data = data) 75 | } else { 76 | model <- lm(y ~ x1 - 1, data = data) 77 | } 78 | beta <- matrix(coef(model)) 79 | vcov_matrix <- vcov(model) 80 | std_error <- sqrt(diag(vcov_matrix)) 81 | true_beta <- rep(1, nrow(vcov_matrix)) 82 | 83 | pw_crit <- qt(1 - ((1 - conf_level) / 2), model$df.residual) 84 | supt_crit <- suptCriticalValue(vcov_matrix = vcov_matrix) 85 | 86 | pw_cover <- is_beta_covered(beta = beta, vcov_matrix = vcov_matrix, 87 | true_beta = true_beta, critical_value = pw_crit) 88 | 89 | supt_cover <- is_beta_covered(beta = beta, vcov_matrix = vcov_matrix, 90 | true_beta = true_beta, critical_value = supt_crit) 91 | 92 | return_list <- list(pw_cover = pw_cover, 93 | supt_cover = supt_cover) 94 | 95 | return(return_list) 96 | } 97 | 98 | is_beta_covered <- function(beta, vcov_matrix, true_beta, critical_value) { 99 | 100 | std_error <- sqrt(diag(vcov_matrix)) 101 | 102 | conf_lb <- beta - critical_value * std_error 103 | conf_ub <- beta + critical_value * std_error 104 | 105 | covered <- (true_beta >= conf_lb) & (true_beta <= conf_ub) 106 | all_covered <- min(covered) 107 | 108 | return(all_covered) 109 | } 110 | 111 | main() 112 | --------------------------------------------------------------------------------