[R-sig-ME] problem running mixed model including a phylogeny suggested in vignette "Covariance structure"
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Mon Mar 17 15:47:44 CET 2025
The short answer is that the *values* of the names are OK, but the
*order* is wrong (setdiff() only checks that the values are
equivalent, not the order). I will try to add some better
tests/diagnostics to the code.
On Thu, Mar 13, 2025 at 12:10 PM Pablo Inchausti
<pablo.inchausti.f using gmail.com> wrote:
>
> Hi,
> I have been trying to run the mixed model incorporating a phylogeny that is
> suggested in
> https://cran.r-project.org/web/packages/glmmTMB/vignettes/covstruct.html
> (section Proptional). I have encountered errors that I cannot resolve and
> hence this post.
>
> This is what I did:
> require(ade4); require(ape); require(glmmTMB)
>
> data(carni70) # loads the data
>
> carnidat <- data.frame(species = rownames(carni70$tab), carni70$tab)
>
> phylo <- read.tree(text=carni70$tre) # reads the phylogeny
>
> A <- vcv(phylo) # uses package ape to calculate the var-covar matrix from
> the phylogeny
>
> # verifies whether the species names of rows and columns of var-covar
> phylogenetic matrix are the same as those in the dataframe
>
> setdiff(carnidat$species, rownames(A)) # No!. I then correct them.
>
> carnidat$species=gsub("_", ".", carnidat$species) # corrects all species
> names
>
> setdiff(colnames(A), rownames(A)) # final check. All is fine.
>
> setdiff(carnidat$species, rownames(A)) # another final check. All is fine.
>
> carnidat$dummy <- factor(1) # a dummy grouping variable must be added to
> the dataset
>
> Then I ran the model:
>
> fit_phylo=glmmTMB(log(range)~log(size)+propto(0+species|dummy, A),
> data= carnidat)
>
> And I obtain the following error message:
>
> Error: column or row names of the matrix do not match the terms.
> Expecting names:
> ‘speciesAtelocynus.microtis’‘speciesBassariscus.alleni’‘
> speciesBassariscus.astutus’‘
> speciesBassariscus.beddardi’‘speciesBassariscus.gabbii’‘speciesBassariscus.lasius’‘speciesBassariscus.pauli’‘
> speciesBassariscus.sumichrasti’‘speciesCanis.latrans’‘speciesCanis.lupus’‘speciesCerdocyon.
>
> (This is much longer, but one can get the idea)
>
> Just in case, the same model does run using the package brms.
>
> I would appreciate very much any suggestion that you might have.
> Thanks in advance.
> Cheers
> Pablo
>
> > sessionInfo()R version 4.4.3 (2025-02-28)
> Platform: x86_64-pc-linux-gnu
> Running under: Ubuntu 22.04.5 LTS
>
>
> Attached base packages:
>
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] glmmTMB_1.1.10 ape_5.8
>
> loaded via a namespace (and not attached):
> [1] nlme_3.1-166 TH.data_1.1-2 estimability_1.5.1
> reformulas_0.3.0 xtable_1.8-4
> [6] minqa_1.2.8 zoo_1.8-12 TMB_1.9.15
> lme4_1.1-35.5 grid_4.4.3
> [11] MASS_7.3-61 mvtnorm_1.3-1 numDeriv_2016.8-1.1
> compiler_4.4.3 multcomp_1.4-26
> [16] codetools_0.2-20 sandwich_3.1-1 emmeans_1.10.5
> coda_0.19-4.1 Rcpp_1.0.13
> [21] mgcv_1.9-1 rstudioapi_0.16.0 lattice_0.22-6
> digest_0.6.37 nloptr_2.1.1
> [26] Rdpack_2.6.1 parallel_4.4.3 splines_4.4.3
> rbibutils_2.3 Matrix_1.7-0
> [31] tools_4.4.3 boot_1.3-31 survival_3.7-0
>
>
> >
>
> --
> *Pablo Inchausti*
> Profesor de Ecología
> Centro Universitario Regional del Este
> Universidad de la República,
> Avenida Cachimba del Rey
> Maldonado, Departamento de Maldonado CP 20100
> Uruguay
> *Phone*: +598.42.25.53.26 interno 602
>
> *Website*: https://sites.google.com/view/pablo-inchausti/iniciostart
> <https://sites.google.com/view/pablo-inchausti//iniciostart>
>
> *Book/Libro Statistical Modeling with R websites: *
>
> *https://sites.google.com/view/statistical-modeling-with-r/home
> <https://sites.google.com/view/statistical-modeling-with-r/home>*
> *https://global.oup.com/booksites/content/9780192859013/
> <https://global.oup.com/booksites/content/9780192859013/>*
>
> *Canal YouTube* Pablo Inchausti Estadistica: @PabloIEstadistica
> https://www.youtube.com/channel/UCKCknL2o8rzr7uumT-GDi7Q/a
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list