使用各種方法計算引導程序置信區間。
用法
int_pctl(.data, ...)
# S3 method for bootstraps
int_pctl(.data, statistics, alpha = 0.05, ...)
int_t(.data, ...)
# S3 method for bootstraps
int_t(.data, statistics, alpha = 0.05, ...)
int_bca(.data, ...)
# S3 method for bootstraps
int_bca(.data, statistics, alpha = 0.05, .fn, ...)
參數
- .data
-
包含使用
bootstraps()
創建的引導重采樣的數據幀。對於 t- 和 BCa-intervals,apparent
參數應設置為TRUE
。即使對於百分位數方法將apparent
參數設置為TRUE
,表觀數據也不會用於計算百分位數置信區間。 - ...
-
要傳遞給
.fn
的參數(僅限int_bca()
)。 - statistics
-
不帶引號的列名稱或
dplyr
選擇器,用於標識包含各個引導估計的數據集中的單個列。這必須是整齊的 tibbles 列表列(包含term
和estimate
列)。對於t-intervals,需要一個標準的整齊列(通常稱為std.err
)。請參閱下麵的示例。 - alpha
-
重要性程度。
- .fn
-
計算興趣統計量的函數。該函數應采用
rsplit
作為第一個參數,並且需要...
。
值
每個函數返回一個包含列 .lower
、 .estimate
、 .upper
、 .alpha
、 .method
和 term
的 tibble。 .method
是間隔類型(例如"percentile"、"student-t" 或"BCa")。 term
是估計的名稱。請注意從 int_pctl()
返回的 .estimate
是引導重采樣的估計值的平均值,而不是表觀模型的估計值。
細節
百分位數間隔是獲得置信區間的標準方法,但需要數千次重采樣才能準確。 T-intervals 可能需要更少的重采樣,但需要相應的方差估計。偏差校正和加速間隔需要用於創建感興趣的統計數據的原始函數,並且計算量很大。
參考
https://rsample.tidymodels.org/articles/Applications/Intervals.html
戴維森,A. 和欣克利,D. (1997)。 Bootstrap 方法及其應用。劍橋:劍橋大學出版社。號碼:10.1017/CBO9780511802843
例子
# \donttest{
library(broom)
library(dplyr)
library(purrr)
library(tibble)
lm_est <- function(split, ...) {
lm(mpg ~ disp + hp, data = analysis(split)) %>%
tidy()
}
set.seed(52156)
car_rs <-
bootstraps(mtcars, 500, apparent = TRUE) %>%
mutate(results = map(splits, lm_est))
int_pctl(car_rs, results)
#> Warning: Recommend at least 1000 non-missing bootstrap resamples for terms: `(Intercept)`, `disp`, `hp`.
#> # A tibble: 3 × 6
#> term .lower .estimate .upper .alpha .method
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) 27.5 30.7 33.6 0.05 percentile
#> 2 disp -0.0440 -0.0300 -0.0162 0.05 percentile
#> 3 hp -0.0572 -0.0260 -0.00840 0.05 percentile
int_t(car_rs, results)
#> # A tibble: 3 × 6
#> term .lower .estimate .upper .alpha .method
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) 28.1 30.7 34.6 0.05 student-t
#> 2 disp -0.0446 -0.0300 -0.0170 0.05 student-t
#> 3 hp -0.0449 -0.0260 -0.00337 0.05 student-t
int_bca(car_rs, results, .fn = lm_est)
#> Warning: Recommend at least 1000 non-missing bootstrap resamples for terms: `(Intercept)`, `disp`, `hp`.
#> # A tibble: 3 × 6
#> term .lower .estimate .upper .alpha .method
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 (Intercept) 27.7 30.7 33.7 0.05 BCa
#> 2 disp -0.0446 -0.0300 -0.0172 0.05 BCa
#> 3 hp -0.0576 -0.0260 -0.00843 0.05 BCa
# putting results into a tidy format
rank_corr <- function(split) {
dat <- analysis(split)
tibble(
term = "corr",
estimate = cor(dat$sqft, dat$price, method = "spearman"),
# don't know the analytical std.err so no t-intervals
std.err = NA_real_
)
}
set.seed(69325)
data(Sacramento, package = "modeldata")
bootstraps(Sacramento, 1000, apparent = TRUE) %>%
mutate(correlations = map(splits, rank_corr)) %>%
int_pctl(correlations)
#> # A tibble: 1 × 6
#> term .lower .estimate .upper .alpha .method
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 corr 0.737 0.768 0.796 0.05 percentile
# }
相關用法
- R rsample initial_split 簡單的訓練/測試集分割
- R rsample initial_validation_split 創建初始訓練/驗證/測試拆分
- R rsample validation_set 創建驗證拆分以進行調整
- R rsample populate 添加評估指標
- R rsample vfold_cv V 折交叉驗證
- R rsample rset_reconstruct 使用新的 rset 子類擴展 rsample
- R rsample group_mc_cv 小組蒙特卡羅交叉驗證
- R rsample group_vfold_cv V 組交叉驗證
- R rsample rolling_origin 滾動原點預測重采樣
- R rsample reverse_splits 反轉分析和評估集
- R rsample group_bootstraps 團體自舉
- R rsample labels.rset 從 rset 對象中查找標簽
- R rsample get_fingerprint 獲取重采樣的標識符
- R rsample bootstraps 引導抽樣
- R rsample validation_split 創建驗證集
- R rsample reg_intervals 具有線性參數模型的置信區間的便捷函數
- R rsample clustering_cv 集群交叉驗證
- R rsample get_rsplit 從 rset 中檢索單個 rsplit 對象
- R rsample loo_cv 留一交叉驗證
- R rsample complement 確定評估樣本
- R rsample slide-resampling 基於時間的重采樣
- R rsample as.data.frame.rsplit 將 rsplit 對象轉換為 DataFrame
- R rsample labels.rsplit 從 rsplit 對象中查找標簽
- R rsample mc_cv 蒙特卡羅交叉驗證
- R rsample tidy.rsplit 整潔的重采樣對象
注:本文由純淨天空篩選整理自Hannah Frick等大神的英文原創作品 Bootstrap confidence intervals。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。