[R] sem package subscript out of bounds error

Jarrett Byrnes jebyrnes at ucdavis.edu
Mon Nov 20 06:31:32 CET 2006


I'm having the most curious error while using the sem package.  For  
the model I'm working with, I keep getting the following error:

Error in J[cbind(1:n, observed)] <- 1 : subscript out of bounds


I''ve used debug=TRUE with sem, and there don't appear to be any  
problems with model - there are no latent variables in this model.   
The variables in the covariance matrix are all in the model.  I've  
tried this with simpler version of the below model, and keep getting  
the same error.

What does this error mean?

Below is the full code, but I've tried this with all sorts of subsets  
of the model, making sure to keep all of the proper error terms.

---

fish.invert.data<-data.frame(Prev.Year.Predatory.Invert.Abundance,
						Prev.Year.Predatory.Fish.Abundance,
						Predatory.Invert.Abundance,
						Predatory.Fish.Abundance,
						Prev.Year.Herbivorous.Invert.Abundance,
						Prev.Year.Herbivorous.Fish.Abundance,
						Herbivorous.Invert.Abundance,
						Herbivorous.Fish.Abundance,
						Kelp.Abundance,
						Prev.Year.Kelp.Abundance,
						Mean.Temp.C,
						Prev.Year.Herbivore.Abundance)


#na.rm=TRUE to deal with a few rows of missing data	
fish.invert.covar<-var(fish.invert.data, na.rm=TRUE)

fish.invert.model<-specify.model()
Prev.Year.Predatory.Invert.Abundance ->  
Prev.Year.Herbivorous.Invert.Abundance, pred.invert.top.down, NA
Predatory.Invert.Abundance -> Herbivorous.Invert.Abundance,  
pred.invert.top.down, NA
Prev.Year.Predatory.Fish.Abundance ->  
Prev.Year.Herbivorous.Fish.Abundance, pred.fish.top.down, NA
Predatory.Fish.Abundance -> Herbivorous.Fish.Abundance,  
pred.fish.top.down, NA
Prev.Year.Predatory.Fish.Abundance ->  
Prev.Year.Herbivorous.Invert.Abundance, pred.fish.invert.top.down, NA
Predatory.Fish.Abundance -> Herbivorous.Invert.Abundance,  
pred.fish.invert.top.down, NA
Prev.Year.Herbivorous.Fish.Abundance -> Prev.Year.Kelp.Abundance,  
top.down.herb.fish, NA
Prev.Year.Herbivorous.Invert.Abundance -> Prev.Year.Kelp.Abundance,  
top.down.herb.invert, NA
Herbivorous.Fish.Abundance -> Kelp.Abundance, top.down.herb.fish, NA
Herbivorous.Invert.Abundance -> Kelp.Abundance, top.down.herb.invert, NA
Prev.Year.Kelp.Abundance -> Herbivorous.Fish.Abundance,  
bottom.up.kelp.fish, NA
Prev.Year.Kelp.Abundance -> Herbivorous.Invert.Abundance,  
bottom.up.kelp.inverts, NA
Prev.Year.Herbivorous.Fish.Abundance -> Predatory.Fish.Abundance,  
bottom.up.herb.fish, NA
Prev.Year.Herbivorous.Invert.Abundance -> Predatory.Invert.Abundance,  
bottom.up.herb.invert, NA
Prev.Year.Herbivorous.Invert.Abundance -> Predatory.Fish.Abundance,  
bottom.up.herb.invert.fish, NA
Mean.Temp.C -> Kelp.Abundance, mean.nutrients.from.temp, NA
Prev.Year.Predatory.Invert.Abundance -> Predatory.Invert.Abundance,  
prev.year.pred.invert, NA
Prev.Year.Predatory.Fish.Abundance -> Predatory.Fish.Abundance,  
prev.year.pred.fish, NA
Prev.Year.Herbivorous.Fish.Abundance -> Herbivorous.Fish.Abundance,  
prev.year.herb.fish, NA
Prev.Year.Herbivorous.Invert.Abundance ->  
Herbivorous.Invert.Abundance, prev.year.herb.invert, NA
Prev.Year.Kelp.Abundance -> Kelp.Abundance, prev.year.kelp, NA
Kelp.Abundance <-> Kelp.Abundance, kelp.abundance.error, NA
Prev.Year.Kelp.Abundance<-> Prev.Year.Kelp.Abundance,  
prev.year.kelp.error, NA
Mean.Temp.C <-> Mean.Temp.C, mean.temp.error, NA
Prev.Year.Herbivorous.Fish.Abundance <->  
Prev.Year.Herbivorous.Fish.Abundance, prev.herb.fish.error, NA
Prev.Year.Herbivorous.Invert.Abundance <->  
Prev.Year.Herbivorous.Invert.Abundance, prev.herb.invert.error, NA
Prev.Year.Predatory.Fish.Abundance <->  
Prev.Year.Predatory.Fish.Abundance, prev.pred.fish.error, NA
Prev.Year.Predatory.Invert.Abundance <->  
Prev.Year.Predatory.Invert.Abundance, prev.pred.invert.error, NA
Herbivorous.Fish.Abundance <->  
Herbivorous.Fish.Abundance,herb.fish.error, NA
Herbivorous.Invert.Abundance <-> Herbivorous.Invert.Abundance,  
herb.invert.error, NA
Predatory.Fish.Abundance <-> Predatory.Fish.Abundance,  
pred.fish.error, NA
Predatory.Invert.Abundance <-> Predatory.Invert.Abundance,  
pred.invert.error, NA

