Skip to contents

score_le8() returns an essential8_scores object: the input data frame (or tibble), with its original class, plus the score columns. The extra class provides summary(), tidy(), plot(), and, with dplyr loaded, summarise().

Row-wise operations such as filter(), mutate(), arrange(), joins, and bind_rows() keep the class. group_by(), summarise() with expressions, as_tibble(), pivot_longer(), and saving to and reading from a file drop it. as_le8_scores() adds the class back to any data frame that still contains the score columns. It does not rescore or change any values.

A data frame with an .imp column, such as saved results from score_le8_imputed(), becomes an essential8_imputed_scores object, so its methods pool across imputations again.

Usage

as_le8_scores(x)

Arguments

x

A data frame containing the columns returned by score_le8(): the eight component scores (diet_score, physical_activity_score, nicotine_score, sleep_score, bmi_score, blood_lipids_score, blood_glucose_score, and blood_pressure_score), n_components, le8_composite_score, le8_category, and le8_population.

Value

x, with the class essential8_scores added, and essential8_imputed_scores too when x has an .imp column.

See also

Examples

scores <- score_le8(
  data.frame(age = 45, sleep_hours = 7.5, bmi = 24, bmi_profile = "general"),
  min_components = 2
)
#> Warning: ! Some LE8 components could not be calculated for any observations.
#> ✖ Diet
#> ✖ Physical activity
#> ✖ Nicotine exposure
#> ✖ Blood lipids
#> ✖ Blood glucose
#> ✖ Blood pressure
#> ℹ Overall LE8 composite scores will use the available components, subject to
#>   `min_components`.
plain <- as.data.frame(scores)
summary(as_le8_scores(plain))
#> LE8 scores: 1 row (1 adult)
#> Diet method: mepa; min_components: 2
#> Composite score available for 1 of 1; all 8 components for 0.
#> 
#>                   n  mean sd median         IQR       range
#> LE8 composite     1 100.0  -  100.0 100.0-100.0 100.0-100.0
#> Diet              0     -  -      -           -           -
#> Physical activity 0     -  -      -           -           -
#> Nicotine exposure 0     -  -      -           -           -
#> Sleep             1 100.0  -  100.0 100.0-100.0 100.0-100.0
#> BMI               1 100.0  -  100.0 100.0-100.0 100.0-100.0
#> Blood lipids      0     -  -      -           -           -
#> Blood glucose     0     -  -      -           -           -
#> Blood pressure    0     -  -      -           -           -
#> 
#> Category (rows with a composite score):
#>            n percent
#>   low      0    0.0%
#>   moderate 0    0.0%
#>   high     1  100.0%