measurement: Get / Set measurement levels for declared objects

measurementR Documentation

Get / Set measurement levels for declared objects

Description

Functions to extract information about the measurement levels of a variable (if already present), or to specify such measurement levels.

Usage

measurement(x)

measurement(x) <- value

Arguments

x

A declared vector.

value

A single character string of measurement levels, separated by commas.

Details

This function creates an attribute called "measurement" to a declared This object, as an optional feature, at this point for purely aesthetic reasons. attribute might become useful in the future to (automatically) determine if a declared object is suitable for a certain statistical analysis, for instance regression requires quantitative variables, while some declared objects are certainly categorical despite using numbers to denote categories.

It distinguishes between "categorical" and "quantitative" types of variables, and additionally recognizes "nominal" and "ordinal" as categorical, and similarly recognizes "interval", "ratio", "discrete" and "continuous" as quantitative.

The words "qualitative" is treated as a synonym for "categorical", and the words "metric" and "numeric" are treated as synonyms for "quantitative", respectively.

Value

A character vector.

See Also

Other labelling functions: drop_undeclare, labels()

Examples

x <- declared(
    c(-2, 1:5, -1),
    labels = c(Good = 1, Bad = 5, DK = -1),
    na_values = c(-1, -2),
    label = "Test variable"
)

x

measurement(x)

# automatically recognized as categorical
measurement(x) <- "ordinal"

measurement(x)

# the same with
measurement(x) <- "categorical, ordinal"

set.seed(1890)
x <- declared(
    sample(c(18:90, -91), 20, replace = TRUE),
    labels = c("No answer" = -91),
    na_values = -91,
    label = "Respondent's age"
)

# automatically recognized as quantitative
measurement(x) <- "discrete"

measurement(x)

# the same with
measurement(x) <- "metric, discrete"


declared documentation built on May 29, 2024, 12:09 p.m.