Re: [R] Questions for package ts prediction
On Mon, 2003-06-09 at 03:56, Prof Brian Ripley wrote: You have a scoping problem: the predict method needs to find the data: please supply an explicit newdata argument. Your first example works because `y' happens to be globally visible and be the right object. Thanks. That makes sense. On 9 Jun 2003, zhu wang wrote: I am trying to write a function to return prediction values using package ts. I have written three different versions since I am not sure what's wrong with my func2. func and func1 return the same results.But func1 and func2 don't. In particular, the only difference between func1 and func2 is the function variable name being y and data, respectively. But running the last line of the following script will give the message: Error in ts(x): object is not a matrix. I am confused. Also, could somebody kindly let me what's the answer if any for the following sunspot example from the package help: data(sunspot) (sunspot.ar - ar(sunspot.year)) # why not just sunspot.ar - ar(sunspot.year) ? Have you tried it? Please do so, and you will learn the difference! This idiom is widely used in the R help files. I have tried it before but now I know the trick here. predict(sunspot.ar, n.ahead=25) -- zhu wang [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] Questions for package ts prediction
Dear helpers, I am trying to write a function to return prediction values using package ts. I have written three different versions since I am not sure what's wrong with my func2. func and func1 return the same results.But func1 and func2 don't. In particular, the only difference between func1 and func2 is the function variable name being y and data, respectively. But running the last line of the following script will give the message: Error in ts(x): object is not a matrix. I am confused. Also, could somebody kindly let me what's the answer if any for the following sunspot example from the package help: data(sunspot) (sunspot.ar - ar(sunspot.year)) # why not just sunspot.ar - ar(sunspot.year) ? predict(sunspot.ar, n.ahead=25) Thanks in advance. Zhu Wang Statistical Science Department Southern Methodist University (214)768-2453 -- zhu wang [EMAIL PROTECTED] # time series prediction func-function(data) {(esti- ar(data)) return(predict(object=esti,newdata=data,n.head=5)) } func1-function(y) {(esti- ar(y)) return(predict(esti,n.head=5)) } func2-function(data) {(esti- ar(data)) return(predict(esti,n.head=5)) } y-arima.sim(model=list(ar=c(1.7,-0.8)),n=100) func(y) func1(y) func2(y) __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help