[R] how to store estimates results as scalars of a matrix?

Joao Pedro W. de Azevedo jazevedo at provide.com.br
Fri Jun 18 20:45:17 CEST 2004


Dear R users,

I've written a loop to generate Moran's test (spdep package) on serval
subsamples of a large dataset. See below a short example.

My loop is working fine, however I would like to be able to store the test
results as lines of a matrix, that I would latter be able to export as a
dataset. My problem is that I'm not sure how I could do this using R.

Any help will be much appreciated.

All the very best,

JP



coords2 <- as.matrix(jcdist.data[1:87, 6:7])

col.tri.nb<-tri2nb(coords2)

for(n in c(1,88,175,262,349)) {
    f<- n+86
    work <- jcdist.data[n:f, 10:12]

    res <-moran.test(spNamedVec("res1", work), nb2listw(col.tri.nb,
style="W"))
    moran<-res$estimate[1]
    upper<-res$estimate[1] + (qnorm(0.025, lower.tail=FALSE)
*sqrt(res$estimate[3]))
    lower<-res$estimate[1] - (qnorm(0.025, lower.tail=FALSE)
*sqrt(res$estimate[3]))
    
    print(moran)
    print(upper)
    print(lower)

}

+ 
+ }
Moran I statistic 
         0.659114 
Moran I statistic 
        0.7802115 
Moran I statistic 
        0.5380164 
Moran I statistic 
         0.650799 
Moran I statistic 
         0.771808 
Moran I statistic 
        0.5297899 
Moran I statistic 
        0.6513354 
Moran I statistic 
        0.7723458 
Moran I statistic 
        0.5303249 
Moran I statistic 
        0.6614869 
Moran I statistic 
        0.7825066 
Moran I statistic 
        0.5404672 
Moran I statistic 
        0.6429097 
Moran I statistic 
        0.7638195 
Moran I statistic 
        0.5219998




More information about the R-help mailing list