# Similar to example in mrct.sparse() helpfile
# Fix seed for reproducibility
set.seed(123)
# Sample outlying indices
cont.ind <- sample(1:50,size=10)
# Generate 50 sparse curves on the interval [0,1] at 10 timepoints with 20% outliers
y <- mrct.rgauss(x.grid=seq(0,1,length.out=10), N=50, model=1,
outliers=cont.ind, method="linear")
# Visualize curves (regular curves grey, outliers black)
colormap <- rep("grey",50); colormap[cont.ind] <- "black"
matplot(x = seq(0,1,length.out=10), y = t(y), type="l", lty="solid",
col=colormap, xlab="t",ylab="")
# Run sparse MRCT
sparse.mrct.y <- mrct.sparse(data = y, nbasis = 10, h = 0.75, new.p = 50,
alpha = 0.1, initializations = 10, criterion = "sum" )
# Visualize alpha-Mahalanobis distances and smoothed curves
# Colorinformation according to estimated outliers (grey regular, black irregular)
mrct.sparse.plot(mrct.sparse.object = sparse.mrct.y)
Run the code above in your browser using DataLab