R语言中有关预测

Python014

R语言中有关预测,第1张

ARIMA有现成的东西

nobs=length(data_set)

fit=arima(data_set, order=c(1,1,1), xreg=1:nobs)

fore=predict(fit, 15, newxreg=(nobs+1):(nobs+15))

arima 是fit模型

predict 是预测

ts.plot 是按时间画图

好吧。。。希望对你有用~~~~~~~~~~~~~

简单的说,fitted是拟合值,predict是预测值:

所做的模型是基于给定样本的值建立的,在这些给定样本x1,x2,...,xn(已知所对应的y值)上做预测就是拟合;

在新样本上xn+1,xn+2,...(y值未知)做预测,就是模型预测。

例如,R in action中的例子:

fit<-lm(weight~height,data=women)

fitted(fit)

predict(fit,newdata=data.frame(height=90))

##将90代入,可以对比下结果。

用predict就能做到。

predict的用法:

predict(object, newdata, se.fit = FALSE, scale = NULL, df = Inf,

interval = c("none", "confidence", "prediction"),

level = 0.95, type = c("response", "terms"),

terms = NULL, na.action = na.pass,

pred.var = res.var/weights, weights = 1, ...)

object是你的回归模型。

newdata是使用的数据。

interval选confidence或者"c"。

level是置信水平。

type在计算响应变量时使用response,对变量计算使用terms。如果是terms,需要用后面terms参数指定变量名(character类型向量形式)。