[R] Method

yonosoyelmejor yonosoyelmejor at hotmail.com
Wed Nov 25 10:43:30 CET 2009


You are right,but I´ll explain,my code creates a time series,after some
transformations I need to make a prediction,which predicts 10values using
the above,then written in a file,I put the code to see if it looks better:

# TODO: Add comment
# 
# Author: Ignacio2
###############################################################################



library(TSA)
library(tseries)

Invernadero<-read.table(file.choose(),header=T,sep=",")

attach(Invernadero)
names(Invernadero)
Invernadero<-ts(Invernadero<-Temp..Ext)
plot(Hora,Invernadero,main="Temperatura Ext.
Invernadero",xlab="Tiempo",ylab="Temperatura Ext.")

x = log(Invernadero)  #Estabilizar la varianza

varianza<-function(x) { ((length(x)-1)/length(x))*var(x) }#para saber la
varianza
varianza(x)
varianza(Invernadero)
x1<-diff(x,lag=60)
adf.test(x1)
x2<-diff(x1,lag=1)
adf.test(x2)
mean(x2)
# La función “ar” permite seleccionar automáticamente “el
#mejor modelo #autorregresivo:

ar(x2)
orden <- ar(x2)$order #con esto obtenemos el orden seleccionado no toda la
informacion

#AIC(arima(x2,order=c(8,0,0)),arima(x2,order=c(31,0,0)))

# Predicción:
x2.pred.ar31<-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$pred
# Errores de predicción:
x2.err.ar31<-predict(arima(x2,order=c(orden,0,0)),n.ahead=10)$se
plot(x2.err.ar31)

#deshacer cambios

x.completada<-c(x2,x2.pred.ar31)
xinv1<-diffinv(x.completada,lag=1,xi=x1[1])
xinv2<-diffinv(xinv1,lag=60,xi=x[1:60])
x.reconstruida<-ts(xinv2,frequency=60)
# Comprobación de que la reconstrucción fue correcta:
yy<-x-x.reconstruida[1:length(x)] # esto para Hora8
## yy debe ser una serie de 0’s
plot(yy)


# Las predicciones para los minutos siguientes de la serie
#original son:
#prediccion = exp(x.reconstruida[481:491]) #en nuestro caso pondriamos los
minutos a saber.
prediccion = exp(x.reconstruida[length(x)+1:length(x)+9]) 
###This is what I do not work, we still need to be reusable by if I change
the number of elements

write.table(prediccion,"C:\\Temp\\prePrueba.txt",quote=F,row.names=F,append=T,col.names=F)


Sarah Goslee wrote:
> 
> If the last position of your vector is 1440, what do you expect to get
> from 1440 + 1???
> And you certainly need some parentheses in there if you expect to get a
> range of
> values from your vector.
> 
> Perhaps you need some subtraction?
> 
> And no, we still can't tell exactly what you want. If this doesn't
> answer your question,
> make a reproducible example with a short vector, your code that
> doesn't work, and
> the _result you expect to get_ so we can help you.
> 
> Sarah
> 
> On Tue, Nov 24, 2009 at 1:44 PM, yonosoyelmejor
> <yonosoyelmejor at hotmail.com> wrote:
>>
>> I use length(myVector),but when i want to use for example
>> exp(x.reconstruida[length(myVector)+1:length(myVector)+9]), I need that
>> function returns the number of last element,would then:
>>
>> if the last position of my vector is 1440
>>
>> exp(x.reconstruida[1440+1:1440+9]
>>
>> This is what I need, I hope having explained,
>>
>> A gretting,
>> Ignacio.
>>
> 
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> ______________________________________________
> R-help at 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.
> 
> 

-- 
View this message in context: http://old.nabble.com/Method-tp26493442p26509891.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list