Hello,

I'm working on a problem using nested for-loops and I don't know if it's a
problem with the order of the loops or something within the loop so any
help with the problem would be appreciated.  To briefly set up the problem.
 I have 259 trees (from 11 different species, of unequal count for each
species) of which I am trying to predict biomass.  For each tree species I
have 10000 iterations for the regression coefficients, which were estimated
previously in WinBUGS, and what I'm trying to do is for each tree I want to
predict the biomass using each species-specific iteration of the regression
coefficients, so that ultimately each tree has 10000 estimates of biomass,
organized into a 10000x259 matrix.  The input data used in the model
equation is stored in two separate files and I don't think this is creating
problems, but I thought it might be worth mentioning. I've pasted the code
below and if any additional info is needed please write back and I will
post it.

#read in the model output data from Jenkins eq. 1 under "data"
#read in the prediction data set under "predict data"

j1data=read.delim("reduced_j1_forR.txt",header=T)
predictdata=read.delim("predictset_forR.txt",header=T)
j1data=j1data[,2:4]
its=c(rep(1:10000,each=11))
j1data=cbind(its,j1data)

#set up a matrix full of zeros "lnbm" where prediction results are placed
#set up for loop that first loops over iteration, then species
#(total iterations=10000it/spp*11spp=110000 iterations)and then over each
tree
#(total # of trees=259)

niter=10000
nspp=11
ntrees=259

lnbm=matrix(0,10000,259)
k=numeric()
for (i in 1:ntrees)
{
for (j in 1:nspp)
{
     for (m in 1:niter)
{
k=((j1data$its[m]-1)*1000)+(j1data$spp[j])
#print(k)
lnbm[m,i]=j1data$b0[k]+j1data$b1[k]*predictdata$lndbh[i]
                  }
       }
}



Thanks

        [[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