Robert Schnitman

Statistical Consultant and Tutor

Mapping Techniques to Maintain Data Frame Consistency in Base R

Introduction Maintaining data frame consistency within Base R can be difficult. The library purrr1 from the tidyverse solves this problem with its map_df() function. However, we can achieve similar results and expand upon them with base R functions. To do so, two methods will be used. Method 1: Use lapply(), data.frame(), and do.call() To replicate purrr’s map_df(), we use three functions: lapply() to apply the function to some data; data.

Presenting the Sachse, TX January 2020 Special Election Pre-runoff Results with R

Preface The contents of this blog post originate from the PDF version (https://github.com/robertschnitman/RS_Reports/blob/master/Polls/Sachse/sachse2020.pdf) and its GitBook equivalent (https://rs-sachse2020.netlify.com/). EDIT 2020-03-27: This post has been updated to use flextable instead of kableExtra to produce a cleaner table for HTML. The PDF and Gitbook reports use the latter, as it is better for PDFs. Introduction The purpose of this document is to demonstrate the utility of using the R programming language in reporting polls by walking through the process via the software itself.

mop(): a New Way to sweep()

Introduction This blog post will compare sweep() and a function I’ve created called mop(). I argue that the latter is preferred over the former, as it is more concise in nature. The Old Way: sweep() The function sweep()1 allows one to process data based on a summary statistic function–for example, dividing each element by a column’s mean. A problem, however, arises: you are required to explicitly state the summary statistic value in the STATS input.

Scatter-text Plots with Base R

To make scatter plots with text as points in Base R, we simply need to use plot(), set the scatter points to be white, and then plot the text with text(). # Trick R into not displaying points. with(mtcars, plot(wt ~ mpg, pch = 1, col = 'white', xlab = 'MPG', ylab = 'Weight', main = 'Weight vs. MPG')) # Plot the labels on the graph. with(mtcars, text(mpg, wt, row.

Using Residuals Percent in OLS Diagnostics

Many students (myself included) were taught to analyze the raw residuals when diagnosing regression models, but not in terms of percent. The benefit of the latter is that we can assess the relative magnitude of error from our regression model. To display the residuals as a percent (henceforth Residuals, %), let’s first load some necessary libraries. libs <- c('tidyverse', 'magrittr', 'ggthemes', 'gridExtra') # For each library, check if they are installed.

Welcome!

Hello, my name is Robert Schnitman, and welcome to my site! This site describes myself and the services I provide as an independent contractor, as well as a blog to record data analysis and R programming ideas. Please check out the “About”, “Curriculum Vitae”, and “Services” pages for more information! Thank you for your time!