Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-18 Thread Rui Barradas

Hello,

Is this what you want?


fun <- function(x, a){
y <- as.numeric(as.character(x))
z <- paste(a, names(x))
data.frame(z, y)
}

dat2 <- as.data.frame(TSmodelForecast)

tmp <- lapply(seq_along(dat2), function(i) fun(dat2[[i]], names(dat2)[i]))
result <- do.call(rbind, tmp)

Hope this helps,

Rui Barradas

Em 17-03-2017 21:45, Rui Barradas escreveu:

Hello,

By running the code of the OP, I've come to the conclusion that
print.forecast calls print.data.frame:

forecast:::print.forecast
function (x, ...)
{
 print(as.data.frame(x))
}



But I'm unable to get what the OP wants by call as.data.frame(...).
Here is the code with some made up data.

library(forecast)
library(tseries)

DAT <- data.frame(x = sample(100, 100, TRUE))

TSdata <- ts(DAT[,1], start=c(1994,10), frequency=12)
TSmodel <- nnetar(TSdata)
TSmodelForecast <- forecast(TSmodel, h=24)
TSmodelForecast

str(as.data.frame(TSmodelForecast))

Hope this helps,

Rui Barradas

Em 17-03-2017 20:48, Jim Lemon escreveu:

Hi Paul,
When manipulating any R object, the first thing to ascertain is what
it is:

class(TSmodelForecast)

should give you useful information.

str(TSmodelForecast)

should give you more. Because of the wealth of defined data structures
in R, it is difficult to manipulate them without this information. I
suspect that your output is something like a time series object, and
once that is known, it should not be too hard to display its contents
in the way you want.

Jim


On Sat, Mar 18, 2017 at 7:12 AM, Paul Bernal 
wrote:

Dear Jim,

Hope you are doing great. I tried to do what you suggested but R send an
error message saying that $ operator is invalid for atomic vectors.

The format of the forecasts are as follows: forecasted years are as
rows,
and forecasted months are in columns what I want to do is to have two
colums, one with the forecasted dates in (MMM- format) and the
second
column with the actual forecast results.

The output that is giving me hard time is the forecast output from
nnetar
model.

Thanks for your valuable support,

Best of regards,

Paul


2017-03-16 18:23 GMT-05:00 Jim Lemon :


Hi Paul,
It looks like the information that is printed is in:

TSModelForecast$mean

If str(TSModelForecast$mean) returns something like a list with two
components, you can probably use something like this:

paste(format(TSModelForecast$mean$Date,"%b-%Y"),
  TSModelForecast$mean$Forecast,sep="-",collapse="\n")

It also might be in TSModelForecast$fitted

Jim


On Fri, Mar 17, 2017 at 5:34 AM, Paul Bernal 
wrote:

Dear friends,

I am currently using R version 3.3.3 (64-bit) and used the following
code
to generate forecasts:


library(forecast)

library(tseries)


 ‘tseries’ version: 0.10-35

 ‘tseries’ is a package for time series analysis and computational
finance.

 See ‘library(help="tseries")’ for details.



DAT<-read.csv("TrainingData.csv")

TSdata<-ts(DAT[,1], start=c(1994,10), frequency=12)

TSmodel<-nnetar(TSdata)

TSmodelForecast<-forecast(TSmodel, h=24)

TSmodelForecast


The problem is that the output comes in this fashion:

 JanFebMarAprMayJun JulAug
Sep   Oct
  201710  20  15  40 9 8 21
21
 19 18
  201834  15   76  10  11

The format I would like to have is the following:

Date Forecast
Jan-2017   10
Feb-2017   20
Mar-2017   15
Apr-201740
May-2017   9
Jun-20178
Jul-2017 21
Aug-2017   21
Sep-2017   19
etc  etc

Is there a way to make the results look like this?

Attached is a dataset as a reference.

Best regards,

Paul
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-18 Thread Jim Lemon
Hi Paul,
A more educated guess is:

print(data.frame(Date=paste(rep(month.abb,32),
 rep(1986:2017,each=12), sep="-")[-(378:384)],
 Forecast=mf5$x))

Someone else may be able to tell you how to extract the dates from the
time series object mf5$x

Jim


