CV-selected penalties from a TROP penalty-sensitivity grid
Source:R/sensitivity.R
selected_lambda.RdReturns the cross-validation-selected penalties of a trop_sensitivity()
grid — the grid cell minimising the CV loss — as a list(time=, unit=, nn=), the same shape trop() accepts for its lambda argument. So the
data-driven choice on a grid can be fed straight back into a fit, e.g.
trop(..., lambda = selected_lambda(g)), without digging the values out of
attr(g, "selected") by hand.
Arguments
- grid
A
cf_trop_gridfromtrop_sensitivity().
Value
A named list with the selected time, unit and nn penalties. The
full selected row (including the ATT and CV loss there) remains available in
attr(grid, "selected").
Examples
# \donttest{
df <- sim_panel(N = 14, T = 9, n_treated = 3, t0 = 6, att = 2, seed = 1)
g <- trop_sensitivity(df, "y", "w", "id", "t",
lambda_time = c(0, 0.25, 1),
control = trop_control(n_cv_cells = 5L, cv_cycles = 1L,
tol = 1e-3, seed = 1L))
selected_lambda(g)
#> $time
#> [1] 1
#>
#> $unit
#> [1] 0
#>
#> $nn
#> [1] 4.658485
#>
# }