Skip to content

Commit

Permalink
More meaningful error when no obs around tau; Shrink if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
FinYang committed Aug 6, 2023
1 parent f825dbd commit 9bef216
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions R/estimation.R
Expand Up @@ -259,7 +259,6 @@ estimate_yield <- function(data, xgrid, hx,
interest = NULL,
cfp_slist = NULL){
units <- 365

if(min(tau)>min(tau_p) || max(tau) < max(tau_p)){
stop('tau_p entries must lie inside tau')
}
Expand Down Expand Up @@ -326,16 +325,22 @@ estimate_yield <- function(data, xgrid, hx,

if(any(dbar$dbar_denom == 0)) {
problem_tau <- filter(dbar, .data$dbar_denom == 0)$xg
warning("tau values at ", paste(problem_tau, collapse = ", "), " does not have enough obs to estimate yield")

if(!identical(tau_p, tau)) {
if(!(max(tau_p)<=min(problem_tau) || min(tau_p) >= max(problem_tau)))
stop("tau values at ", paste(problem_tau, collapse = ", "),
" does not have enough obs to estimate yield. ",
"Modified tau and tau_p." )
}
warning("tau values at ", paste(problem_tau, collapse = ", "),
" does not have enough obs to estimate yield")
output <- estimate_yield(
data = data,
xgrid = xgrid,
hx = hx,
tau = tau[!tau %in% problem_tau],
ht = ht[!tau %in% problem_tau],
tau_p = tau_p,
htp = htp,
tau_p = tau_p[!tau_p %in% problem_tau],
htp = htp[!tau_p %in% problem_tau],
rgrid = rgrid,
hr = hr)
return(output)
Expand Down

0 comments on commit 9bef216

Please sign in to comment.