View source: R/initialize_states.R
repeated_median_line | R Documentation |
Fit a level and trend to a time series using Repeated Median Regression
repeated_median_line(x)
x |
Numeric vector representing a time series |
A list of intercept
, slope
, fitted
values, and residuals
https://en.wikipedia.org/wiki/Repeated_median_regression
y <- 1:100 + rnorm(100)
tulip:::repeated_median_line(y)
y <- 1:28 + rt(n = 28, df = 1)
y_idx <- 1:length(y)
lm_fit <- lm(y ~ 1 + y_idx)
rm_fit <- tulip:::repeated_median_line(y)
plot(y, pch = 19, cex = 0.5)
abline(a = 0, b = 1, lty = 2) # ideal fit
abline(
a = lm_fit$coefficients[1],
b = lm_fit$coefficients[2],
col = "darkblue"
)
abline(
a = rm_fit$intercept,
b = rm_fit$slope,
col = "darkorange"
)
y <- as.numeric(RobStatTM::resex)
y_idx <- 1:length(y)
lm_fit <- lm(y ~ 1 + y_idx)
rm_fit <- tulip:::repeated_median_line(y)
plot(y, pch = 19, cex = 0.5)
abline(
a = lm_fit$coefficients[1],
b = lm_fit$coefficients[2],
col = "darkblue"
)
abline(a = rm_fit$intercept, b = rm_fit$slope, col = "darkorange")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.