Describes a subset of the UKB sample, relative to a reference subsample, on the UKB primary demographics (sex, age, ethnicity, Townsend deprivation) and assessment centre and current employment status. The "subset" and "reference" samples are defined either by a variable of interest (nonmiss.var - those with data form the "subset" of interest and samples with missing data are the "reference" sample), or a logical vector (subset.var - where TRUE values define the "subset" and FALSE the "reference" samples) . This function is intended as an exploratory data analysis and quality control tool.

ukb_context(
  data,
  nonmiss.var = NULL,
  subset.var = NULL,
  bar.position = "fill",
  sex.var = "sex_f31_0_0",
  age.var = "age_when_attended_assessment_centre_f21003_0_0",
  socioeconomic.var = "townsend_deprivation_index_at_recruitment_f189_0_0",
  ethnicity.var = "ethnic_background_f21000_0_0",
  employment.var = "current_employment_status_f6142_0_0",
  centre.var = "uk_biobank_assessment_centre_f54_0_0"
)

Arguments

data

A UKB dataset constructed with ukb_df.

nonmiss.var

The variable of interest which defines the "subset" (samples with data) and "reference" (samples without data, i.e., NA) samples.

subset.var

A logical vector defining a "subset" (TRUE) and "reference" subset (FALSE). Length must equal the number of rows in your data.

bar.position

This argument is passed to the position in geom_bar. The default value is "fill" which shows reference and subset of interest as proportions of the full dataset. Useful alternatives are "stack" for counts and "dodge" for side-by-side bars.

sex.var

The variable to be used for sex. Default value "sex_f31_0_0".

age.var

The variable to be use for age. Default value "age_when_attended_assessment_centre_f21003_0_0".

socioeconomic.var

The variable to be used for socioeconomic status. Default value is "townsend_deprivation_index_at_recruitment_f189_0_0".

ethnicity.var

The variable to be used for ethnicity. Default value "ethnic_background_f21000_0_0".

employment.var

The variable to be used for employment status. Default value "current_employment_status_f6142_0_0".

centre.var

The variable to be used for assessment centre. Default value "uk_biobank_assessment_centre_f54_0_0".

See also

Examples

if (FALSE) {
# Compare those with data to those without
ukb_context(my_ukb_data, nonmiss.var = "my_variable_of_interest")

# Define a subset of interest as a logical vector
subgroup_of_interest <- (my_ukb_data$bmi > 40 & my_ukb_data$age < 50)
ukb_context(my_ukb_data, subset.var = subgroup_of_interest)
}