Rmomal / EMtree

Infers species direct association networks
https://rmomal.github.io/EMtree/
7 stars 2 forks source link

model dateError in terms.formula(object, data = data) : ExtractVars里的模型公式不对 #2

Closed Hanqingpeng closed 3 years ago

Hanqingpeng commented 4 years ago

compare_output<-ComparEMtree(counts, covar_matrix=covar, models=tested_models, m_names=models_names, Pt=0.15, S=3, maxIter=5,cond.tol=1e-8,cores=1)

model dateError in terms.formula(object, data = data) : ExtractVars里的模型公式不对

Rmomal commented 4 years ago

Hi, Thank you for reporting this. Could you please give a minimal example of the covariates you used and the models you tested, so that I can look into the error more precisely ? Thank you very much.

vincentwb commented 3 years ago

I am also encountered this error when I run the code in "README.md" in the EMtree files.

library(ade4) library(tidyverse) data(baran95) counts = as.matrix(baran95$fau) covar = as_tibble(baran95$plan)

n = nrow(counts) p = ncol(counts)

r

head(counts)

> AMA CAS CHI CHL CJO CST CTR CWA CYS DAF EFI ELA GDE GME HFA HFO IAF LFA

> 1 0 2 0 3 0 0 0 0 0 0 71 1 5 6 0 0 7 3

> 2 0 1 0 0 0 0 0 0 0 0 118 2 3 0 0 0 8 1

> 3 0 2 0 3 0 0 0 0 0 0 69 0 6 2 0 0 8 3

> 4 0 0 0 2 0 0 0 0 0 0 56 0 0 0 0 0 1 0

> 5 0 0 0 0 0 0 0 0 3 0 0 1 1 0 0 0 2 2

> 6 0 0 0 0 0 0 0 0 5 0 0 0 2 0 0 0 0 0

> LGR LNI PAA PBR PEL PJU PLE PMO POQ PPA PQQ PTY SEB TIN TLE

> 1 3 0 0 5 2 9 26 0 4 0 0 0 22 0 2

> 2 7 0 0 0 0 0 113 0 1 0 0 1 18 0 1

> 3 0 0 0 1 0 3 0 0 1 0 0 0 3 0 0

> 4 2 0 0 0 0 0 0 0 0 0 0 0 15 0 0

> 5 5 0 0 0 3 0 0 0 4 0 0 3 0 0 0

> 6 9 0 0 2 4 4 0 2 0 0 0 1 0 0 0

head(covar)

> # A tibble: 6 x 2

> date site

>

> 1 apr93 km03

> 2 apr93 km03

> 3 apr93 km03

> 4 apr93 km03

> 5 apr93 km17

> 6 apr93 km17

#

Fit PLN model

This creates a PLNmodels object

r

library(PLNmodels) model<-PLN(counts ~ covar$site) library(EMtree) set.seed(3) output<-EMtree(model, maxIter = 10, plot=TRUE) str(output) library(parallel) resample_output<-ResampleEMtree(counts=counts, covar_matrix = covar$site , S=5, maxIter=10,cond.tol=1e-8, cores=1) str(resample_output) library(parallel) tested_models=list("date","site",c("date","site")) models_names=c("date","site","date + site") compare_output<-ComparEMtree(counts, covar_matrix=covar, models=tested_models, m_names=models_names, Pt=0.15, S=3, maxIter=5,cond.tol=1e-8,cores=1)

vincentwb commented 3 years ago

compare_output<-ComparEMtree(counts, covar_matrix=covar, models=tested_models, m_names=models_names, Pt=0.15, S=3, maxIter=5,cond.tol=1e-8,cores=1)

model dateError in terms.formula(object, data = data) : ExtractVars里的模型公式不对

No error when modify the code as follow.

tested_models=list(1,2,c(1,2)) models_names=c("date","site","date + site") compare_models<-ComparEMtree(Y, X, models=tested_models, m_names=models_names, Pt=2/p, S=3, maxIter=5,cond.tol=1e-8,cores=1)

vincentwb commented 3 years ago

compare_output<-ComparEMtree(counts, covar_matrix=covar, models=tested_models, m_names=models_names, Pt=0.15, S=3, maxIter=5,cond.tol=1e-8,cores=1)

model dateError in terms.formula(object, data = data) : ExtractVars里的模型公式不对

No error when modify the code as follow.

tested_models=list(1,2,c(1,2)) models_names=c("date","site","date + site") compare_models<-ComparEMtree(Y, X, models=tested_models, m_names=models_names, Pt=2/p, S=3, maxIter=5,cond.tol=1e-8,cores=1)

Rmomal commented 3 years ago

Hi @vincentwb,

Thank you for reporting this. I think the README.md you refer to is not up to date, I suggest you update your version of EMtree by downloading it again. This example of the ComparEMtree() function is now in the Fatala.Rmd vignette, and actually specifies the tested_models parameter exactly like you did in your last comment. I am interested in knowing if this function is useful to you ? I was thinking about deleting it.