File:Sliding Window Error Metrics Loglog Normal Data.png

Original file (1,440 × 1,200 pixels, file size: 309 KB, MIME type: image/png)

Summary

Description
English: This image presents a line plot of three error metrics (Mean Absolute Error - MAE, Root Mean Square Error - RMSE, and Mean Absolute Logarithmic Error - MALE) calculated over a sliding window of size 28, plotted against the independent variable (x). Each error metric is represented by a different color, with the corresponding smoothed line overlaying the original line. The y-axis is limited to a range of 0 to 2.5.
Date
Source Own work
Author Talgalili
# Reproducible R code

# Load necessary libraries
library(ggplot2)
library(patchwork)

# Set seed for reproducibility
set.seed(123)

# Generate data
n <- 10000
x <- sort(runif(n, min = 1, max = 100))
intercept <- 0.000001
slope <- 0.5
y_true_log <- intercept + slope * log10(x)
noise <- rnorm(n, mean = 0, sd = .1)
y_observed_log <- y_true_log + noise
y_observed <- 10^y_observed_log
y_true <- 10^y_true_log

# Create data frame
df <- data.frame(x = x, y_true = y_true, y_observed = y_observed)

# Load necessary libraries
library(dplyr)
library(ggplot2)
library(zoo)

# Define window size
window_size <- 28

# Calculate error metrics over sliding window
df <- df %>%
  arrange(x) %>%
  mutate(MAE = rollapply(abs(y_true - y_observed), width = window_size, FUN = mean, align = "right", fill = NA),
         RMSE = sqrt(rollapply((y_true - y_observed)^2, width = window_size, FUN = mean, align = "right", fill = NA)),
         MALE = rollapply(abs(log10(y_true) - log10(y_observed)), width = window_size, FUN = mean, align = "right", fill = NA))

# Load necessary library
library(tidyr)

# Reshape data to long format
df_long <- df %>%
  gather(key = "error_type", value = "error_value", MAE, RMSE, MALE)

options(
  repr.plot.width  = 12,   # in inches (default = 7)
  repr.plot.height = 10   # in inches (default = 7)
)

# Plot error metrics
ggplot(df_long, aes(x = x, y = error_value, color = error_type)) +
  geom_line(alpha = .5) +
  geom_smooth() +
#   scale_x_log10() +
#   scale_y_log10() + 
  coord_cartesian(ylim = c(0, 2.5)) + # Set the limits of the plot without excluding obs
  theme_bw() + theme(text = element_text(size = 25)) +
  theme(legend.position="bottom") +

  labs(x = 'X', y = 'Error', title = 'Sliding Window Analysis of Error Metrics\nin Loglog Normal Data')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

Captions

Sliding Window Analysis of Error Metrics in Loglog Normal Data

Items portrayed in this file

depicts

15 April 2024

image/png

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current11:31, 15 April 2024Thumbnail for version as of 11:31, 15 April 20241,440 × 1,200 (309 KB)TalgaliliFix header
11:28, 15 April 2024Thumbnail for version as of 11:28, 15 April 20241,440 × 1,200 (312 KB)TalgaliliUploaded own work with UploadWizard

Metadata