| numspellr | R Documentation |
numspellr() is a universal numeric persistence detector designed to
identify prolonged stability ("spells") and rigidity patterns in numeric
data. The function automatically detects numeric variables from various
data structures (numeric vectors or data frames) and computes persistence
metrics commonly used in rigidity and stickiness analysis.
The output includes interpretable measures such as average spell length, stability ratio, elasticity, and adjustment frequency, accompanied by plain-language interpretations suitable for policy and applied analysis.
numspellr(data, lang = c("indonesia", "english"), min_spell = 2, tol = NULL)
data |
A numeric vector or a data.frame/tibble containing one or more numeric variables. Non-numeric columns are ignored automatically. |
lang |
Language for persistence status labels and interpretation text.
Must be either |
min_spell |
Minimum length (in periods) required for a sequence to be considered a
persistence spell. Default is |
tol |
Optional numeric tolerance threshold for detecting stability.
If |
The function identifies persistence spells as consecutive periods where absolute changes fall below a tolerance threshold.
Metrics computed include:
avg_spell: average duration of stable periods.
median_spell: median duration of stability.
max_spell: longest observed stable period.
stability_ratio: proportion of observations belonging to spells.
elasticity_index: average relative magnitude of changes.
adjustment_frequency: share of periods with meaningful changes.
spell_concentration: dominance of long spells over short ones.
Persistence status is classified into qualitative categories ranging from highly flexible to highly rigid, with labels adapted to the selected language.
A data.frame with one row per numeric variable containing:
Detected data structure type.
Variable identifier.
Variable name.
Average persistence spell length.
Median persistence spell length.
Maximum persistence spell length.
Share of observations in stable spells.
Average relative change magnitude.
Frequency of meaningful adjustments.
Concentration index of persistence spells.
Qualitative persistence category.
Plain-language interpretation suitable for policy analysis.
Joko Nursiyono
Caballero, R. J., & Engel, E. M. R. A. (1993). Microeconomic adjustment hazards and aggregate dynamics. Quarterly Journal of Economics, 108(2), 359–383.
Nakamura, E., & Steinsson, J. (2008). Five facts about prices: A reevaluation of menu cost models. Quarterly Journal of Economics, 123(4), 1415–1464.
diff, rle
x <- c(10, 10, 10, 11, 11, 11, 11, 12)
numspellr(x, lang = "english")
df <- data.frame(
time = 1:8,
value = c(5, 5, 5, 5, 6, 6, 6, 7)
)
numspellr(df, lang = "indonesia")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.