Skip to contents

Confidence intervals for a fastcpd object

Usage

# S3 method for class 'fastcpd'
confint(
  object,
  parm = c("cp", "theta"),
  level = 0.95,
  method = NULL,
  B = 999,
  bootstrap = c("nonparametric"),
  window = NULL,
  min_segment_length = 2L,
  seed = NULL,
  refit_envir = parent.frame(),
  ...
)

Arguments

object

A fastcpd object.

parm

The target parameter. Use "cp" for change-point locations or "theta" for segment parameters.

level

Confidence level.

method

Method used to construct intervals. Change-point intervals support "bootstrap" and "profile". Parameter intervals support "wald".

B

Number of bootstrap replicates when method = "bootstrap".

bootstrap

Bootstrap type. Currently "nonparametric" resamples observations within each estimated segment and is available for all families that can be refitted from object@call.

window

Optional half-width around each detected change point for profile intervals. If NULL, the whole interval between neighboring detected change points is profiled.

min_segment_length

Minimum number of observations on each side of a candidate split for profile intervals.

seed

Optional random seed used for bootstrap reproducibility.

refit_envir

Environment used to evaluate bootstrap refits and arguments stored in object@call, such as variance_estimation.

...

Ignored.

Value

A data frame of class fastcpd_confint containing estimates, lower and upper interval bounds, and method-specific diagnostics. The returned intervals can be visualized with plot.fastcpd_confint().

Examples

# The well-log data contain outliers, so a robust variance estimate keeps
# the detection and the confidence intervals stable.
sigma2 <- estimate_variance_median(well_log)
result <- detect_mean(well_log, trim = 0.001, variance_estimation = sigma2)

(cp_profile_interval <- confint(
  result,
  parm = "cp",
  method = "profile",
  level = 0.8,
  window = 8
))
#>    parm index estimate lower upper profile_min    cutoff level  method
#> 1    cp     1        7     7     7    52.87531 0.8211872   0.8 profile
#> 2    cp     2       19    19    19   241.92780 0.8211872   0.8 profile
#> 3    cp     3      356   352   356   263.35905 0.8211872   0.8 profile
#> 4    cp     4      448   445   448   238.46836 0.8211872   0.8 profile
#> 5    cp     5      717   712   717   244.38148 0.8211872   0.8 profile
#> 6    cp     6      844   836   844   165.77061 0.8211872   0.8 profile
#> 7    cp     7     1034  1034  1034   112.33891 0.8211872   0.8 profile
#> 8    cp     8     1070  1070  1070   722.51640 0.8211872   0.8 profile
#> 9    cp     9     1215  1215  1223  1701.84249 0.8211872   0.8 profile
#> 10   cp    10     1369  1368  1370  1196.88610 0.8211872   0.8 profile
#> 11   cp    11     1428  1428  1436   391.19149 0.8211872   0.8 profile
#> 12   cp    12     1526  1526  1526   371.54521 0.8211872   0.8 profile
#> 13   cp    13     1685  1685  1685   187.02093 0.8211872   0.8 profile
#> 14   cp    14     1866  1866  1866   198.37859 0.8211872   0.8 profile
#> 15   cp    15     2047  2046  2048   266.44151 0.8211872   0.8 profile
#> 16   cp    16     2409  2409  2409   192.51522 0.8211872   0.8 profile
#> 17   cp    17     2469  2469  2469    51.88408 0.8211872   0.8 profile
#> 18   cp    18     2531  2531  2531    48.09349 0.8211872   0.8 profile
#> 19   cp    19     2591  2591  2591   898.13692 0.8211872   0.8 profile
#> 20   cp    20     2777  2769  2777  1273.88265 0.8211872   0.8 profile
#> 21   cp    21     3490  3490  3498   618.70326 0.8211872   0.8 profile
#> 22   cp    22     3544  3542  3544   108.47163 0.8211872   0.8 profile
#> 23   cp    23     3656  3655  3656    55.24233 0.8211872   0.8 profile
#> 24   cp    24     3672  3666  3672    69.17805 0.8211872   0.8 profile
#> 25   cp    25     3744  3744  3744   114.51875 0.8211872   0.8 profile
#> 26   cp    26     3855  3855  3855    87.10437 0.8211872   0.8 profile
#> 27   cp    27     3886  3883  3886   157.00664 0.8211872   0.8 profile
#> 28   cp    28     3945  3944  3945   170.67656 0.8211872   0.8 profile
#> 29   cp    29     3963  3963  3963   104.68678 0.8211872   0.8 profile
#> 30   cp    30     4035  4035  4036    64.94389 0.8211872   0.8 profile

