Laura MartÃnez Suz
2012-Dec-29 20:40 UTC
[R] Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical subscript too long
Hello there, I'm trying to plot vectors with p<0.1 in a NMDS ordination plot using p.max. Below the scripts I'm using. I guess I'm missing something! could you please give me a hand? species<-metaMDS(species_matrix)ef<-envfit(species,environmentaldata_file,permu=999,na.rm=TRUE)efplot(species, dis="sites")plot(ef,p.max=0.1) Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical subscript too long Many thanks! Laura [[alternative HTML version deleted]]
Gavin Simpson
2012-Dec-30 12:16 UTC
[R] Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical subscript too long
On Sat, 2012-12-29 at 20:40 +0000, Laura Mart?nez Suz wrote:> Hello there, > I'm trying to plot vectors with p<0.1 in a NMDS ordination plot using p.max. Below the scripts I'm using. I guess I'm missing something! could you please give me a hand? > species<-metaMDS(species_matrix)ef<-envfit(species,environmentaldata_file,permu=999,na.rm=TRUE)efplot(species, dis="sites")plot(ef,p.max=0.1) > Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical subscript too long > Many thanks! > LauraHi Laura, Can you send the data to me **off list** so I can run through the code under the debugger and see what is causing the error? I can see where the subscripting occurs related to p.max but can't immediately see under what circumstances the subscript could ever get longer than the object being subscripted. I promise to delete the data once I have tracked the problem down. Cheers, G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson
2012-Dec-31 22:05 UTC
[R] Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical subscript too long
Hi Laura, Following a bit of further digging, I noticed that the bug was in not handling the levels of the factor constraints appropriately. In your data set 12 rows (observations) were deleted because of missing data. These observations meant that one or more of the factor variables had more levels() than actually used in the subset of data analysed. I have checked in some fixes for this which removes the extraneous levels: https://r-forge.r-project.org/scm/viewvc.php?view=rev&root=vegan&revision=2342 We are currently planning a release for some time in the new year, but in the meantime, you can get a copy of the development version of Vegan from R-forge once the new binary has been built (needs to be Rev 2342 or later to include this fix but only Rev 2341 has been built thus far): https://r-forge.r-project.org/R/?group_id=68 I've CC'd this back to R-Help for the record. Thanks for taking the time to post about this and for sending me your data so I could track this down quickly. All the best and Happy New Year. G On Mon, 2012-12-31 at 14:17 +0000, Laura Mart?nez Suz wrote:> Hi Gavin, > > > Thank you! It works now, that's great, many thanks. I have spent hours > trying to see what I was doing wrong, I'm not very good in R.. > > > That was my first email to the R community, should I "officialy" reply > to you? > > > All the best for you as well and happy New Year! > > > Laura > > > > > Subject: RE: [R] Error in plot.envfit(ef, p.max = 0.1) : (subscript) > logical subscript too long > > From: gavin.simpson at ucl.ac.uk > > To: lauramsuz at hotmail.com > > CC: lauramsuz at um.es > > Date: Mon, 31 Dec 2012 12:02:09 +0100 > > > > Hi Laura, > > > > Thanks for this. There is a bug which has lead me to discover > another > > bug in that same section of code. The issue you uncovered is that > you > > have factor variables but none are significant at the level you > > requested and we don't handle the "no significant factors" case > > explicitly. That led me to find another bug in that I don't think > this > > code to select significant factors ever worked correctly. > > > > I'll need to speak to Jari about this as he wrote the code, but he > is > > away at the moment. I'll see about coming up with a fix for this. > > > > In the meantime, I presume this will work for you as the factors are > not > > significant, just drop them before doing the envfit() call: > > > > facs <- sapply(enviromentaldata_file, is.factor) > > env <- enviromentaldata_file[, !facs] > > > > ef <- envfit(species, env, permutations = 999, na.rm = TRUE) > > > > plot(species, display = "sites") > > plot(ef, p.max = 0.1) > > > > HTH and thanks for providing the data. I'll delete it now. > > > > All the best, > > > > Gavin > > > > On Sun, 2012-12-30 at 15:25 +0000, Laura Mart?nez Suz wrote: > > > Hi Gavin, > > > > > > > > > Many thanks! Here they go, named as in the scripts. > > > > > > > > > species_matrix is the file with the relative abundance of each > species > > > (394) related to the total number of species in each plot (22). > > > > > > > > > environmentaldata_file corresponds to data from the 22 plots in > the > > > same order than in the species file. > > > > > > > > > I wanted to see which factors are affecting the dissimilarities in > > > community composition among plots and plot the significant ones as > > > vectors at p<0.1. > > > > > > > > > Sorry if it becomes a silly thing and thanks again for your > offer.. > > > and yes, please, delete them! :) > > > > > > > > > Regards, > > > > > > > > > Laura > > > > > > > > > > Subject: Re: [R] Error in plot.envfit(ef, p.max = 0.1) : > (subscript) > > > logical subscript too long > > > > From: gavin.simpson at ucl.ac.uk > > > > To: lauramsuz at hotmail.com > > > > CC: r-help at r-project.org > > > > Date: Sun, 30 Dec 2012 13:16:56 +0100 > > > > > > > > On Sat, 2012-12-29 at 20:40 +0000, Laura Mart?nez Suz wrote: > > > > > Hello there, > > > > > I'm trying to plot vectors with p<0.1 in a NMDS ordination > plot > > > using p.max. Below the scripts I'm using. I guess I'm missing > > > something! could you please give me a hand? > > > > > > > > > species<-metaMDS(species_matrix)ef<-envfit(species,environmentaldata_file,permu=999,na.rm=TRUE)efplot(species, dis="sites")plot(ef,p.max=0.1) > > > > > Error in plot.envfit(ef, p.max = 0.1) : (subscript) logical > > > subscript too long > > > > > Many thanks! > > > > > Laura > > > > > > > > Hi Laura, > > > > > > > > Can you send the data to me **off list** so I can run through > the > > > code > > > > under the debugger and see what is causing the error? I can see > > > where > > > > the subscripting occurs related to p.max but can't immediately > see > > > under > > > > what circumstances the subscript could ever get longer than the > > > object > > > > being subscripted. > > > > > > > > I promise to delete the data once I have tracked the problem > down. > > > > > > > > Cheers, > > > > > > > > G > > > > > > > > -- > > > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~%~ > > > % > > > > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > > > > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > > > > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > > > > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ > > > > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > > > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > %~%~ > > > % > > > > > > > > > > > -- > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > % > > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 > > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 > > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk > > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ > > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~ > % > > >-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%