[R-sig-eco] NA error in envfit

Jari Oksanen jari.oksanen at oulu.fi
Fri Dec 6 20:54:15 CET 2013


Kendra,

Are you sure that it was a factor? I am unable to trigger an error with a one-level factor in vegan 2.0-9. Moreover, the error message you sent was from vectorfit and factors (also one-level factors) are not handled in that function but they go to factorfit, and error should come from factorfit.  Character strings  variable go to vectorfit (instead of factorfit) and gives exactly that error and from vectorfit. 

I don't ask these things out of my meanness, but I want to fix these functions for the next release. I have now found one problem and I have fixed that in R-Forge. If there are some other problems, I want to fix them, too. Therefore I really want to know what happened with your application. I try to reproduce your problems, but this is kind of blind watchmaker's works as I don't have a reproducible test case. Therefore I have to ask stubbornly.

Cheers, Jari Oksanen
On 06/12/2013, at 21:35 PM, Mitchell, Kendra wrote:

> My offending variable was correctly imported as a factor, but since I was subsetting the data to look only at one zone at a time it was a factor with only one level
> 
> 
> --
> Kendra Maas Mitchell, Ph.D.
> Post Doctoral Research Fellow
> University of British Columbia
> 604-822-5646
> 
> ________________________________________
> From: Gavin Simpson [ucfagls at gmail.com]
> Sent: Friday, December 06, 2013 11:09 AM
> To: Dixon, Philip M [STAT]
> Cc: Mitchell, Kendra; r-sig-ecology at r-project.org
> Subject: Re: [R-sig-eco] NA error in envfit
> 
> Phillip,
> 
> You approach to using factors misses an important consideration; the
> class that was observed in the full dataset should not disappear just
> because you subsetted the data in some manner. Also, `droplevels()` is
> a useful function to call on a factor or data frame if subsetting
> produces levels with zero observations and if that information is not
> made use on in whatever computations follow next.
> 
> G
> 
> On 5 December 2013 10:42, Dixon, Philip M [STAT] <pdixon at iastate.edu> wrote:
>> Kendra,
>> 
>> I wonder if the problem is a factor level with no observations.  One of the frustrating things about factors (class variables) in R is that the list of levels is stored separately from the data.  This can cause all sorts of problems if you create the factor, then subset the data, and the subset is missing one or more levels of the factor.  You are subsetting your data, so this may be the source of the problem.
>> 
>> My working philosophy is to keep variables as character strings or numbers until just before I need the factors.  That avoids any issues with extraneous levels.  That means reading data sets (.txt or .csv files) with as.is=TRUE to avoid default creation of factors.  relevel() may recreate the list of levels.  I usually use factor(as.character(variable)) to flip a factor to a vector of character strings then back to a factor with the correct set of levels.
>> 
>> Best wishes,
>> Philip Dixon
>> 
>> 
>>        [[alternative HTML version deleted]]
>> 
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> 
> 
> 
> --
> Gavin Simpson, PhD
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list