On Sat, Mar 18, 2017 at 8:23 AM, Paul Bernal  wrote:
> Dear Jim,
>
> Thank you for your valuable replies. So variable mf5 has the forecasts for a
> fitted nnetar model.
>
> Below is the class and the str(mf5) output. Maybe with this information I am
> sharing with you, hopefully you can give me some more guidance.
>
> Again, thank you so much!
>
>> class(mf5)
> [1] "forecast"
>>
>> str(mf5)
> List of 16
>  $ x: Time-Series [1:377] from 1986 to 2017: 48 40 44 35 44 42 39 37
> 41 36 ...
>  $ m: num 12
>  $ p: num 25
>  $ P: num 1
>  $ scalex   :List of 2
>   ..$ center: num 38.1
>   ..$ scale : num 10.9
>  $ size : num 13
>  $ subset   : int [1:377] 1 2 3 4 5 6 7 8 9 10 ...
>  $ model:List of 20
>   ..$ :List of 15
>   .. ..$ n: num [1:3] 25 13 1
>   .. ..$ nunits   : int 40
>   .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
>   .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
>   .. ..$ nsunits  : num 39
>   .. ..$ decay: num 0
>   .. ..$ entropy  : logi FALSE
>   .. ..$ softmax  : logi FALSE
>   .. ..$ censored : logi FALSE
>   .. ..$ value: num 5.83
>   .. ..$ wts  : num [1:352] -1.081 2.199 0.734 1.358 1.115 ...
>   .. ..$ convergence  : int 1
>   .. ..$ fitted.values: num [1:352, 1] 0.246 0.439 -0.357 1.325 -0.195 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ residuals: num [1:352, 1] -0.0754 0.00853 -0.0242 -0.05026
> 0.0898 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
> linout = linout, trace = trace)
>   .. ..- attr(*, "class")= chr "nnet"
>   ..$ :List of 15
>   .. ..$ n: num [1:3] 25 13 1
>   .. ..$ nunits   : int 40
>   .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
>   .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
>   .. ..$ nsunits  : num 39
>   .. ..$ decay: num 0
>   .. ..$ entropy  : logi FALSE
>   .. ..$ softmax  : logi FALSE
>   .. ..$ censored : logi FALSE
>   .. ..$ value: num 2.54
>   .. ..$ wts  : num [1:352] -7.113 4.668 -0.801 -5.487 2.751 ...
>   .. ..$ convergence  : int 1
>   .. ..$ fitted.values: num [1:352, 1] 0.145 0.443 -0.401 1.286 -0.158 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ residuals: num [1:352, 1] 0.0258 0.0037 0.02 -0.0107 0.0528 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
> linout = linout, trace = trace)
>   .. ..- attr(*, "class")= chr "nnet"
>   ..$ :List of 15
>   .. ..$ n: num [1:3] 25 13 1
>   .. ..$ nunits   : int 40
>   .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
>   .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
>   .. ..$ nsunits  : num 39
>   .. ..$ decay: num 0
>   .. ..$ entropy  : logi FALSE
>   .. ..$ softmax  : logi FALSE
>   .. ..$ censored : logi FALSE
>   .. ..$ value: num 1.1
>   .. ..$ wts  : num [1:352] -2.24 -0.698 -0.243 -2.575 4.073 ...
>   .. ..$ convergence  : int 1
>   .. ..$ fitted.values: num [1:352, 1] 0.2466 0.2986 -0.4369 1.3053 -0.0965
> ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ residuals: num [1:352, 1] -0.07551 0.14845 0.056 -0.03027
> -0.00844 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
> linout = linout, trace = trace)
>   .. ..- attr(*, "class")= chr "nnet"
>   ..$ :List of 15
>   .. ..$ n: num [1:3] 25 13 1
>   .. ..$ nunits   : int 40
>   .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
>   .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
>   .. ..$ nsunits  : num 39
>   .. ..$ decay: num 0
>   .. ..$ entropy  : logi FALSE
>   .. ..$ softmax  : logi FALSE
>   .. ..$ censored : logi FALSE
>   .. ..$ value: num 1.8
>   .. ..$ wts  : num [1:352] 0.427 1.89 -0.705 -3.121 -1.134 ...
>   .. ..$ convergence  : int 1
>   .. ..$ fitted.values: num [1:352, 1] 0.11 0.37 -0.38 1.25 -0.15 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL
>   .. ..$ residuals: num [1:352, 1] 0.06113 0.07689 -0.00135 0.02279
> 0.04491 ...
>   .. .. ..- attr(*, "dimnames")=List of 2
>   .. .. .. ..$ : NULL
>   .. .. .. ..$ : NULL

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Rui Barradas

