##
## Many of the examples below illustrate the above
## function(s) on random data. Thus it can be fun
## (and informative) to run them several times.
##
#
# simple linear response
#
# input and predictive data
X <- seq(0,1,length=50)
XX <- seq(0,1,length=99)
Z <- 1 + 2*X + rnorm(length(X),sd=0.25)
# out <- blm(X=X, Z=Z, XX=XX) # try Linear Model with tgp
p <- tgp.default.params(2)
p$tree <- c(0,0,10) # no tree
p$gamma <- c(-1,0.2,0.7) # force llm
out <- tgp(X=X,Z=Z,XX=XX,params=p)
plot(out) # plot the surface
#
# 1-d Example
#
# construct some 1-d nonstationary data
X <- seq(0,20,length=100)
XX <- seq(0,20,length=99)
Z <- (sin(pi*X/5) + 0.2*cos(4*pi*X/5)) * (X <= 9.6)
lin <- X>9.6;
Z[lin] <- -1 + X[lin]/10
Z <- Z + rnorm(length(Z), sd=0.1)
# out <- btlm(X=X, Z=Z, XX=XX) # try Linear CART with tgp
p <- tgp.default.params(2)
p$gamma <- c(-1,0.2,0.7) # force llm
out <- tgp(X=X,Z=Z,XX=XX,params=p)
plot(out) # plot the surface
tgp.trees(out) # plot the MAP trees
# out <- btgp(X=X, Z=Z, XX=XX) # use a treed GP with tgp
p <- tgp.default.params(2)
p$gamma <- c(0,0.2,0.7) # force no llm
out <- tgp(X=X,Z=Z,XX=XX,params=p)
plot(out) # plot the surface
tgp.trees(out) # plot the MAP trees
#
# 2-d example
# (using the isotropic correlation function)
#
# construct some 2-d nonstationary data
exp2d.data <- exp2d.rand()
X <- exp2d.data$X; Z <- exp2d.data$Z
XX <- exp2d.data$XX
# try a GP with tgp
# out <- bgp(X=X, Z=Z, XX=XX, corr="exp")
p <- tgp.default.params(3)
p$tree <- c(0,0,10) # no tree
p$gamma <- c(0,0.2,0.7) # no llm
p$corr <- "exp"
out <- tgp(X=X,Z=Z,XX=XX,params=p)
plot(out) # plot the surface
# try a treed GP LLM with tgp
# out <- btgpllm(X=X,Z=Z,XX=XX,corr="exp")
p <- tgp.default.params(3)
p$corr <- "exp"
out <- tgp(X=X,Z=Z,XX=XX,params=p)
plot(out) # plot the surface
tgp.trees(out) # plot the MAP trees
#
# Motorcycle Accident Data
#
# get the data
require(MASS)
# try a custom treed GP LLM with tgp, without m0r1
p <- tgp.default.params(2)
p$bprior <- "b0" # beta linear prior for common mean
p$nug.p <- c(1.0,0.1,10.0,0.1) # mixture nugget prior
out <- tgp(X=mcycle[,1], Z=mcycle[,2], params=p,
BTE=c(2000,22000,2)) # run mcmc longer
plot(out) # plot the surface
tgp.trees(out) # plot the MAP trees
# for other examples try the demos or the vignette
Run the code above in your browser using DataLab