Ruchi -
   If the only way you can figure out to read your data
into R is through SAS, I think you need to spend more time
with the R introductory documentation, for example

  http://cran.r-project.org/doc/manuals/R-intro.html

While data is usually read from a file, you can imitate
SAS' datalines command using the textConnection function:

dat = read.table(textConnection('2008 12 13 12 14 13 12 11 15 10 12 12 12
+ 2009 12 13 12 14 13 12 11 15 10 12 12 12
+ '))

Now convert the data into a time series.  We can ignore the first
column of dat, and use the transpose because R stores its data by
columns:

myts = ts(as.vector(t(dat[,-1])),start=c(2008,1),frequency=12)

Now, we can load the forecast package, which contains auto.arima:

library(forecast)

From here, things should work as you expect:

fit = auto.arima(myts)
fcast = forecast(fit)
plot(fcast)
summary(fcast)
                                        - Phil Spector
                                         Statistical Computing Facility
                                         Department of Statistics
                                         UC Berkeley
                                         spec...@stat.berkeley.edu



On Thu, 7 Oct 2010, Vangani, Ruchi wrote:

1.  This is an imaginary data on monthly outcomes of 2 years and I want to 
forecast the outcome for next 12 months of next year.


data Data1;
input Yr Jan Feb Mar Apr May June July Aug Sept Oct Nov Dec;
datalines;
2008 12 13 12 14 13 12 11 15 10 12 12 12
2009 12 13 12 14 13 12 11 15 10 12 12 12
;
run;

I converted the above data into the below format to use it in R as it was 
giving error: asking to use only univariate time series.

data Data1;
input RR;
datalines;
12
14
17
15
13
15
15
14
15
14
16
15
15
18
16
16
15
14
15
16
16
14
13
12
;
run;


1.  I successfully took this data thru xport into R using the below codes:

libname xportout xport 'H:\Care Transition Evaluation\CT-Codes\SAS\gross 
up\Data\Forc1.xpt';

data xportout.Forc1;
  set Data1;
run;



setwd("H:/Care Transition Evaluation/CT-Codes/SAS/gross up/Data")
getwd()
Forc<-read.xport("Forc1.xpt")
attach(Forc)
names(Forc)
Forc


1.  Used the auto.arima codes:
fit <- auto.arima(Forc)
fcast <-forecast(fit)
plot(fcast)
summary(fcast)

But the following error comes on using the first line of code:
fit <- auto.arima(Forc)
-----------------------------------------------------------------------
Error in model.frame.default(formula = x ~ 1, drop.unused.levels = TRUE) :
 invalid type (list) for variable 'x'
-----------------------------------------------------------------------


1.  Further:
I tried to use the Holt Winters Algorithm using the below codes:

Final <- HoltWinters(Forc,gamma=FALSE)
plot(forecast(Final))
Final

pred <- predict(Final, n.ahead = 8)
plot(Final, predicted.values = pred)

pred

These codes work completely fine but it adjusts for the trend and does not 
takes into account the seasonal component which is more important in the 
analysis.



Please help.

Thanks,
Ruchi







The information contained in this communication is highl...{{dropped:18}}

______________________________________________
R-help@r-project.org mailing list
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
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.

Reply via email to