Hello,

By running the code of the OP, I've come to the conclusion that 
print.forecast calls print.data.frame:


forecast:::print.forecast
function (x, ...)
{
print(as.data.frame(x))
}



But I'm unable to get what the OP wants by call as.data.frame(...).
Here is the code with some made up data.

library(forecast)
library(tseries)

DAT <- data.frame(x = sample(100, 100, TRUE))

TSdata <- ts(DAT[,1], start=c(1994,10), frequency=12)
TSmodel <- nnetar(TSdata)
TSmodelForecast <- forecast(TSmodel, h=24)
TSmodelForecast

str(as.data.frame(TSmodelForecast))

Hope this helps,

Rui Barradas

Em 17-03-2017 20:48, Jim Lemon escreveu:

Hi Paul,
When manipulating any R object, the first thing to ascertain is what it is:

class(TSmodelForecast)

should give you useful information.

str(TSmodelForecast)

should give you more. Because of the wealth of defined data structures
in R, it is difficult to manipulate them without this information. I
suspect that your output is something like a time series object, and
once that is known, it should not be too hard to display its contents
in the way you want.

Jim


On Sat, Mar 18, 2017 at 7:12 AM, Paul Bernal  wrote:

Dear Jim,

Hope you are doing great. I tried to do what you suggested but R send an
error message saying that $ operator is invalid for atomic vectors.

The format of the forecasts are as follows: forecasted years are as rows,
and forecasted months are in columns what I want to do is to have two
colums, one with the forecasted dates in (MMM- format) and the second
column with the actual forecast results.

The output that is giving me hard time is the forecast output from nnetar
model.

Thanks for your valuable support,

Best of regards,

Paul


2017-03-16 18:23 GMT-05:00 Jim Lemon :


Hi Paul,
It looks like the information that is printed is in:

TSModelForecast$mean

If str(TSModelForecast$mean) returns something like a list with two
components, you can probably use something like this:

paste(format(TSModelForecast$mean$Date,"%b-%Y"),
  TSModelForecast$mean$Forecast,sep="-",collapse="\n")

It also might be in TSModelForecast$fitted

Jim


On Fri, Mar 17, 2017 at 5:34 AM, Paul Bernal 
wrote:

Dear friends,

I am currently using R version 3.3.3 (64-bit) and used the following
code
to generate forecasts:


library(forecast)

library(tseries)


 ‘tseries’ version: 0.10-35

 ‘tseries’ is a package for time series analysis and computational
finance.

 See ‘library(help="tseries")’ for details.



DAT<-read.csv("TrainingData.csv")

TSdata<-ts(DAT[,1], start=c(1994,10), frequency=12)

TSmodel<-nnetar(TSdata)

TSmodelForecast<-forecast(TSmodel, h=24)

TSmodelForecast


The problem is that the output comes in this fashion:

 JanFebMarAprMayJun JulAug
Sep   Oct
  201710  20  15  40 9 8 21
21
 19 18
  201834  15   76  10  11

The format I would like to have is the following:

Date Forecast
Jan-2017   10
Feb-2017   20
Mar-2017   15
Apr-201740
May-2017   9
Jun-20178
Jul-2017 21
Aug-2017   21
Sep-2017   19
etc  etc

Is there a way to make the results look like this?

Attached is a dataset as a reference.

Best regards,

Paul
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Paul Bernal
Dear Jim,

Thank you for your valuable replies. So variable mf5 has the forecasts for
a fitted nnetar model.

Below is the class and the str(mf5) output. Maybe with this information I
am sharing with you, hopefully you can give me some more guidance.

Again, thank you so much!

> class(mf5)
[1] "forecast"
>
> str(mf5)
List of 16
 $ x: Time-Series [1:377] from 1986 to 2017: 48 40 44 35 44 42 39
37 41 36 ...
 $ m: num 12
 $ p: num 25
 $ P: num 1
 $ scalex   :List of 2
  ..$ center: num 38.1
  ..$ scale : num 10.9
 $ size : num 13
 $ subset   : int [1:377] 1 2 3 4 5 6 7 8 9 10 ...
 $ model:List of 20
  ..$ :List of 15
  .. ..$ n: num [1:3] 25 13 1
  .. ..$ nunits   : int 40
  .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..$ nsunits  : num 39
  .. ..$ decay: num 0
  .. ..$ entropy  : logi FALSE
  .. ..$ softmax  : logi FALSE
  .. ..$ censored : logi FALSE
  .. ..$ value: num 5.83
  .. ..$ wts  : num [1:352] -1.081 2.199 0.734 1.358 1.115 ...
  .. ..$ convergence  : int 1
  .. ..$ fitted.values: num [1:352, 1] 0.246 0.439 -0.357 1.325 -0.195 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ residuals: num [1:352, 1] -0.0754 0.00853 -0.0242 -0.05026