(theta_wald_interval <- confint(
  result,
  parm = "theta",
  method = "wald"
))
#>             parm segment parameter  estimate     lower     upper        se
#> segment 1  theta       1         1 131888.96 127801.47 135976.45 2085.4923
#> segment 2  theta       2         1  99849.77  96307.89 103391.66 1807.1184
#> segment 3  theta       3         1 112027.36 111743.38 112311.34  144.8889
#> segment 4  theta       4         1 110326.68 109737.20 110916.17  300.7632
#> segment 5  theta       5         1 112927.95 112599.24 113256.66  167.7112
#> segment 6  theta       6         1 111704.25 111245.47 112163.03  234.0747
#> segment 7  theta       7         1 113602.38 113265.87 113938.90  171.6962
#> segment 8  theta       8         1 105619.22 104754.36 106484.08  441.2629
#> segment 9  theta       9         1 126801.79 125577.95 128025.63  624.4200
#> segment 10 theta      10         1 126664.12 125246.83 128081.42  723.1243
#> segment 11 theta      11         1 124647.53 123319.15 125975.90  677.7550
#> segment 12 theta      12         1 125292.53 124134.32 126450.74  590.9334
#> segment 13 theta      13         1 134977.35 134587.66 135367.04  198.8259
#> segment 14 theta      14         1 114811.49 114438.85 115184.13  190.1253
#> segment 15 theta      15         1 129263.26 128899.06 129627.46  185.8193
#> segment 16 theta      16         1 119356.88 119116.38 119597.39  122.7081
#> segment 17 theta      17         1 135435.44 134897.30 135973.57  274.5641
#> segment 18 theta      18         1 119580.84 118997.19 120164.48  297.7836
#> segment 19 theta      19         1 129117.18 128625.40 129608.95  250.9113
#> segment 20 theta      20         1 114845.84 113778.63 115913.05  544.5049
#> segment 21 theta      21         1 110800.29 110577.37 111023.22  113.7396
#> segment 22 theta      22         1 111894.13 110900.55 112887.71  506.9384
#> segment 23 theta      23         1 109595.48 109191.67 109999.28  206.0251
#> segment 24 theta      24         1 112505.95 111157.98 113853.92  687.7520
#> segment 25 theta      25         1 111688.13 110951.88 112424.38  375.6467
#> segment 26 theta      26         1 107527.00 107089.67 107964.32  223.1294
#> segment 27 theta      27         1 111524.77 110234.32 112815.21  658.4030
#> segment 28 theta      28         1 108912.44 107604.79 110220.09  667.1782
#> segment 29 theta      29         1  73923.62  71071.77  76775.47 1455.0520
#> segment 30 theta      30         1 110564.84 109911.94 111217.74  333.1202
#> segment 31 theta      31         1 105222.16 103374.87 107069.45  942.5111
#>            level method
#> segment 1   0.95   wald
#> segment 2   0.95   wald
#> segment 3   0.95   wald
#> segment 4   0.95   wald
#> segment 5   0.95   wald
#> segment 6   0.95   wald
#> segment 7   0.95   wald
#> segment 8   0.95   wald
#> segment 9   0.95   wald
#> segment 10  0.95   wald
#> segment 11  0.95   wald
#> segment 12  0.95   wald
#> segment 13  0.95   wald
#> segment 14  0.95   wald
#> segment 15  0.95   wald
#> segment 16  0.95   wald
#> segment 17  0.95   wald
#> segment 18  0.95   wald
#> segment 19  0.95   wald
#> segment 20  0.95   wald
#> segment 21  0.95   wald
#> segment 22  0.95   wald
#> segment 23  0.95   wald
#> segment 24  0.95   wald
#> segment 25  0.95   wald
#> segment 26  0.95   wald
#> segment 27  0.95   wald
#> segment 28  0.95   wald
#> segment 29  0.95   wald
#> segment 30  0.95   wald
#> segment 31  0.95   wald

