[R] Need some help in R programming code

jim holtman jholtman at gmail.com
Sat Nov 22 15:47:36 CET 2008


You need to also provide the data that your code is using since the
error message indicates that the problem is probably in the way that
the object 'a' is defined and there is no indication of what it looks
like.  You should either provide the output of "str(a)", or the output
of 'dput(a)' so we have an idea of what it is.  The error message
seems to indicate the the "$" is not legal for 'a' as it is currently
defined.

On Sat, Nov 22, 2008 at 4:55 AM, saikat sarkar <dipa_sanyal at yahoo.com> wrote:
>
> Dear R guru,
>
> I am Saikat Sarkar working as a researcher of Economics in Tampere
> University, Finland. I am trying to estimate some Garch related tests with
> Bayesian analysis by R programme.
>
> I am not good in R but trying to survive.
>
> Anyway I have the coding but not working properly. I have tried to find the
> problem but failed. I am writing to all R gurus to help me out.
>
> Could you please look at the problem and help me if you can.
>
> Thanking you
> saikat
>
> Could you please look at the problem below:
>
> R message is like below:
> -------
> Error in garch.gjr.d0(param, y, X, Z, iterate = FALSE)$res :
>  $ operator is invalid for atomic vectors
> plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))
> -----------------------
> Coding
> --------
>
> res<-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$res
> sig2<-garch.gjr.d0(a$estimate,y,X,X,iterate=FALSE)$sig2
>
>
> test.mic <- function(param,y,X,Z)
>
> {
>   n <- length(y)
>
>   res <- garch.gjr.d0(param,y,X,Z,iterate=FALSE)$res
>
>   s2 <- garch.gjr.d0(param,y,X,Z,iterate=FALSE)$sig2
>
>   s<-sqrt(s2)
>
>   r <- res
>
>   u <- r[-1]
>
>   r2<- (r[-n]^2*s2[-n])/s[-1]
>
>   r3<- (r[-n]^3*s2[-n]*s[-n])/s[-1]
>
>   U <- cbind(r[-n],r2,r3)
>
>   U <- cbind(1,U)
>
>   U <- U/matrix(s[-1],nr=nrow(U),nc=ncol(U))
>
>   Fstat<-summary(lm(u~U-1))$fstatistic[1]
>
>   Fstat
>
> }
>
>
> sim.gjr <- function(par,y,X=0,Z=0)
> {
>
>   n <- length(y)
>
>   e<-numeric(n)
>
>   yrep<-numeric(n)
>
>   yrep[1] <- y[1]
>
>   n.dummies.mean <- dim(X)[2]
>
>   if(is.matrix(X)) e[1] <- e[1]-sum(X[1,]*par[9:(8+n.dummies.mean)])
>
>   delta <- par[-(1:(8+n.dummies.mean))]
>
>   s2 <- var(y)
>
>   for(i in 2:n){
>
>     s2 <-
> par[5]+par[6]*e[i-1]^2+par[7]*ifelse(e[i-1]<0,1,0)*e[i-1]^2+par[8]*s2+sum(X[i,]*delta)
>
>     e[i] <- rnorm(1,0,sqrt(s2))
>
>     yrep[i]<-par[1]+par[2]*yrep[i-1]+par[3]*s2+par[4]*yrep[i-1]*s2+e[i]
>
>   }
>
>
>   if(is.matrix(X)) yrep <- yrep + X%*%par[9:(8+n.dummies.mean)]
>
>   yrep
> }
>
> yrep <- sim.gjr(a$estimate,y,X,Z)
>
>
> n.test <- 500
>
> Ch.mic <- Ch.mic.rep <- numeric(n.test)
>
> for(i in 1:n.test){
>
>   simulation <- sample(1:10000,1)
>
>   par <- sims.matrix[simulation,]
>
>   Ch.mic[i] <- test.mic(par,y,X,X)
>
>   yrep <- sim.gjr(par,y,X,X)
>
>   Ch.mic.rep[i] <- test.mic(par,yrep,X,X)
> }
>
>  plot(Ch.mic,Ch.mic.rep,xlim=c(0,6),ylim=c(0,6))
>
>  lines(c(0,6),c(0,6))
> --
> View this message in context: http://www.nabble.com/Need-some-help-in-R-programming-code-tp20634187p20634187.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list