llrs / experDesign

Design experiments distributed in several batches
https://experDesign.llrs.dev
Other
10 stars 1 forks source link

`spatial()` assigns multiple samples to the same plate position in the same batch #45

Closed AnnaPagotto closed 11 months ago

AnnaPagotto commented 11 months ago

Hi Lluís, thank you for this amazing package. I'm using it for my project, but I encountered some issues when distributing the samples in the plate grid. I have some cases where spatial() assigns the same position in the same batch to two samples. Could you help me with that?

Thank you a lot! Best, Anna

llrs commented 11 months ago

Hi Anna, happy to hear from a happy user.

Sorry to hear that spatial doesn't fully work. I think I tested to prevent this from happening, but I will give it a look. Could you provide the code where this happens? This way I will make sure it won't happen again.

AnnaPagotto commented 11 months ago

Hi Lluis,

Thank you very much for the super fast reply. Here is the code and the dataset. Thanks!

Anna

Il giorno mar 5 dic 2023 alle ore 12:15 Lluís Revilla < @.***> ha scritto:

Hi Anna, happy to hear from a happy user.

Sorry to hear that spatial doesn't fully work. I think I tested to prevent this from happening, but I will give it a look. Could you provide the code where this happens? This way I will make sure it won't happen again.

— Reply to this email directly, view it on GitHub https://github.com/llrs/experDesign/issues/45#issuecomment-1840542974, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYJGFB5GHRC32OUCVBNILB3YH363RAVCNFSM6AAAAABAHO4A5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBQGU2DEOJXGQ . You are receiving this because you authored the thread.Message ID: @.***>

llrs commented 11 months ago

Sorry, if you send the data via email, I don't see it in the github issue. But don't worry that I found a way to reproduce the issue:

data(survey, package = "MASS")
set.seed(4568)
nas <- c(137, 70)
index <- replicates(survey[-nas, c("Sex", "Smoke", "Age")], size_subset = 50,
                   iterations = 25, controls = 15)
index2 <- spatial(index, survey[-nas, c("Sex", "Smoke", "Age")], iterations = 25)
uniquness <- vapply(index2, function(x){length(unique(x)) == length(x)},
                    FUN.VALUE = logical(1L))
expect_false(any(!uniquness))

i1 <- inspect(index, survey[-nas, c("Sex", "Smoke", "Age")])
i2 <- inspect(index2, i1, index_name = "spatial")
# This should be empty too
i2 |> group_by(batch) |> count(spatial) |> ungroup() |> arrange(batch) |> filter(n!= 1)
AnnaPagotto commented 11 months ago

Oh, sorry, I didn't realise it. Let me know if I can provide with anything else. I can still send you the code if you wish.

llrs commented 11 months ago

Hi Anna, I fixed this locally, thanks for opening the issue. However, I found that there is a problem with batch_names which affects inspect too when there are controls or repeated positions. Do you have controls in your data? Or would this be enough for the moment?

AnnaPagotto commented 11 months ago

Hi Lluis,

I'm assigning the position to my controls separately, hence this should be enough for now.

Thank you a lot for your work!

On Thu, Dec 7, 2023, 11:24 Lluís Revilla @.***> wrote:

Hi Anna, I fixed this locally, thanks for opening the issue. However, I found that there is a problem with batch_names which affects inspect too when there are controls or repeated positions. Do you have controls in your data? Or would this be enough for the moment?

— Reply to this email directly, view it on GitHub https://github.com/llrs/experDesign/issues/45#issuecomment-1845075939, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYJGFB6ZUHO7FPZHSAMHWQLYIGKMZAVCNFSM6AAAAABAHO4A5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBVGA3TKOJTHE . You are receiving this because you authored the thread.Message ID: @.***>

AnnaPagotto commented 11 months ago

Hi Lluis, I removed and reinstalled the package. I thought that was sufficient to have the fixed version, but the bug is still there. What do you mean by "fixed locally"? Sorry for my ignorance. Anna

llrs commented 11 months ago

I meant that it was only in my computer, not yet on github or CRAN.

To install the package with the fix you will need to use remotes::install_github("llrs/experDesign") and it will install the development version with the fix. You don't need to uninstall it and reinstall it again, but you will need to close R and start again R after the installation to be sure that the new version is used.

If it is not fixed then I would need to know the code used and the experDesign version used.

AnnaPagotto commented 11 months ago

Thanks, the positions are now uniquely assigned. I just noticed now something that was not there before the fixing: I have two numeric and two categorical variables. For one categorical variable (in my case "age") it doesn't distribute the samples randomly in the plate.

Here the example:

image
llrs commented 11 months ago

Nice plot! I assume you blocked/omitted the first column? Or you only provided with columns 2 to 8?

I think I reverted that change, it slipped through. You will need to repeat the steps in https://github.com/llrs/experDesign/issues/45#issuecomment-1847506001. I am not sure how you have age as categorical, in the plots it is displayed as numeric. Did you use cut to categorize it or it is a simple typo?

AnnaPagotto commented 11 months ago

Sorry, it was a typo, I have age as numeric indeed. PS: yes I blocked the first and the last two columns. And I used ggplate for the plot :)

AnnaPagotto commented 11 months ago

It is perfectly working now! Thank you a lot!

llrs commented 11 months ago

Glad it works now! I hope it helps well designing your experiment! Thanks for the tip about ggplate! I might use it in the future.