AndrewLJackson / siar

Stable Isotope Analysis in R - package
24 stars 5 forks source link

Groups not in order #14

Closed andrewcparnell closed 1 year ago

andrewcparnell commented 8 years ago

It seems that SIAR will run but produce incorrect results if you put the groups in the wrong order.

MRE:

library(siar)

data(geese2demo, sourcesdemo, correctionsdemo, concdepdemo)

# Run on first 2 groups
run = siarmcmcdirichletv4(geese2demo[1:38,], sourcesdemo, correctionsdemo, concdepdemo)
siarhistograms(run) # Choose group 1

# Now shuffle groups
run2 = siarmcmcdirichletv4(geese2demo[sample(1:38),], sourcesdemo, correctionsdemo, concdepdemo)
siarhistograms(run2) # Choose group 1

These two will produce different results without an error or a warning.

I suggest adding a line beneath numgroups <- max(data[, 1]) in siarmcmcdirichletv4 which says something like:

if(!identical(data[,1], sort(data[,1]))) stop("Group variable must be in order")
DiegoNabaesJodar commented 6 years ago

I just spent hours trying to figure out why the raw data plot was not corresponded by the other plots... I suggest (at least) emending  the tutorial "SIAR V4 (Stable Isotope Analysis in R) An Ecologist’s Guide" and any others, to clarify the need for the sequential order of the consumer groups. Best, Diego.