Press "Enter" to skip to content

Category: R

From SAS to R

Gigi Kenneth continues a series:

If you’re moving regulated analysis from SAS to R, two things are worth knowing up front. R is a choice you can defend: regulators don’t tell you which software to use, and R has already been through FDA review in public pilot submissions. And the language itself is the cheap part. Most of the cost and risk comes from six other places, and most of those are about planning, not programming.

Part one asked whether SAS is still worth keeping. This post covers why R, and where to put your budget and attention once you commit.

Click through for several notes that may trip up a migration, particularly in a clinical environment.

Leave a Comment

Writing MICE from Scratch in R

Ken Koon Wong rewrites a package:

We used mulitple imputation by chained equations (MICE) quite often in imputing missing data in many occasion, but I never really understood the mechanism behind it except that it appears magical! 🧙 I want to see if I can build this from scratch as a mean to understand the foundation of MICE so that at least it will give me the illusion of understanding. 🤣 Join me in my messy journey of trying to code it from the ground up (FYI, I’m not coding OLS or MLE from the ground up…), and let’s see if we can create some “magic” here! This is going to be a bumpy one with lots of coding, and maybe less of mathematical formulae. I’ll try my best to provide a TL;DR for each section so that we can get a high level view as well. Buckle up! And oh, Happy Halloween! 🎃 What a better time to look at magical recipes of statistics! Let’s go!

I really like this post. The end result isn’t exactly what the mice implementation gives, but it’s close enough to show real understanding of the algorithm. H/T R-Bloggers.

Leave a Comment

Space-Filling Curves to Display Battles over Time

Richard Vale plots historical battles:

I recently learned about an interesting way of reducing the dimension of a data set. I’d like to illustrate it with a data set of about 550 historical battles in the UK, extracted from Wikidata using a SPARQL query. No doubt some readers will have seen this idea before, but it’s new to me and I found it pretty.

The following plot shows the raw data, with a crossed swords symbol for the location of each battle. It’s possible to see some patterns on the plot (for example, it probably wasn’t much fun to live on the borders of mediaeval Wales) but it could be clearer.

Click through to learn about Hilbert curves and how we can use them to map 2D information to a 1D space. I’d love to see the repro code for this, but Richard does explain the technique. H/T R-Bloggers.

Leave a Comment

Package and Environment Managers in R

Isabella Velasquez surveys the field:

I don’t want to/can’t pass judgement on which is the best or which I recommend, because I honestly haven’t had the opportunity to explore all of them fully (a very diplomatic way of saying that I haven’t yet used all of them in a real-world context), but I would love to hear everybody else’s opinions on which they think is the best tool because I imagine people have them! 😀

Even so, this is a nice primer on what’s available and how you might want to use them. H/T R-Bloggers.

Comments closed

Updates to the VSCode R Extension

Chris Brown notes some changes:

I was doing some analysis work with R today (don’t get to do that very often anymore) and R wasn’t playing with VS Code nicely.

Turns out there has recently been a major update to the VS Code R editor extension.

So if you are having issues, check out the Extensions page for setup instructions.

Click through for some of the major changes and for some thoughts on Positron versus base VSCode. H/T R-Bloggers.

Comments closed

An Introduction to Data Dict

Malte Grosser describes a new project:

A data dictionary can record what each row represents, how values were measured and how tables fit together. Data Dict provides a format for writing this down alongside rules the data should satisfy. Both live in one file, data-dict.yaml. Its command-line tool checks the rules against the data and turns the dictionary into readable documentation.

The open-source project was initiated by Hadley Wickham and is supported by Posit. The format is designed for teams working across R, Python and SQL.

The post combines a high-level description of the Data Dict project, as well as one of the examples in frog jumping. H/T R-Bloggers.

Comments closed

Understanding the Receiver Operating Characteristic Curve

Ken Koon Wong digs into ROC and the area under the curve (AUC):

We see ROC-AUC so often with classification models, we know the higher the better, but there is always that, well it depends scenario. I’ve always wanted to know what the pitfall is, how to avoid it, and how to do better. Let’s go from the basics on how to code ROC-AUC from scratch to decision curve analysis!

Click through to learn how to calculate ROC and dig into the topic a bit. H/T R-Bloggers.

Comments closed

Dodging in ggplot2

Zenguo Zhang teaches a lesson:

In ggplot2, when displaying grouped data along categorical axes (such as grouped bar charts, boxplots, or error bars), horizontal dodging is used to prevent elements from overlapping at each categorical position. ggplot2 provides two primary dodging position functions: position_dodge() and position_dodge2().

Click through or else Piccolo is going to yell again.

Comments closed

Charting Average Full Database Backup Durations with R

Thomas Williams has a script:

DBAs spend time dealing with SQL Server performance, capacity, monitoring, troubleshooting, provisioning, etcetera; I’ve previously mentioned that R is a powerful, open-source language with a great ecosystem of libraries for analysis and visualisation, so it’s no surprise that I think mixing SQL Server and R Markdown for reporting goes together like a Vegemite and cheese sandwich…lunch perfection!

Here’s a couple of real-world examples of how I’ve used R Markdown connected to SQL Server (for a recap of how to do this from a technical perspective, see my earlier blog post “Connecting to a SQL Server database from R Markdown”):

This is a neat approach to visualizing database backup times as a process control chart.

Comments closed

Dual Y Axes in R with ggplot()

Andrea Onofri builds a complex chart:

I have often found myself needing to plot a single graph with two y-axes having different scales. For example, this might be useful for representing temperature and rainfall data at a given location. Unfortunately, doing this with ggplot() is not straightforward.

As Andrea mentions, there are specific circumstances in which having a dual-axis chart is reasonable, and click through to learn how. ggplot2 tends to be rather opinionated regarding visual choice and design. I happen to like those opinions and think they are generally correct, but I can also recognize that there may be exceptions to the rules. For those instances, I think “Somewhat difficult but not impossible” is a solid answer, as it keeps people from doing things inappropriately with a couple of mouse clicks, like setting up those stupid 3D bar charts in Excel. H/T R-Bloggers.

Comments closed