RDocumentation: StructTS
  • AI Chat
  • Code
  • Report
  • Spinner

    Note that this notebook was automatically generated from an RDocumentation page. It depends on the package and the example code whether this code will run without errors. You may need to edit the code to make things work.

    if(!require('stats')) {
        install.packages('stats')
        library('stats')
    }
    ## see also JohnsonJohnson, Nile and AirPassengers
    require(graphics)
    
    trees <- window(treering, start = 0)
    (fit <- StructTS(trees, type ="trend", init = c(1,2,3)))
    plot(trees)
    lines(fitted(fit), col = "green")
    tsdiag(fit)
    
    (fit <- StructTS(log10(UKgas), type = "BSM"))
    par(mfrow = c(4, 1)) # to give appropriate aspect ratio for next plot.
    plot(log10(UKgas))
    plot(cbind(fitted(fit), resids=resid(fit)), main = "UK gas consumption")
    
    ## keep some parameters fixed; trace optimizer:
    StructTS(log10(UKgas), type = "BSM", fixed = c(0.1,0.001,NA,NA),
             optim.control = list(trace = TRUE))