[R] Applying forecast functions to columns in a data frame

David Winsemius dwinsemius at comcast.net
Tue Jun 22 17:35:59 CEST 2010


On Jun 22, 2010, at 11:10 AM, phani kishan wrote:

> Hey!
>
> On Tue, Jun 22, 2010 at 8:11 PM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Jun 22, 2010, at 10:32 AM, Henrique Dallazuanna wrote:
>
> Try this:
>
> lapply(DF, auto.arima)
>  I am getting the following error:
> "Error in if (PVAL == min(tablep)) warning("p-value smaller than  
> printed p-value") else warning("p-value greater than printed p- 
> value") :
>   missing value where TRUE/FALSE needed"
>
> My objective is to come up with an exponential smoothing model which  
> best fits all the time-series. Simple operations like mean etc. can  
> be applied using lapply but not statistical functions.

It is possible that do.call may be more helpful than lapply in some  
instances. But you have not described your desired instance in very  
much detail.

> Is it necessary that I write a function myself?

Perhaps it will be as simple as writing a wrapper that sets up the  
parameters and possibly deal with NA's. Tell us how would you do it  
for one vector,  offer a modest subset of the data with the head  
function and dput(), then we can tell you how it can be done for n  
vectors.

> If so, how do I loop though the columns in the dataframe?

lapply   # since data.frames are lists

# Or:

?do.call


> Thanks a lot
> Phani
>
> I cannot comment on the relative merits of auto.arima or the  
> forecast function, but I did notice that earlier today that Gabor  
> Grothendieck (who, I suspect, could comment knowledgeably) mentioned  
> the latter's use in a similar context:
>
> https://stat.ethz.ch/pipermail/r-help/2010-June/243252.html
>
>
> On Tue, Jun 22, 2010 at 11:26 AM, phani kishan  
> <phanikishan at gmail.com>wrote:
>
> Hey,
> I have a list of 30 odd time-series (products) in columns of a data- 
> frame.
> I want to apply time-series forecasting functions across all the  
> columns of
> the data-frame in order to determine which is the best model to use.
> How do I go about this?
>
> Phani
>
> -- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list