README.md

gptrendR

Estimates trend indices for time series data using Gaussian Process regression

library(devtools)
install_github('aejensen/gptrendR')

Simulate data from a latent Gaussian Process

library(gptrendR)

set.seed(123456)
tObs <- seq(0,1, length.out = 100)
sim <- simulateGP(tObs, seCov, c(2, 0.1), 0.05, deriv=TRUE)

Fit the GP model

fit <- GP(sim$t, sim$y, seCov)

Smoothing example

tEval <- seq(0, 1, length.out=200)
p <- gpPrediction2(tEval, sim$t, sim$y, seCov, fit$m, fit$theta, fit$sigma2, nSim = 2.5*10^4)

par(mfrow=c(1,2), bty="n")
plot(fit, type="n")
plotBand(p$f$t, apply(p$postPred$sim, 1, quantile, p = 0.025),
                apply(p$postPred$sim, 1, quantile, p = 0.975),
                col = "darkgray")
plotBand(p$f$t, apply(p$f$sim, 1, quantile, p = 0.025),
                apply(p$f$sim, 1, quantile, p = 0.975),
                col = "lightgray")
points(sim$t, sim$y, pch=19, cex=0.5)
lines(p$f$t, p$f$mu, lwd=2)
curve(sim$f(x), 0, 1, add = TRUE, lwd = 2, col = 2)

plot(p$df$t, p$df$mu, type="n")
plotBand(p$df$t, apply(p$df$sim, 1, quantile, p = 0.025),
                 apply(p$df$sim, 1, quantile, p = 0.975),
                 col = "lightgray")
lines(p$df$t, p$df$mu, lwd = 2, col = 2)


aejensen/gptrendR documentation built on May 31, 2019, 1:49 a.m.