is_categorical: Check if a variable is categorical

View source: R/all_generic.R

is_categoricalR Documentation

Check if a variable is categorical

Description

Determines if a variable represents categorical (factor-based) rather than continuous data. For event terms, categorical variables are those that have discrete factor levels (like trial types or conditions) rather than numeric values. For example, stimulus types ("face", "house") would be categorical, while reaction times would be continuous. This function is complementary to is_continuous().

Usage

is_categorical(x)

Arguments

x

The object to check (typically an event_term, event_seq, or event_matrix)

Value

Logical; TRUE if the variable is categorical (factor-based), FALSE if continuous

See Also

is_continuous(), event_term()

Other variable_type: is_continuous()

Examples

# Create event terms with different types

# Categorical event (factor)
event_data <- data.frame(
  condition = factor(c("face", "house", "face", "house")),
  onsets = c(1, 10, 20, 30),
  run = c(1, 1, 1, 1)
)
cat_term <- event_term(
  list(condition = event_data$condition),
  onsets = event_data$onsets,
  blockids = event_data$run
)
is_categorical(cat_term)  # Returns: TRUE

# Continuous event (numeric)
event_data$intensity <- c(0.8, 1.2, 0.9, 1.1)  # stimulus intensity
cont_term <- event_term(
  list(intensity = event_data$intensity),
  onsets = event_data$onsets,
  blockids = event_data$run
)
is_categorical(cont_term)  # Returns: FALSE

bbuchsbaum/fmrireg documentation built on March 1, 2025, 11:20 a.m.