Mathew
Mathew

Reputation: 1450

Sarima show only plots

I have the following code that I am running in R:

```{r}
library(astsa)
data = c(1:500)
mo1 = sarima(data,0,0,2)
```

It produces both the five plots I am interested in and output from the nonlinear optimization routine. I don't want the output from the nonlinear optimization however to turn it off using details=FALSE I will also turn off the plots which I need.

When I run this code in the console, the plots are put into a pdf and the optimization output is printed to STDOUT. This is good because I can have the plots and optimization separately which is what I need, however I want to do this in RStudios. How can this be done?

Upvotes: 3

Views: 865

Answers (2)

SCDCE
SCDCE

Reputation: 1643

It's been a couple of years but this will produce only the plots when knitted:

```{r results='hide',fig.keep='all'}
sarima(data,0,0,2)
```

Upvotes: 1

user20650
user20650

Reputation: 25864

It looks like the details argument is used to both return the trace output from the optimisers -- see the lines in sarima:

trc = ifelse(details, 1, 0)

and various

optim.control = list(trace = trc, REPORT = 1, reltol = tol)

and to produce the plots

if (details) {
  < code for plots>
}

A couple of options to produce the plots but no optimiser output would be to:

  1. capture the output from the optimiser:

    mo1 = capture.output(sarima(data,0,0,2))
    

    but then you either have to parse the captured output to get the fit statistics or need to run sarima a second time (mo1 = sarima(data,0,0,2, details=FALSE)) to get the statistics.

  2. change the body of the function to change what the argument details does:

    body(sarima)[[18]] = quote(trc <- abs(details-1)) 
    mo1 = sarima(data,0,0,2, details = TRUE)
    
  3. Another option would be to request that the authors change the function to separate the optimiser trace and plot commands (i.e. add a plot=TRUE type argument to the function signature and change if(details) to if(plot)).

Upvotes: 1

Related Questions