# Create functional data with an outlier
t <- seq(0, 1, length.out = 50)
X <- matrix(0, 20, 50)
for (i in 1:19) X[i, ] <- sin(2*pi*t) + rnorm(50, sd = 0.1)
X[20, ] <- sin(2*pi*t) + 5 # Large outlier
fd <- fdata(X, argvals = t)
# Compare mean vs geometric median
mean_curve <- mean(fd)
gmed_curve <- gmed(fd)
# The geometric median is less affected by the outlier
Run the code above in your browser using DataLab