Im trying to apply an simple formula y~x
to a function, in this case adonis {vegan}
when inside mapply
but I get Error: object of type 'symbol' is not subsettable.
Im running: mapply(adonis, formula=dist_list~group_list, data=group_list, SIMPLIFY=F)
, where dist_list is a list of distance matrices in dist class and group_list a list of factors. The same works with single dist and factor objects. This also works: mapply(betadisper, d = dist_list, group = group_list, SIMPLIFY=FALSE)
.
So the problem seem to be with the use of a formula
inside mapply
. I've been trying the use of substitute
but ending up with the same error.
Here's an attempt of providing a reproducible example:
data(varespec)
dis <- vegdist(varespec, method="bray")
dis1 <- vegdist(varespec,method="jaccard")
dis2 <- vegdist(varespec,method="mountford")
dist_list <- list(dis,dis1,dis2)
groups <- factor(c(rep(1,16), rep(2,8)), labels = c("grazed","ungrazed"))
groups1 <- factor(c(rep(1,10), rep(2,14)), labels = c("grazed","ungrazed"))
groups2 <- factor(c(rep(1,20), rep(2,4)), labels = c("grazed","ungrazed"))
group_list <- list(groups,groups1,groups2)
mapply(adonis, formula=dist_list~group_list, data=group_list, SIMPLIFY=F)
#Error: object of type 'symbol' is not subsettable
Any pointer to sort this out would be very much appreciated, thanks!
This seems to work though
mapply(function(x,y) adonis(x~y), dist_list, group_list, SIMPLIFY=FALSE)