filter_na_strata: Remove missing values and ensure case-control per stratum

View source: R/filter_na_strata.R

filter_na_strataR Documentation

Remove missing values and ensure case-control per stratum

Description

Remove strata for which there are only 1s (used points, presence) or only 0s (available points, background or absence).

Usage

filter_na_strata(f, data)

Arguments

f

⁠[formula]⁠
Formula for model fitting.

data

⁠[data.frame]⁠
Data set to be checked.

Value

Cleaned data.frame, removing from the input data the rows with NA in any of the columns and all the strata for which there are only presences or only absences.

References

amt::remove_incomplete_strata()

Examples

library(survival)
# create test dataset
test1 <- data.frame(case = c(0,0,1,0,1,1,0,1,NA,1),
                    x = c(0,2,1,2,1,0,1,0,0,1),
                    step_id = c(0,0,0,0,1,1,1,2,2,2))
# Remove NAs
f <- case ~ x + strata(step_id)
filter_na_strata(f, test1)

# Fit a stratified model
if(FALSE) {
  # with no NAs; necessary if using glmnet
  coxph(Surv(rep(1, length(case)), case) ~ x + strata(step_id), filter_na_strata(f, test1))
  # This differs from that
  coxph(Surv(rep(1, length(case)), case) ~ x + strata(step_id), test1)
}

NINAnor/oneimpact documentation built on June 14, 2025, 12:27 a.m.