Hello Dirk and others,<br>The "explicit print" worked fine! I had read about in other posts, but I didn't realize my mistake.<br>In the 11th standard example I found that just adding "x11()" and "sleep()" at the beginning and end of plot, I can see the graphics.<br>
Arima function returns an "arima model", not just a vector, so I don't know how to get it (but I don't need it at this time).<br>Thank you very much, you answered really fast!<br><br><div class="gmail_quote">
2011/11/29 Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org">edd@debian.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>
<div></div><div class="h5"><br>
On 29 November 2011 at 11:03, Kowagunga wrote:<br>
| Hello everyone,<br>
| I'm working to get some predictions using ARIMA model in R. This is the code<br>
| I'm using, at it works as expected:<br>
|<br>
|<br>
| library(TSA)<br>
| load(' path... /R/i686-pc-linux-gnu-library/2.14/TSA/data/airpass.rda')<br>
| show(airpass)<br>
| m <- arima(airpass,order=c(0,1,12),seasonal=list(order=c(0,1,1),period=24))<br>
| m<br>
| plot(m,n.ahead=72,xlab='Time',type='o',ylab='Passengers')<br>
| abline(h=0)<br>
|<br>
|<br>
| I use example data from the TSA package, and the prediction is plotted well.<br>
| The issue is that what I really want is use it within a bigger C++ project, so<br>
| I need to use RInside package. I've tested every example of RInside, and it<br>
| seems perfectly operative in my machine.<br>
| I have programmed it like this:<br>
|<br>
| //Ejemplo que carga los datos airpass.rda del package TSA y realiza una<br>
| prediccion ARIMA sobre ellos<br>
| #include <RInside.h> <br>
| // for the embedded R via RInside<br>
| int main(int argc, char *argv[]) {<br>
| RInside R(argc, argv); //<br>
| create an embedded R instance<br>
| std::string evalstr = "library(TSA); load(' ...path... /R/<br>
| i686-pc-linux-gnu-library/2.14/TSA/data/airpass.rda'); show(airpass);"; //<br>
| Cargamos la libreria TSA necesaria y el archivo de datos<br>
| R.parseEvalQ(evalstr);<br>
| std::string evalstr2 = "m <- arima(airpass,order=c(0,1,12),seasonal=<br>
| list(order=c(0,1,1),period=24)); m"; //Calculo de la prediccion sobre los<br>
| datos. Coeficientes manualmente precalculados<br>
| R.parseEvalQ(evalstr2);<br>
| std::string evalstr3 = "plot(m,n.ahead=72,xlab='Tiempo',type=<br>
| 'o',ylab='Pasajeros'); abline(h=0)"; //Dibujamos los datos y la prediccion.<br>
| R.parseEvalQ(evalstr3);<br>
| std::string evalstr4 = "cat('AIC del modelo:\n'); m$aic"; //Muestra<br>
| el estimador de bondad AIC<br>
| R.parseEvalQ(evalstr4);<br>
|<br>
| exit(0);<br>
| }<br>
|<br>
| (The comments are in spanish, sorry)<br>
| When I run this code, the output of the first evalstr is the same that in R.<br>
| TSA & airpass are loaded correctly. But the next line seems not to work.<br>
| It tooks several seconds calculating arima model, but it the problem is that<br>
| "m" command to show the model produces no output, the same that "m$aic". With<br>
| "no output" I mean nothing (including any error).<br>
<br>
</div></div>RInside is by default silent and only prints if you are explicit.<br>
<br>
So try an explicit 'print(m)' as in:<br>
<div class="im"><br>
std::string evalstr2 = "m <- arima(airpass,order=c(0,1,12),"<br>
</div> "seasonal=list(order=c(0,1,1),period=24)); print(m)";<br>
R.parseEvalQ(evalstr2);<br>
<br>
which will now print m.<br>
<br>
If you want a result returned you must<br>
<br>
a) use parseEval() and NOT parseEvalQ() which is 'quiet'<br>
<br>
b) assign to some variable -- I don't know of the top of my head what<br>
arima() returns, but if it were just a vector you'd do<br>
<div class="im"><br>
std::string evalstr2 = "m <- arima(airpass,order=c(0,1,12),"<br>
"seasonal=list(order=c(0,1,1),period=24)); m";<br>
</div> Rcpp::NumericVector myM = R.parseEval(evalstr2);<br>
<br>
This is all relatively basic and I encourage you to study the over ten examples<br>
that come with RInside a little more closely.<br>
<br>
Dirk<br>
<div><div></div><div class="h5"><br>
<br>
| I can't get the graphic too, but I know that maybe I would have to plot to a<br>
| file to get it work. The problem is that I also get no error. This is the<br>
| output of my code (there are some warning lines at the beginning, but the rest<br>
| of examples always worked with the same lines):<br>
|<br>
| During startup - Warning messages:<br>
| 1: Setting LC_CTYPE failed, using "C"<br>
| 2: Setting LC_COLLATE failed, using "C"<br>
| 3: Setting LC_TIME failed, using "C"<br>
| 4: Setting LC_MESSAGES failed, using "C"<br>
| 5: Setting LC_PAPER failed, using "C"<br>
| 6: Setting LC_PAPER failed, using "C"<br>
| 7: Setting LC_MEASUREMENT failed, using "C"<br>
| Loading required package: leaps<br>
| Loading required package: locfit<br>
| Loading required package: akima<br>
| Loading required package: lattice<br>
| locfit 1.5-6 2010-01-20<br>
| Loading required package: mgcv<br>
| This is mgcv 1.7-9. For overview type 'help("mgcv-package")'.<br>
| Loading required package: tseries<br>
| Loading required package: quadprog<br>
| Loading required package: zoo<br>
|<br>
| Attaching package: 'zoo'<br>
|<br>
| The following object(s) are masked from 'package:base':<br>
|<br>
| as.Date, as.Date.numeric<br>
|<br>
|<br>
| Attaching package: 'TSA'<br>
|<br>
| The following object(s) are masked from 'package:stats':<br>
|<br>
| acf, arima<br>
|<br>
| The following object(s) are masked from 'package:utils':<br>
|<br>
| tar<br>
|<br>
| Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec<br>
| 1960 112 118 132 129 121 135 148 148 136 119 104 118<br>
| 1961 115 126 141 135 125 149 170 170 158 133 114 140<br>
| 1962 145 150 178 163 172 178 199 199 184 162 146 166<br>
| 1963 171 180 193 181 183 218 230 242 209 191 172 194<br>
| 1964 196 196 236 235 229 243 264 272 237 211 180 201<br>
| 1965 204 188 235 227 234 264 302 293 259 229 203 229<br>
| 1966 242 233 267 269 270 315 364 347 312 274 237 278<br>
| 1967 284 277 317 313 318 374 413 405 355 306 271 306<br>
| 1968 315 301 356 348 355 422 465 467 404 347 305 336<br>
| 1969 340 318 362 348 363 435 491 505 404 359 310 337<br>
| 1970 360 342 406 396 420 472 548 559 463 407 362 405<br>
| 1971 417 391 419 461 472 535 622 606 508 461 390 432<br>
| AIC del modelo:<br>
|<br>
| <br>
| I have tried everything that came to my mind, and I have no more ideas! I think<br>
| I have explained my best, hope somebody can help me with this.<br>
| Sorry if I made some language mistake ;) Thank you very much!<br>
|<br>
</div></div>| ----------------------------------------------------------------------<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<font color="#888888">--<br>
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too<br>
dark to read." -- Groucho Marx<br>
</font></blockquote></div><br>