# NOT RUN {
library(PivotalR)
<!-- %% @test .port Database port number -->
<!-- %% @test .dbname Database name -->
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)
## use double values as the time stamp
## Any values that can be ordered will work
example_time_series <- data.frame(id =
seq(0,1000,length.out=length(ts)),
val = arima.sim(list(order=c(2,0,1), ar=c(0.7,
-0.3), ma=0.2), n=1000000) + 3.2)
x <- as.db.data.frame(example_time_series, field.types = list(id="double
precision", val = "double precision"), conn.id = cid)
dim(x)
names(x)
## use formula
s <- madlib.arima(val ~ id, x, order = c(2,0,1))
s
## delete s and the 3 tables: model, residuals and statistics
delete(s)
s # s does not exist any more
## do not use formula
s <- madlib.arima(x$val, x$id, order = c(2,0,1))
s
lookat(sort(s$residuals, F, s$residuals$tstamp), 10)
lookat(s$model)
lookat(s$statistics)
## 10 forecasts
pred <- predict(s, n.ahead = 10)
lookat(sort(pred, F, pred$step_ahead), "all")
## Use expressions
s <- madlib.arima(val+2 ~ I(id + 1), x, order = c(2,0,1))
db.disconnect(cid, verbose = FALSE)
# }
Run the code above in your browser using DataLab