Separates elements in a statistical formula
Source:R/extract_response_strata.R
extract_response_strata.Rd
This function separates the response variable, the strata variable, and the covariates/predictors in a statistical formula.
Value
A list
with strings representing the response variable (response
),
the stratum variable (strata
),
and possibly all explanatory variables (covars
), if covars = TRUE
, as shown
in the formula.
Examples
# formula with strata
f <- formula(use ~ exp1 + exp2 + exp1:exp2 + strata(id))
extract_response_strata(f)
#> $response
#> [1] "use"
#>
#> $strata
#> [1] "id"
#>
extract_response_strata(f, covars = TRUE)
#> $response
#> [1] "use"
#>
#> $strata
#> [1] "id"
#>
#> $covars
#> [1] "exp1 + exp2 + exp1:exp2"
#>
# formula without strata
f2 <- formula(use ~ exp1 + exp2 + exp1:exp2)
extract_response_strata(f2, covars = TRUE)
#> $response
#> [1] "use"
#>
#> $strata
#> [1] ""
#>
#> $covars
#> [1] "exp1 + exp2 + exp1:exp2"
#>