[R] loop for, error: obj type 'closure' not subsetable

Rafael_Leon rafleon at highstat.cl
Thu Jul 26 07:40:09 CEST 2012


Hi everyone,

I've got the following problem:

I've got a matrix [1000,2] and two vectors. In very matrix row there is  two
coefficients b0 and b1. The vectors are two variables x and y.  I want to do
a loop to take b0 and b1 and with x and y calculate the residual of a linear
model and calculate the second order coefficient of autocorrelation. What I
did is :

rho<-function(mat, x,y){
rhoes=rep(0,dim(mat)[1])
for (i in 1:dim(mat)[1]){
        
           
rhoes[i]=acf(y-(mat[i,1]+mat[i,2]*x),type="correlation",plot=FALSE)$acf[2]
#explanation below

    }
    print(rho[i])

}

I'm getting this error:
Error in rho[i] : object of type 'closure' is not subsettable

Any help will be deeply appreciated,

Cheers,

Rafael

P.S.
mat[i,1]=b0
mat[i,2]=b1
mat[i,1]+mat[i,2]*x= y estimated
y-(mat[i,1]+mat[i,2]*x)= errors (residuals)
acf= R function to calculate autocorrelation
$acf[2] = to extract 2nd order autocorrelation



--
View this message in context: http://r.789695.n4.nabble.com/loop-for-error-obj-type-closure-not-subsetable-tp4637873.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list