comp_mean: Compositional mean

View source: R/comp_mean.R

comp_meanR Documentation

Compositional mean

Description

Calculates the compositional mean of a dataset.

Usage

comp_mean(
  data,
  comp_labels,
  rounded_zeroes = TRUE,
  det_limit = NULL,
  units = "unitless",
  specified_units = NULL
)

Arguments

data

Dataset to calculate compositional mean of.

comp_labels

The labels of the compositional parts.

rounded_zeroes

Are zeroes rounded zeroes?

det_limit

Detection limit if zeroes are to be imputed. This is needed when rounded_zeroes is TRUE. It should be the minimum measurable value in the compositional columns of data, and should be on the same scale as the (input) compositional columns. If rounded_zeroes is TRUE and there are zero values in the data, it throws an error. If the compositional columns do not have a constant sum, it also throws an error, as it cannot be automatically rescaled. Embedded zero imputation is for convenience only. It may be advisable to perform zero imputation prior to working with the data, particularly in more complex cases.

units

What should the units of the compositional variables be in any output? Currently available are "unitless" (where working in terms of proportions), "hr/day", "hr/wk", "min/day", "min/wk" and "specified", in which case the specified_units argument should be set. Note that this doesn't specify the input units, as this is not relevant for any function.

specified_units

If units are being specified via the composition sum, this is where it is done. It should be a vector where the first argument is a string describing the units, and the second argument is the expected sum of a composition e.g. c("hr/day", 24)

Value

Vector which is the compositional mean.

Examples

comp_mean(data = simdata, # this is the dataset
comp_labels = c("vigorous", "moderate", "light", "sedentary", "sleep"), # this is the labels
# of the compositional columns, which we specified above
rounded_zeroes = TRUE, # this option specifies that we'll treat the zeroes
# as rounded zeroes i.e. we'll impute them.
det_limit = 0.00119, # This is the det_limit for zero imputation
units = "hr/day" # this is the units. There are pre-specified options "hr/day",
# "hr/wk", "min/day", "min/wk" and "unitless".
# If you set units = "specified", you can also specify your own units using
# specified = c("my_units_name", sum of a composition in these units)
)

OxWearables/epicoda documentation built on Dec. 7, 2022, 9:07 p.m.