0.0898 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
linout = linout, trace = trace)
  .. ..- attr(*, "class")= chr "nnet"
  ..$ :List of 15
  .. ..$ n: num [1:3] 25 13 1
  .. ..$ nunits   : int 40
  .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..$ nsunits  : num 39
  .. ..$ decay: num 0
  .. ..$ entropy  : logi FALSE
  .. ..$ softmax  : logi FALSE
  .. ..$ censored : logi FALSE
  .. ..$ value: num 2.54
  .. ..$ wts  : num [1:352] -7.113 4.668 -0.801 -5.487 2.751 ...
  .. ..$ convergence  : int 1
  .. ..$ fitted.values: num [1:352, 1] 0.145 0.443 -0.401 1.286 -0.158 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ residuals: num [1:352, 1] 0.0258 0.0037 0.02 -0.0107 0.0528 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
linout = linout, trace = trace)
  .. ..- attr(*, "class")= chr "nnet"
  ..$ :List of 15
  .. ..$ n: num [1:3] 25 13 1
  .. ..$ nunits   : int 40
  .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..$ nsunits  : num 39
  .. ..$ decay: num 0
  .. ..$ entropy  : logi FALSE
  .. ..$ softmax  : logi FALSE
  .. ..$ censored : logi FALSE
  .. ..$ value: num 1.1
  .. ..$ wts  : num [1:352] -2.24 -0.698 -0.243 -2.575 4.073 ...
  .. ..$ convergence  : int 1
  .. ..$ fitted.values: num [1:352, 1] 0.2466 0.2986 -0.4369 1.3053 -0.0965
...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ residuals: num [1:352, 1] -0.07551 0.14845 0.056 -0.03027
-0.00844 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
linout = linout, trace = trace)
  .. ..- attr(*, "class")= chr "nnet"
  ..$ :List of 15
  .. ..$ n: num [1:3] 25 13 1
  .. ..$ nunits   : int 40
  .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..$ nsunits  : num 39
  .. ..$ decay: num 0
  .. ..$ entropy  : logi FALSE
  .. ..$ softmax  : logi FALSE
  .. ..$ censored : logi FALSE
  .. ..$ value: num 1.8
  .. ..$ wts  : num [1:352] 0.427 1.89 -0.705 -3.121 -1.134 ...
  .. ..$ convergence  : int 1
  .. ..$ fitted.values: num [1:352, 1] 0.11 0.37 -0.38 1.25 -0.15 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ residuals: num [1:352, 1] 0.06113 0.07689 -0.00135 0.02279
0.04491 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : NULL
  .. .. .. ..$ : NULL
  .. ..$ call : language nnet.default(x = x, y = y, size = ..1,
linout = linout, trace = trace)
  .. ..- attr(*, "class")= chr "nnet"
  ..$ :List of 15
  .. ..$ n: num [1:3] 25 13 1
  .. ..$ nunits   : int 40
  .. ..$ nconn: num [1:41] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ conn : num [1:352] 0 1 2 3 4 5 6 7 8 9 ...
  .. ..$ nsunits  : num 39
  .. ..$ decay: num 0
  .. ..$ entropy  : logi FALSE
  .. ..$ softmax  : logi FALSE
  .. ..$ censored : logi FALSE
  .. ..$ value: num 2.67
  .. ..$ wts  

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Jim Lemon
Hi Paul,
When manipulating any R object, the first thing to ascertain is what it is:

class(TSmodelForecast)

should give you useful information.

str(TSmodelForecast)

should give you more. Because of the wealth of defined data structures
in R, it is difficult to manipulate them without this information. I
suspect that your output is something like a time series object, and
once that is known, it should not be too hard to display its contents
in the way you want.

Jim