(cp_bootstrap_interval <- confint(
  result,
  parm = "cp",
  method = "bootstrap",
  B = 5,
  seed = 10
))
#>    parm index estimate lower upper detection_rate level    method     bootstrap
#> 1    cp     1        7     6     7            1.0  0.95 bootstrap nonparametric
#> 2    cp     2       19    15    19            1.0  0.95 bootstrap nonparametric
#> 3    cp     3      356   225   358            0.8  0.95 bootstrap nonparametric
#> 4    cp     4      448   448   509            0.8  0.95 bootstrap nonparametric
#> 5    cp     5      717   698   738            0.6  0.95 bootstrap nonparametric
#> 6    cp     6      844   822   844            0.8  0.95 bootstrap nonparametric
#> 7    cp     7     1034  1034  1035            1.0  0.95 bootstrap nonparametric
#> 8    cp     8     1070  1070  1071            1.0  0.95 bootstrap nonparametric
#> 9    cp     9     1215  1192  1212            0.8  0.95 bootstrap nonparametric
#> 10   cp    10     1369  1355  1396            1.0  0.95 bootstrap nonparametric
#> 11   cp    11     1428  1424  1441            1.0  0.95 bootstrap nonparametric
#> 12   cp    12     1526  1523  1527            1.0  0.95 bootstrap nonparametric
#> 13   cp    13     1685  1685  1685            1.0  0.95 bootstrap nonparametric
#> 14   cp    14     1866  1866  1866            1.0  0.95 bootstrap nonparametric
#> 15   cp    15     2047  2047  2047            1.0  0.95 bootstrap nonparametric
#> 16   cp    16     2409  2409  2409            1.0  0.95 bootstrap nonparametric
#> 17   cp    17     2469  2469  2469            1.0  0.95 bootstrap nonparametric
#> 18   cp    18     2531  2531  2531            1.0  0.95 bootstrap nonparametric
#> 19   cp    19     2591  2591  2592            1.0  0.95 bootstrap nonparametric
#> 20   cp    20     2777  2777  2784            1.0  0.95 bootstrap nonparametric
#> 21   cp    21     3490  3280  3463            0.6  0.95 bootstrap nonparametric
#> 22   cp    22     3544  3531  3561            0.4  0.95 bootstrap nonparametric
#> 23   cp    23     3656  3656  3656            0.6  0.95 bootstrap nonparametric
#> 24   cp    24     3672    NA    NA            0.0  0.95 bootstrap nonparametric
#> 25   cp    25     3744  3744  3746            1.0  0.95 bootstrap nonparametric
#> 26   cp    26     3855  3855  3856            1.0  0.95 bootstrap nonparametric
#> 27   cp    27     3886  3886  3910            0.8  0.95 bootstrap nonparametric
#> 28   cp    28     3945  3943  3947            1.0  0.95 bootstrap nonparametric
#> 29   cp    29     3963  3963  3963            1.0  0.95 bootstrap nonparametric
#> 30   cp    30     4035  4035  4037            1.0  0.95 bootstrap nonparametric

variance_result <- detect_variance(well_log)
# Wald intervals are not available for variance-family fits.

# ARIMA profile intervals use the same segment-local native likelihood as the
# detector rather than a separate stats::arima refit.
arima_small <- rep(c(0.1, -0.1), 20)
arima_large <- rep(c(2, -2), length.out = 41)
arima_data <- c(0, cumsum(c(arima_small, arima_large)))
arima_result <- detect_arima(
  arima_data,
  order = c(0, 1, 0)
)
arima_profile_interval <- confint(
  arima_result,
  parm = "cp",
  method = "profile",
  level = 0.8,
  window = 1
)