## fit a Gaussian process ##
x1 = rep(-5:5,3); x2 = kronecker(1:3, rep(1,11))
y = sin(x1) + 2*x2 + rnorm(length(x1),sd=.001)
fit = mlegp(cbind(x1,x2), y)
## plot all main effects
plotMainEffects(fit)
## library adapt must be loaded for FANOVA=TRUE
## plot all main effects with FANOVA contributions in legend
plotMainEffects(fit, FANOVA = TRUE)
## plotMainEffects for x2 'manually'
main = plotMainEffects(fit, effects = 2, no.plot=TRUE)
plot(main$index, main$preds, xlab = "x2", ylab = "predicted output")
## fit multiple Gaussian processes ##
x = seq(-5,5)
z1 = 10 - 5*x + rnorm(length(x))
z2 = 4 - 5*x + rnorm(length(x))
z3 = 7*sin(x) + rnorm(length(x))
fitMulti = mlegp(x, cbind(z1,z2,z3), param.names = "x")
# for each gaussian process, plot main effects for parameter 1
plotMainEffects(fitMulti, effects = 1)
# plot the main effect of the first parameter for gaussian processes 1 and 3
plotMainEffects(fitMulti, effects = 1, gp.nums = c(1,3))
## fit multiple Gaussian processes using principle component weights ##
x = seq(-5,5,by=.2)
p = 1:50
y = matrix(0,length(p), length(x))
for (i in p) {
y[i,] = sin(x) + i + rnorm(length(x), sd = .01)
}
numPCs = 2
fitPC = mlegp(p, t(y), PC.num = numPCs)
# plot main effects on the functional output ##
plotMainEffects(fitPC, effects = 1, xValues = x)Run the code above in your browser using DataLab