Dear R Users,

Kindly advice me what's wrong in my programming.

I'm using the Cochrane-Orcutt two stage procedure with Prais Wisten 
transformation, below is my R programming :

>Y<-c(60.8,62.5,64.6,66.1,67.7,69.1,71.7,73.5,76.2,77.3,78.8,80.2,82.6,84.3,83.3,84.1,86.4,87.6,89.1,89.3,89.1,
>,
+ 
89.3,90.4,90.3,90.7,92.0,94.9,95.2,96.5,95.0,96.2,97.4,100.0,99.7,99.0,98.7,99.4,100.5,105.2,108.0,112.0,113.5,

+ 115.7,117.7,119.0,120.2)
> 
>X<-c(48.9,50.6,52.9,55.0,56.8,58.8,61.2,62.5,64.7,65.0,66.3,69.0,71.2,73.4,72.3,74.8,77.1,78.5,79.3,79.3,79.2,
>,
+ 
80.8,80.1,83.0,85.2,87.1,89.7,90.1,91.5,92.4,94.4,95.9,100.0,100.4,101.3,101.5,104.5,106.5,109.5,112.8,116.1,

+ 119.1,124.0,128.7,132.7,135.7)
> model<-lm(Y~X)
> e<-resid(model)
> mylag<-function(e,d=1) { 
+       n<-length(e) 
+       c(rep(NA,d),e)[1:n] 
+ }
> n<-length(e)
> e1<-mylag(e)
> modele<-lm(e~e1-1)
> rho<-coef(modele)
> rho
       e1 
0.8875926 
> n<-length(e)
> xstar<-c(X[1]*(1-rho^2)^0.5,X[2:n]-rho*X[1:(n-1)])
> ystar<-c(Y[1]*(1-rho^2)^0.5,Y[2:n]-rho*Y[1:(n-1)])
> modelb<-lm(ystar~xstar)
> bstar<-coef(modelb)
> a<-(bstar[[1]][[1]])/(1-rho)
> a[1:n]<-a
> b<-bstar[[2]][[1]]
> u<-Y-(a+X*b)
> u<-u
> myu<-function(u,d=1) { 
+       n<-length(u) 
+       c(rep(NA,d),u)[1:n] 
+ }
> u1<-myu(u)
> modelu<-lm(u~u1-1)
> Rho<-coef(modelu)
> Rho
      u1 
1.029970 

 The answer should be less than one but I got 1.029970. Any correction in the 
programming part? Any preventive action on this matter?

Thank you.

Regards,
Lim Hock Ann



      
        [[alternative HTML version deleted]]

______________________________________________
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