Skip to content

genind2hierfstat

7 messages · Libby Liggins, Jombart, Thibaut, Eric Crandall +1 more

#
Hi Thibaut and Jerome -

The interoperability that you are building between your packages is
fantastic! But, I am having trouble with the genind2hierfstat function. It
doesn't seem to exist in either adegenet 2.0 or the development version of
hierfstat. I apologise if I missing something.

Thanks,
Libby.
#
Hi Libby, 

yes, it has been removed from adegenet and internalized in hierfstat. I think the idea is that ultimately all procedures in hierfstat will work directly with genind objects, so conversion will not be needed any more. 

For now, we still cheat, and use genind2hierfstat inside hierfstat. This function is hidden (.genind2hierfstat), and not exported. To access it, you need:

hierfstat:::.genind2hierfstat

(with the current devel of hierfstat)

Best
Thibaut

==============================
Dr Thibaut Jombart
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - School of Public Health
Norfolk Place, London W2 1PG, UK
Tel. : 0044 (0)20 7594 3658
http://sites.google.com/site/thibautjombart/
http://sites.google.com/site/therepiproject/
http://adegenet.r-forge.r-project.org/
Twitter: @thibautjombart
#
Great, thanks Thibaut!

Libby.

On Thu, Jul 16, 2015 at 10:47 PM, Jombart, Thibaut <t.jombart at imperial.ac.uk

  
  
4 days later
#
Hi Emmanuel or others,

	I was directed here to ask a question about the amova function in pegas. Hopefully this is the right place.

	 I have been using pegas::amova() in a function that loops over a database of species to calculate amova at up to three hierarchical levels. My function recently broke, apparently due to a recent update <https://cran.r-project.org/web/packages/pegas/NEWS> to Pegas - specifically this change:

    o amova() failed when the factors in the rhs of the formula were
      in a data frame. Thanks to Zhian Kamvar for the fix.

As a workaround to for pegas:amova not being able to use a dataframe of factors, I was assigning the factors to the global environment:

      level1factor<<-as.factor(sp[[l1]])
      level2factor<<-as.factor(sp[[l2]])
      amova_out<-pegas::amova(dists~level2factor/level1factor, nperm=nperm, is.squared=T)


Now, after the update, my function is throwing an error. The traceback goes

4 stop("'bin' must be numeric or a factor") 
3 FUN(X[[i]], ...) 
2 lapply(gr, tabulate) 
1 pegas::amova(dists ~ level2factor/level1factor, nperm = nperm, 
    is.squared = T) 

As far as I can tell, the objects that I am submitting to tabulate() in gr via lapply() ARE factors. 

When I try to reproduce the problem by running step by step through the pegas::amova function, everything works fine. 

So I am stumped for now. Does anyone have any ideas?


Many thanks,

Eric Crandall



PS - I?m very happy to see strata being added to genind objects in adegenet. Will these eventually be usable by pegas::amova or a similar amova function?
#
Hi Eric,

Can you provide a minimum working example and post your session information?

The following example works for me (adapted from https://github.com/emmanuelparadis/pegas/pull/2#issue-67437033):

library('pegas')
data(microbov)
set.seed(20150409)
mic20 <- microbov[sample(nInd(microbov), 20)]
microdf <- data.frame(other(mic20))
d <- dist(tab(mic20))
amova(d ~ spe/breed, data = microdf, nperm = 0)

SPE   <<- as.factor(microdf$spe)
BREED <<- as.factor(microdf$breed)
amova(d ~ SPE/BREED, nperm = 0)
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] pegas_0.8-1    adegenet_2.0.0 ade4_1.7-2     ape_3.3       

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6      spdep_0.5-88     plyr_1.8.3       LearnBayes_2.15  tools_3.2.1     
 [6] boot_1.3-16      digest_0.6.8     nlme_3.1-120     gtable_0.1.2     lattice_0.20-31 
[11] Matrix_1.2-1     igraph_1.0.1     shiny_0.12.1     DBI_0.3.1        parallel_3.2.1  
[16] proto_0.3-10     coda_0.17-1      dplyr_0.4.2      stringr_1.0.0    grid_3.2.1      
[21] R6_2.1.0         sp_1.1-1         ggplot2_1.0.1    reshape2_1.4.1   seqinr_3.1-3    
[26] deldir_0.1-9     magrittr_1.5     scales_0.2.5     htmltools_0.2.6  MASS_7.3-41     
[31] splines_3.2.1    assertthat_0.1   mime_0.3         colorspace_1.2-6 xtable_1.7-4    
[36] httpuv_1.3.2     stringi_0.5-5    munsell_0.4.2  

