mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 00:43:00 +02:00
small as.mo fix
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
---
|
||||
title: "How to import data from SPSS / SAS / Stata"
|
||||
author: "Matthijs S. Berends"
|
||||
date: "14 February 2019"
|
||||
date: '`r format(Sys.Date(), "%d %B %Y")`'
|
||||
output:
|
||||
rmarkdown::html_vignette:
|
||||
toc: true
|
||||
@ -20,6 +20,7 @@ knitr::opts_chunk$set(
|
||||
)
|
||||
# set to original language (English)
|
||||
Sys.setlocale(locale = "C")
|
||||
library(AMR)
|
||||
```
|
||||
|
||||
## SPSS / SAS / Stata
|
||||
@ -34,7 +35,7 @@ As said, SPSS is easier to learn than R. But SPSS, SAS and Stata come with major
|
||||
|
||||
The [official R network (CRAN)](https://cran.r-project.org/web/packages/) features almost 14,000 packages at the time of writing, our `AMR` package being one of them. All these packages were peer-reviewed before publication. Aside from this official channel, there are also developers who choose not to submit to CRAN, but rather keep it on their own public repository, like GitLab or GitHub. So there may even be a lot more than 14,000 packages out there.
|
||||
|
||||
Bottomline is, you can really extend it yourself or ask somebody to do this for you. Take for example our `AMR` package. SPSS, SAS and Stata will never know what a valid MIC value is (so data might not be clean) or what the Gram stain of *E. coli* is. Or the fact that all species of *Klebiella* are resistant to amoxicillin.
|
||||
Bottom line is, you can really extend it yourself or ask somebody to do this for you. Take for example our `AMR` package. Among other things, it adds reliable reference data to R to help you with the data cleaning and analysis. SPSS, SAS and Stata will never know what a valid MIC value is or what the Gram stain of *E. coli* is. Or that all species of *Klebiella* are resistant to amoxicillin and that Floxapen^®^ is a trade name of flucloxacillin. These facts and properties are often needed to clean existing data, which would be very inconvenient in a software package without reliable reference data. See below for a demonstration.
|
||||
|
||||
* **R is extremely flexible.**
|
||||
|
||||
@ -65,20 +66,43 @@ As said, SPSS is easier to learn than R. But SPSS, SAS and Stata come with major
|
||||
|
||||
If you sometimes write syntaxes in SPSS to run a complete analysis or to 'automate' some of your work, you should perhaps do this in R. You will notice that writing syntaxes in R is a lot more nifty and clever than in SPSS.
|
||||
|
||||
To demonstrate the first point:
|
||||
|
||||
```{r, warning = FALSE, message = FALSE}
|
||||
# not all values are valid MIC values:
|
||||
as.mic(0.125)
|
||||
as.mic("testvalue")
|
||||
|
||||
# the Gram stain is avaiable for all bacteria:
|
||||
mo_gramstain("E. coli")
|
||||
|
||||
# Klebsiella is intrinsic resistant to amoxicllin, according to EUCAST:
|
||||
klebsiella_test <- data.frame(mo = "klebsiella",
|
||||
amox = "S",
|
||||
stringsAsFactors = FALSE)
|
||||
klebsiella_test
|
||||
eucast_rules(klebsiella_test, info = FALSE)
|
||||
|
||||
# hundreds of trade names can be translated to an ATC or name:
|
||||
atc_name("floxapen")
|
||||
as.atc("floxapen")
|
||||
atc_tradenames("floxapen")
|
||||
```
|
||||
|
||||
## Import data from SPSS/SAS/Stata
|
||||
|
||||
### RStudio
|
||||
To work with R, probably the best option is to use [RStudio](https://www.rstudio.com/products/rstudio/). It is an open-source and free desktop environment which not only allows you to run R code, but also supports project management, version management, package management and convenient import menu to work with other data sources. You can also run [RStudio Server](https://www.rstudio.com/products/rstudio/), which is nothing less than the complete RStudio software available as a website (e.g. in your corporate network or at home).
|
||||
To work with R, probably the best option is to use [RStudio](https://www.rstudio.com/products/rstudio/). It is an open-source and free desktop environment which not only allows you to run R code, but also supports project management, version management, package management and convenient import menus to work with other data sources. You can also run [RStudio Server](https://www.rstudio.com/products/rstudio/), which is nothing less than the complete RStudio software available as a website (e.g. in your corporate network or at home).
|
||||
|
||||
To import a data file, just click *Import Dataset* in the Environment tab:
|
||||
|
||||

|
||||

|
||||
|
||||
If additional packages are needed, RStudio will ask you if they should be installed on beforehand.
|
||||
|
||||
In the the window that opens, you can define all options (parameters) that should be used for import and you're ready to go:
|
||||
|
||||

|
||||

|
||||
|
||||
If you want named variables to be imported as factors so it resembles SPSS more, use `as_factor()`.
|
||||
|
||||
|
@ -23,7 +23,7 @@ knitr::opts_chunk$set(
|
||||
)
|
||||
```
|
||||
|
||||
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using AI (Artificial Intelligence) combined with the taxonomic tree of Catalogue of Life.
|
||||
One of the most important features of this package is the complete microbial taxonomic database, supplied by the [Catalogue of Life](http://catalogueoflife.org). We created a function `as.mo()` that transforms any user input value to a valid microbial ID by using intelligent rules combined with the taxonomic tree of Catalogue of Life.
|
||||
|
||||
Using the `microbenchmark` package, we can review the calculation performance of this function. Its function `microbenchmark()` runs different input expressions independently of each other and measures their time-to-result.
|
||||
|
||||
@ -38,7 +38,7 @@ library(AMR)
|
||||
|
||||
In the next test, we try to 'coerce' different input values for *Staphylococcus aureus*. The actual result is the same every time: it returns its MO code `B_STPHY_AUR` (*B* stands for *Bacteria*, the taxonomic kingdom).
|
||||
|
||||
But the calculation time differs a lot. Here, the AI effect can be reviewed best:
|
||||
But the calculation time differs a lot:
|
||||
|
||||
```{r}
|
||||
S.aureus <- microbenchmark(as.mo("sau"),
|
||||
|
Reference in New Issue
Block a user