Skip to content

Commit

Permalink
Use clinelist rather than truncated_linelist
Browse files Browse the repository at this point in the history
  • Loading branch information
athowes committed May 15, 2024
1 parent 6930bfe commit d0ed63e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions R/observe.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ observe_process <- function(linelist) {
return(clinelist)
}

#' Filter observations based on a observation time of secondary events
#' Filter observations based on the observation time of secondary events
#'
#' @family observe
#' @export
filter_obs_by_obs_time <- function(linelist, obs_time) {
truncated_linelist <- data.table::copy(linelist)
truncated_linelist[, obs_at := obs_time]
truncated_linelist[, obs_time := obs_time - ptime]
truncated_linelist[, censored_obs_time := obs_at - ptime_lwr]
truncated_linelist[, censored := "interval"]
truncated_linelist <- truncated_linelist[stime_upr <= obs_at]
clinelist <- data.table::copy(linelist)
clinelist[, obs_at := obs_time]
clinelist[, obs_time := obs_time - ptime]
clinelist[, censored_obs_time := obs_at - ptime_lwr]
clinelist[, censored := "interval"]
clinelist <- clinelist[stime_upr <= obs_at]

return(truncated_linelist)
return(clinelist)
}

#' Filter observations based on the observation time of primary events
Expand All @@ -48,28 +48,29 @@ filter_obs_by_ptime <- function(linelist, obs_time,
obs_at <- match.arg(obs_at)

pfilt_t <- obs_time
truncated_linelist <- data.table::copy(linelist)
clinelist <- data.table::copy(linelist)

truncated_linelist[, censored := "interval"]
truncated_linelist <- truncated_linelist[ptime_upr <= pfilt_t]
clinelist[, censored := "interval"]
clinelist <- clinelist[ptime_upr <= pfilt_t]

if (obs_at == "obs_secondary") {
# Update observation time to be the same as the maximum secondary time
truncated_linelist[, obs_at := stime_upr]
clinelist[, obs_at := stime_upr]
} else if (obs_at == "max_secondary") {
truncated_linelist[, obs_at := stime_upr |> max() |> ceiling()]
clinelist[, obs_at := stime_upr |> max() |> ceiling()]
}

# make observation time as specified
truncated_linelist[, obs_time := obs_at - ptime]
clinelist[, obs_time := obs_at - ptime]
# Assuming truncation at the beginning of the censoring window
truncated_linelist[, censored_obs_time := obs_at - ptime_lwr]
clinelist[, censored_obs_time := obs_at - ptime_lwr]

# set observation time to artifial observation time
if (obs_at == "obs_secondary") {
truncated_linelist[, obs_at := pfilt_t]
clinelist[, obs_at := pfilt_t]
}
return(truncated_linelist)

return(clinelist)
}

#' Pad zero observations as unstable in a lognormal distribution
Expand Down

0 comments on commit d0ed63e

Please sign in to comment.