Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rhs/data issue in amova #2

Merged
merged 2 commits into from Apr 30, 2015
Merged

Fix rhs/data issue in amova #2

merged 2 commits into from Apr 30, 2015

Conversation

zkamvar
Copy link
Contributor

@zkamvar zkamvar commented Apr 9, 2015

When running amova using a data frame, it would error because of line 18, where it was trying to retrieve an object that didn't exist. This is bypassed if the data is present in a data.frame:

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)

When running amova using a data frame, it would error because of line 18, where it was trying to retrieve an object that didn't exist. This is bypassed if the data is present in a data.frame
@zkamvar
Copy link
Contributor Author

zkamvar commented Apr 29, 2015

Any word on this? Good? Bad?

@emmanuelparadis
Copy link
Owner

Wed, 29 Apr 2015 08:45:42 -0700 "Zhian N. Kamvar"
notifications@github.com:

Any word on this? Good? Bad?

Thanks for the reminder. I'll have a look at it very soon.

@emmanuelparadis
Copy link
Owner

There seems to be a problem when the rhs is not a factor. I get an error:

> res <- fixed.amova(d ~ g, DF, nperm = 100)
Error in FUN(X[[i]], ...) : 'bin' must be numeric or a factor
> str(DF$g)
 chr [1:15] "A" "A" "A" "A" "A" "A" "A" ...

But not if the rhs is in the global env.:

> res <- fixed.amova(d ~ g, nperm = 100)
Warning message:
In fixed.amova(d ~ g, nperm = 100) :
  elements in the rhs of the formula are not all factors
> str(g)
 chr [1:15] "A" "A" "A" "A" "A" "A" "A" ...

It's just a warning because of StAMMP (I guess you've seen the comment in the source).

I think there's a possibility to use the envir option in get even with a data.frame:

> get("g", envir = as.environment(DF))
 [1] "A" "A" "A" "A" "A" "A" "A" "B" "B" "B" "B" "B" "B" "B"
[15] "B"

This'd solve the initial bug.

@zkamvar
Copy link
Contributor Author

zkamvar commented Apr 30, 2015

Good points. I think I have addressed this in my latest commit. I created a new variable to contain the environment where the data lives and placed an explicit "get" call in the control structure checking for factors.

emmanuelparadis added a commit that referenced this pull request Apr 30, 2015
Fix rhs/data issue in amova
@emmanuelparadis emmanuelparadis merged commit 45bd3ff into emmanuelparadis:master Apr 30, 2015
@emmanuelparadis
Copy link
Owner

Perfect! I've merged and updated the files. Many thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants