Learn R Programming

rbart (version 1.0)

simdat: Simulated Example

Description

Simulated data with nonlinear mean and heteroskedasticity.

Usage

data("simdat")

Arguments

Format

x

simulated train x values

y

simulated train y values

xp

simulated test xp values

yp

simulated test yp values

fx

true f evaluated on train x

sx

true s evaluated on train x

fxp

true f evaluated on test xp

sxp

true s evaluated on test xp

Details

The simulated data in simdat was generated using the code:

##simulate data set.seed(99)

# train data n=500 #train data sample size p=1 #just one x x = matrix(sort(runif(n*p)),ncol=p) #iid uniform x values fx = 4*(x[,1]^2) #quadratric function f sx = .2*exp(2*x[,1]) # exponential function s y = fx + sx*rnorm(n) # y = f(x) + s(x) Z

#test data (the p added to the variable names is for predict) np=1000 #test data sample size xp = matrix(sort(runif(np*p)),ncol=p) fxp = 4*(xp[,1]^2) sxp = .2*exp(2*xp[,1]) yp = fxp + sxp*rnorm(np)

Examples

Run this code
# NOT RUN {
data(simdat)

## plot x vs y with f(x) and f(x) +/- 2s(x) for train and test simulated data
##train
plot(simdat$x,simdat$y,xlab="x",ylab="y")
##test
points(simdat$xp,simdat$yp,col="red",pch=2)
lines(simdat$xp,simdat$fxp,col="blue",lwd=2)
lines(simdat$xp,simdat$fxp+2*simdat$sxp,col="blue",lwd=2,lty=2)
lines(simdat$xp,simdat$fxp-2*simdat$sxp,col="blue",lwd=2,lty=2)
legend("topleft",legend=c("train","test"),pch=c(1,2),col=c("black","red"))
# }

Run the code above in your browser using DataLab