On Sat, Mar 18, 2017 at 7:12 AM, Paul Bernal  wrote:
> Dear Jim,
>
> Hope you are doing great. I tried to do what you suggested but R send an
> error message saying that $ operator is invalid for atomic vectors.
>
> The format of the forecasts are as follows: forecasted years are as rows,
> and forecasted months are in columns what I want to do is to have two
> colums, one with the forecasted dates in (MMM- format) and the second
> column with the actual forecast results.
>
> The output that is giving me hard time is the forecast output from nnetar
> model.
>
> Thanks for your valuable support,
>
> Best of regards,
>
> Paul
>
>
> 2017-03-16 18:23 GMT-05:00 Jim Lemon :
>>
>> Hi Paul,
>> It looks like the information that is printed is in:
>>
>> TSModelForecast$mean
>>
>> If str(TSModelForecast$mean) returns something like a list with two
>> components, you can probably use something like this:
>>
>> paste(format(TSModelForecast$mean$Date,"%b-%Y"),
>>  TSModelForecast$mean$Forecast,sep="-",collapse="\n")
>>
>> It also might be in TSModelForecast$fitted
>>
>> Jim
>>
>>
>> On Fri, Mar 17, 2017 at 5:34 AM, Paul Bernal 
>> wrote:
>> > Dear friends,
>> >
>> > I am currently using R version 3.3.3 (64-bit) and used the following
>> > code
>> > to generate forecasts:
>> >
>> >> library(forecast)
>> >>
>> >> library(tseries)
>> >
>> > ‘tseries’ version: 0.10-35
>> >
>> > ‘tseries’ is a package for time series analysis and computational
>> > finance.
>> >
>> > See ‘library(help="tseries")’ for details.
>> >
>> >
>> >> DAT<-read.csv("TrainingData.csv")
>> >>
>> >> TSdata<-ts(DAT[,1], start=c(1994,10), frequency=12)
>> >>
>> >> TSmodel<-nnetar(TSdata)
>> >>
>> >> TSmodelForecast<-forecast(TSmodel, h=24)
>> >>
>> >> TSmodelForecast
>> >
>> > The problem is that the output comes in this fashion:
>> >
>> > JanFebMarAprMayJun JulAug
>> > Sep   Oct
>> >  201710  20  15  40 9 8 21
>> > 21
>> > 19 18
>> >  201834  15   76  10  11
>> >
>> > The format I would like to have is the following:
>> >
>> > Date Forecast
>> > Jan-2017   10
>> > Feb-2017   20
>> > Mar-2017   15
>> > Apr-201740
>> > May-2017   9
>> > Jun-20178
>> > Jul-2017 21
>> > Aug-2017   21
>> > Sep-2017   19
>> > etc  etc
>> >
>> > Is there a way to make the results look like this?
>> >
>> > Attached is a dataset as a reference.
>> >
>> > Best regards,
>> >
>> > Paul
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-16 Thread Jim Lemon
Hi Paul,
It looks like the information that is printed is in:

TSModelForecast$mean

If str(TSModelForecast$mean) returns something like a list with two
components, you can probably use something like this:

paste(format(TSModelForecast$mean$Date,"%b-%Y"),
 TSModelForecast$mean$Forecast,sep="-",collapse="\n")

It also might be in TSModelForecast$fitted

Jim


On Fri, Mar 17, 2017 at 5:34 AM, Paul Bernal  wrote:
> Dear friends,
>
> I am currently using R version 3.3.3 (64-bit) and used the following code
> to generate forecasts:
>
>> library(forecast)
>>
>> library(tseries)
>
> ‘tseries’ version: 0.10-35
>
> ‘tseries’ is a package for time series analysis and computational
> finance.
>
> See ‘library(help="tseries")’ for details.
>
>
>> DAT<-read.csv("TrainingData.csv")
>>
>> TSdata<-ts(DAT[,1], start=c(1994,10), frequency=12)
>>
>> TSmodel<-nnetar(TSdata)
>>
>> TSmodelForecast<-forecast(TSmodel, h=24)
>>
>> TSmodelForecast
>
> The problem is that the output comes in this fashion:
>
> JanFebMarAprMayJun JulAug
> Sep   Oct
>  201710  20  15  40 9 8 21 21
> 19 18
>  201834  15   76  10  11
>
> The format I would like to have is the following:
>
> Date Forecast
> Jan-2017   10
> Feb-2017   20
> Mar-2017   15
> Apr-201740
> May-2017   9
> Jun-20178
> Jul-2017 21
> Aug-2017   21
> Sep-2017   19
> etc  etc
>
> Is there a way to make the results look like this?
>
> Attached is a dataset as a reference.
>
> Best regards,
>
> Paul
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.