Hi everyone,

I was wondering if I could get some help with a code I'm working on, which
is not working.  I'm trying to predict species abundances within a
community by using the first axis of a principal component analysis of the
community leaving out the species of interest.  The hypothesis being that
species abundances should be well predicted by other species in the
community.

My code is as follows using the dune dataset from the vegan package:

library(vegan)
data(dune)

finaldata <- data.frame(a= 0, b= 0, c= 0) #empty dataframe to put data into
species <- colnames(dune)

for (i in 1: 30) {
  species.i <- species[i]
  community.i <- dune
  community.i$species.i <- NULL
  comm.i.hel <- decostand(community.i, "hellinger")
  com.pca.i <- rda(comm.i.hel) # pca on community without species i
  site.score <- com.pca.i$CA$u
  site.score.pc1 <- site.score[, 1]
  spe.site.i <- dune$species.i
  predict.i <- summary(lm(spe.site.i~ site.score.pc1)) # regress pc1
against species i abund at each site
      r.sq.i <- predict.i$r.squared
      p.val.i <- predict.i$p.value
  finaldata[i,] <- cbind(species.i, r.sq.i, p.val.i) #store relevant info
for each species in the empty dataframe
}

When the loop gets to the linear regression part it gives an error saying
that spe.site.i is NULL.  I guess that's because I assigned it as a NULL
variable.  Does anyone know how to fix this?  The code is not making the
species.i null, it's making a new variable called species.i and making that
null, I think.

Any comments or suggestions would be appreciated.  Thank you so much!

Vincenzo

	[[alternative HTML version deleted]]