fish.invert.model

fish.invert.sem<-sem(fish.invert.model, fish.invert.covar, N=166,  
debug=TRUE)


Yields

observed variables:
[1] "1:Prev.Year.Predatory.Invert.Abundance"    
"2:Prev.Year.Predatory.Fish.Abundance"      
"3:Predatory.Invert.Abundance"
[4] "4:Predatory.Fish.Abundance"                
"5:Prev.Year.Herbivorous.Invert.Abundance"  
"6:Prev.Year.Herbivorous.Fish.Abundance"
[7] "7:Herbivorous.Invert.Abundance"            
"8:Herbivorous.Fish.Abundance"             "9:Kelp.Abundance"
[10] "10:Prev.Year.Kelp.Abundance"               
"11:Mean.Temp.C"                            
"12:Prev.Year.Herbivore.Abundance"


parameters:
[1] "1:pred.invert.top.down"        "2:pred.fish.top.down"           
"3:pred.fish.invert.top.down"   "4:top.down.herb.fish"
[5] "5:top.down.herb.invert"        "6:bottom.up.kelp.fish"          
"7:bottom.up.kelp.inverts"      "8:bottom.up.herb.fish"
[9] "9:bottom.up.herb.invert"       "10:bottom.up.herb.invert.fish"  
"11:mean.nutrients.from.temp"   "12:prev.year.pred.invert"
[13] "13:prev.year.pred.fish"        "14:prev.year.herb.fish"         
"15:prev.year.herb.invert"      "16:prev.year.kelp"
[17] "17:kelp.abundance.error"       "18:prev.year.kelp.error"        
"19:mean.temp.error"            "20:prev.herb.fish.error"
[21] "21:prev.herb.invert.error"     "22:prev.pred.fish.error"        
"23:prev.pred.invert.error"     "24:herb.fish.error"
[25] "25:herb.invert.error"          "26:pred.fish.error"             
"27:pred.invert.error"


RAM:
       heads to from parameter start
[1,]     1  5    1         1    NA
[2,]     1  7    3         1    NA
[3,]     1  6    2         2    NA
[4,]     1  8    4         2    NA
[5,]     1  5    2         3    NA
[6,]     1  7    4         3    NA
[7,]     1 10    6         4    NA
[8,]     1 10    5         5    NA
[9,]     1  9    8         4    NA
[10,]     1  9    7         5    NA
[11,]     1  8   10         6    NA
[12,]     1  7   10         7    NA
[13,]     1  4    6         8    NA
[14,]     1  3    5         9    NA
[15,]     1  4    5        10    NA
[16,]     1  9   11        11    NA
[17,]     1  3    1        12    NA
[18,]     1  4    2        13    NA
[19,]     1  8    6        14    NA
[20,]     1  7    5        15    NA
[21,]     1  9   10        16    NA
[22,]     2  9    9        17    NA
[23,]     2 10   10        18    NA
[24,]     2 11   11        19    NA
[25,]     2  6    6        20    NA
[26,]     2  5    5        21    NA
[27,]     2  2    2        22    NA
[28,]     2  1    1        23    NA
[29,]     2  8    8        24    NA
[30,]     2  7    7        25    NA
[31,]     2  4    4        26    NA
[32,]     2  3    3        27    NA
Error in J[cbind(1:n, observed)] <- 1 : subscript out of bounds



More information about the R-help mailing list