eco-stats / mvabund

1 stars 1 forks source link

Unable to use `composition = TRUE` in `manyglm()` #4

Open hrdawson opened 3 months ago

hrdawson commented 3 months ago

Hi,

I'm trying to set composition = TRUE in manyglm() but each time I do it returns the error message:

Error in manyglm(copepods ~ block * treatment, family = "negative.binomial", : object 'data2' not found

I'm using a modification of the code in the original paper (doi: 10.1111/j.2041-210X.2012.00190.x).

data("Tasmania")

attach(Tasmania)

tas.nb <- manyglm(copepods ~ block*treatment, family = "negative.binomial", composition = TRUE)

I have this error both in the most recent CRAN version of mvabund and the GitHub dev version of mvabund. I'm running R v. 4.4.0.

Any ideas on how to set data2 or otherwise convince manyglm to work with relative compositions?

Thanks for the useful package!

dwarton commented 3 months ago

It looks like if the data argument has not been specified, comp=TRUE can't find the data. This is a bug I can work on fixing, in the meantime please use the data argument, e.g. library(mvabund) data("Tasmania") tas.nb <- manyglm(copepods ~ block*treatment, family = "negative.binomial", composition = TRUE, data=Tasmania)

Also, attach is generally frowned upon and best avoided for a few reasons, a couple are explained here

hrdawson commented 3 months ago

That's a very simple and easy workaround that works for me. Thank you!

Good to know about attach. I think I was copy-pasting code from an old tutorial.