msberends / AMR

Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by using evidence-based methods, as described in https://doi.org/10.18637/jss.v104.i03.
https://msberends.github.io/AMR/
Other
83 stars 12 forks source link

uti argument in as.sir not working as expected #141

Closed samueljpearce closed 5 months ago

samueljpearce commented 5 months ago

This is for veterinary data using CLSI 2023 guidelines. I have a dataframe with a list of MICs for a variety of antimicrobials and a column labelled "specimen" which has the body site, including some "urine" samples.

I am having several issues with the uti argument as follows:

samueljpearce commented 5 months ago

I think my issue was using as.sir within mutate_if. However, using it outside of a mutate function results in a different problem where as.sir tries to interpret non-mic columns. For example, running as.sir(guideline = "CLSI", breakpoint_type = "animal", host = "host", uti = "urine"), on a dataframe consisting of "mo", "host", "urine" and a series of antimicrobial MIC columns gives this error: Warning: in as.sir(): 171 results in column 'mo' truncated (100%) that were invalid antimicrobial interpretations: "Dog" OK.

msberends commented 5 months ago

Definitely something to improve! I was just working on it the other week. Which version of the package did you use?

samueljpearce commented 5 months ago

I updated to v2.1.1 today so it should be latest release!

msberends commented 5 months ago

It is, but you might be interested in our latest beta version that is all about veterinary medicine :)

Please read this: https://msberends.github.io/AMR/news/index.html

You can now set animal species! Supports 20 languages.

I’m curious if this solves your problem with uti as well.

You can try the latest version using:

install.packages("AMR", repos = "https://msberends.r-universe.dev/")

Would be awesome if you could let me know if this revamped approach works for you!

samueljpearce commented 5 months ago

Oh I missed that v2.1.1.9015 wasn't on CRAN yet. Thanks for letting me know - I will try it out!

samueljpearce commented 5 months ago

I’m curious if this solves your problem with uti as well.

Yes and no. As I thought, the mutate_if(x, is.mic, as.sir) method doesn't seem to work (the same happens with the new "host" column). I'm no expert with R but I would think this is because it is mutating at the specified point (i.e. columns that match is.mic) and therefore the function does not have the scope to access the specimen and host columns. Does it work for you?

When using as.sir(data, ...) it does still seem to try and interpret other columns, but at least it doesn't seem to affect the output as far as I can tell.

samueljpearce commented 5 months ago

The more I use this argument, the harder I find it is to get consistent behaviour from it but I think I may have found the problem. I've created a minimal example dataset attached.

minimal_reproducible_example.csv

With this minimal example, if you run as.sir(data, guideline = "CLSI", breakpoint_type = "animal", uti = "uti", host = "host") on the whole dataset, it incorrectly identifies many E. coli isolates as resistant to AMP. However, if you run only say, the first 30 samples, it correctly identifies them as sensitive or resistant.

It seems to be that the breakpoints do not get applied correctly to each host if there are multiple. For example, using this dataset, the above as.sir function will correctly identify dog urine isolates as S or R. Once you include isolate 33 which is a cat, they all seem to become resistant.

The canine and feline breakpoints should be the same for AMP and E. coli, so I did some digging into the clinical_breakpoints dataset and it does not actually have the feline uncomplicated UTI breakpoint for AMP, even though it is in the CLSI VET01 2023 guidelines.

Therefore, I think it is blanket applying the soft tissue breakpoint for cats, to both the cat and dog isolates, rendering them all resistant.

msberends commented 5 months ago

Wow, thanks so much for your time!

Consistent behaviour is the most important thing, so some bits must be changed in the functions, no doubt about that.

The canine and feline breakpoints should be the same for AMP and E. coli, so I did some digging into the clinical_breakpoints dataset and it does not actually have the feline uncomplicated UTI breakpoint for AMP, even though it is in the CLSI VET01 2023 guidelines.

This is also a very important thing, I need to check why this is the case. Are you not getting notes that dogs breakpoints are being used?

samueljpearce commented 5 months ago

It does, but it seems to default to the soft tissue breakpoints, rendering urine cultures resistant.

samueljpearce commented 5 months ago

Closing as part of wider issue in #142