library(dbarts)
library(MASS)
data(mcycle)
y.train = mcycle$accel
x.train = mcycle$times
#x.train = (1:150)/151
#y.train = ifelse(x.train>0.2,-50 + 100*sin(6*(x.train-0.1)), 0) + rnorm(length(x.train), 0, 1 + 30*(x.train>0.2))
plot(x.train, y.train)

bf = BayesTree::bart(x.train, y.train)
##
##
## Running BART with numeric y
##
## number of trees: 200
## Prior:
## k: 2.000000
## degrees of freedom in sigma prior: 3
## quantile in sigma prior: 0.900000
## power and base for tree prior: 2.000000 0.950000
## use quantiles for rule cut points: 0
## data:
## number of training observations: 133
## number of test observations: 0
## number of explanatory variables: 1
##
##
## Cutoff rules c in x<=c vs x>c
## Number of cutoffs: (var: number of possible c):
## (1: 100)
##
##
## Running mcmc loop:
## iteration: 100 (of 1100)
## iteration: 200 (of 1100)
## iteration: 300 (of 1100)
## iteration: 400 (of 1100)
## iteration: 500 (of 1100)
## iteration: 600 (of 1100)
## iteration: 700 (of 1100)
## iteration: 800 (of 1100)
## iteration: 900 (of 1100)
## iteration: 1000 (of 1100)
## iteration: 1100 (of 1100)
## time for loop: 5
##
## Tree sizes, last iteration:
## 3 3 3 2 2 2 2 2 4 3 3 2 3 2 4 3 2 1 2 4
## 2 2 2 3 2 2 2 3 2 2 2 2 4 2 2 2 2 2 2 3
## 4 3 2 3 2 2 2 2 2 2 2 2 3 3 3 4 1 2 2 2
## 2 3 2 2 2 2 2 2 2 2 3 1 1 3 2 2 3 2 2 2
## 2 4 2 2 3 3 2 2 3 3 3 3 3 3 2 3 2 2 3 2
## 3 3 3 2 2 2 3 2 3 2 3 1 2 3 3 2 2 3 2 3
## 2 2 3 4 2 3 3 2 1 3 1 3 4 3 2 2 2 2 2 2
## 4 5 3 2 2 2 2 2 2 2 3 2 2 3 2 2 3 2 2 2
## 3 1 2 2 2 2 2 2 2 4 2 3 3 3 3 2 4 3 2 1
## 3 3 2 2 2 2 3 4 3 2 2 2 3 2 2 2 2 3 2 4
## Variable Usage, last iteration (var:count):
## (1: 283)
## DONE BART
bfd = dbarts::bart(x.train, y.train)
##
## Running BART with numeric y
##
## number of trees: 200
## Prior:
## k: 2.000000
## degrees of freedom in sigma prior: 3.000000
## quantile in sigma prior: 0.900000
## power and base for tree prior: 2.000000 0.950000
## use quantiles for rule cut points: false
## data:
## number of training observations: 133
## number of test observations: 0
## number of explanatory variables: 1
##
##
## Cutoff rules c in x<=c vs x>c
## Number of cutoffs: (var: number of possible c):
## (1: 100)
## Running mcmc loop:
## iteration: 100 (of 1000)
## iteration: 200 (of 1000)
## iteration: 300 (of 1000)
## iteration: 400 (of 1000)
## iteration: 500 (of 1000)
## iteration: 600 (of 1000)
## iteration: 700 (of 1000)
## iteration: 800 (of 1000)
## iteration: 900 (of 1000)
## iteration: 1000 (of 1000)
## total seconds in loop: 0.784895
##
## Tree sizes, last iteration:
## 2 2 1 1 4 2 2 2 2 4 3 1 2 3 1 2 2 3 1 2
## 1 2 2 3 1 4 2 2 2 4 3 1 1 2 3 2 2 2 3 4
## 2 3 2 2 2 2 3 3 2 2 2 3 2 5 1 1 2 3 2 3
## 2 2 2 2 1 3 2 1 2 3 3 2 1 3 2 4 2 2 2 2
## 2 1 3 2 3 3 3 3 1 1 6 3 4 3 2 1 1 2 2 2
## 1 2 3 2 2 2 2 1 3 2 2 3 2 2 2 4 2 3 2 2
## 3 1 2 1 2 2 2 1 1 2 6 3 1 3 4 3 2 2 2 1
## 2 1 3 2 1 4 2 3 3 4 2 4 3 3 3 2 2 1 2 3
## 3 3 4 2 1 2 2 2 2 4 2 1 2 3 1 4 3 4 2 3
## 1 3 2 2 1 1 4 2 3 3 1 1 1 2 2 4 3 2 2 3
##
## Variable Usage, last iteration (var:count):
## (1: 257)
## DONE BART
plot(x.train, bf$yhat.train.mean, type='l')
lines(x.train, bfd$yhat.train.mean, type='l', col='red')
points(x.train, y.train)