The data frame implementation works now, so you can use your strata directly instead of pulling the levels from it:

my_strata <- strata(my_data)
amova_out <- pegas::amova(dists~l2/l1, data = my_strata, nperm=nperm, is.squared=T)

Additionally, poppr has a wrapper to ADE4's implementation of AMOVA that explicitly handles strata called poppr.amova.

Cheers,
Zhian
#
Hi Eric,

Can you provide a minimum working example and post your session information?

The following example works for me (adapted from https://github.com/emmanuelparadis/pegas/pull/2#issue-67437033):

library('pegas')
data(microbov)
set.seed(20150409)
mic20 <- microbov[sample(nInd(microbov), 20)]
microdf <- data.frame(other(mic20))
d <- dist(tab(mic20))
amova(d ~ spe/breed, data = microdf, nperm = 0)

SPE   <<- as.factor(microdf$spe)
BREED <<- as.factor(microdf$breed)
amova(d ~ SPE/BREED, nperm = 0)
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] pegas_0.8-1    adegenet_2.0.0 ade4_1.7-2     ape_3.3       

loaded via a namespace (and not attached):
[1] Rcpp_0.11.6      spdep_0.5-88     plyr_1.8.3       LearnBayes_2.15  tools_3.2.1     
[6] boot_1.3-16      digest_0.6.8     nlme_3.1-120     gtable_0.1.2     lattice_0.20-31 
[11] Matrix_1.2-1     igraph_1.0.1     shiny_0.12.1     DBI_0.3.1        parallel_3.2.1  
[16] proto_0.3-10     coda_0.17-1      dplyr_0.4.2      stringr_1.0.0    grid_3.2.1      
[21] R6_2.1.0         sp_1.1-1         ggplot2_1.0.1    reshape2_1.4.1   seqinr_3.1-3    
[26] deldir_0.1-9     magrittr_1.5     scales_0.2.5     htmltools_0.2.6  MASS_7.3-41     
[31] splines_3.2.1    assertthat_0.1   mime_0.3         colorspace_1.2-6 xtable_1.7-4    
[36] httpuv_1.3.2     stringi_0.5-5    munsell_0.4.2  

The data frame implementation works now, so you can use your strata directly instead of pulling the levels from it:

my_strata <- strata(my_data)
amova_out <- pegas::amova(dists~l2/l1, data = my_strata, nperm=nperm, is.squared=T)

Additionally, poppr has a wrapper to ADE4's implementation of AMOVA that explicitly handles strata called poppr.amova.

Cheers,
Zhian
2 days later
#
Hi Zhian,

	Thanks for your quick reply, and sorry for being a bit slow on this end. 

	Perhaps it is something specific to my system. I cannot run your example. See below.

Thanks again,

Eric



library('pegas')
data(microbov)
set.seed(20150409)
mic20 <- microbov[sample(nInd(microbov), 20)]
microdf <- data.frame(other(mic20))
d <- dist(tab(mic20))
amova(d ~ spe/breed, data = microdf, nperm = 0)
Error in FUN(X[[i]], ...) : 'bin' must be numeric or a factor

SPE   <<- as.factor(microdf$spe)
BREED <<- as.factor(microdf$breed)
amova(d ~ SPE/BREED, nperm = 0)
Error in FUN(X[[i]], ...) : 'bin' must be numeric or a factor
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] gdata_2.17.0      hierfstat_0.04-14 gtools_3.5.0      iNEXT_2.0.3       strataG_0.9.4     plyr_1.8.3        mmod_1.3.0        pegas_0.8-1       adegenet_2.0.0    ape_3.3          
[11] seqinr_3.1-3      ade4_1.7-2       

loaded via a namespace (and not attached):
 [1] Rcpp_0.11.6      spdep_0.5-88     mapdata_2.2-4    LearnBayes_2.15  tools_3.2.1      boot_1.3-17      digest_0.6.8     gtable_0.1.2     nlme_3.1-121     lattice_0.20-33  Matrix_1.2-2    
[12] igraph_1.0.1     shiny_0.12.1     DBI_0.3.1        parallel_3.2.1   proto_0.3-10     coda_0.17-1      dplyr_0.4.2      stringr_1.0.0    maps_2.3-10      swfscMisc_1.0.3  grid_3.2.1      
[23] R6_2.1.0         sp_1.1-1         ggplot2_1.0.1    reshape2_1.4.1   deldir_0.1-9     magrittr_1.5     scales_0.2.5     htmltools_0.2.6  MASS_7.3-43      splines_3.2.1    assertthat_0.1  
[34] mime_0.3         colorspace_1.2-6 xtable_1.7-4     httpuv_1.3.2     stringi_0.5-5    munsell_0.4.2