R Code

R Code

Breaking Predict for lm() with dollar.sign

As is often the case with \(R\), there are many ways to do things that are equivalent or nearly equivalent. It is the nearly equivalent part that is frustrating; one of the first encounters with this can come with attempts to predict a regression. The ultimate source of troubles is scoping and environments; the use of the $ syntax sometimes has unintended side effects. lm() Syntax is Important I will refer to an example from a recent homework on regression.

Financial Analysis of SEC Reports in R

The Package: finreport The key tool to facilitate the financial analysis of companies that file regular SEC reports of certain forms is finreportr. To make use of it, we must first have R install it and dependencies. To install it, install.packages("finreportr", dependencies=TRUE). The Commands The first command is CompanyInfo(). library(finreportr) CompanyInfo("JPM") ## company CIK SIC state state.inc FY.end street.address ## 1 JPMORGAN CHASE & CO 0000019617 6021 NY DE 1231 383 MADISON AVENUE ## city.

A Quick and Dirty Introduction to R

Some Data I will start with some inline data. library(tidyverse); library(skimr); Support.Times <- structure(list(Screened = c(26.9, 28.4, 23.9, 21.8, 22.4, 25.9, 26.5, 20, 23.7, 23.7, 22.6, 19.4, 27.3, 25.3, 27.7, 25.3, 28.4, 24.2, 20.4, 29.6, 27, 23.6, 18.3, 28.1, 20.5, 24.1, 27.2, 26.4, 24.5, 25.6, 17.9, 23.5, 25.3, 20.2, 26.3, 27.9), Not.Screened = c(24.7, 19.1, 21, 17.8, 22.8, 24.4, 17.9, 20.5, 20, 26.2, 14.5, 22.4, 21.1, 24.3, 22, 24.3, 23.

Working an Example on Proportions

A Proportions Example We started with an equation: \[ z = \frac{\hat{\pi} - \pi}{\sqrt{\frac{\pi(1-\pi)}{n}}} \] In language, the difference between the sample proportion (recall that with only two outcomes the sample proportion \(\hat{\pi}\) is between 0 [all No’s] and 1 [all Yes’s]) and the true probability \(\pi\) divided by the standard error of the proportion \(\sqrt{\frac{\pi(1-\pi)}{n}}\) has a \(z\) [Normal(0,1)] distribution under the condition that \(n\pi > 10\) and \(n(1-\pi) > 10\).

Alluvial Plots

Alluvial and Sankey Diagrams The aforementioned plots are methods for visualising the flow of data through a stream of markers. I was motivated to show this because enough of you deal in orders, tickets, and the like the flow visualisation of a system might prove of use. I will work with a familiar dataset. These are data on Admissions at the University of California Berkeley. The data exist as an internal R file in tabular form.

Local Maps for Oregon

A Citation I found a starting point on local maps in Seattle. library(ggmap) library(osmdata) library(tidyverse) # SLE <- get_map(getbb("Salem, OR"), source="osm") # SLE %>% ggmap() An Oregon Map of Liquor Stores The setup for a Google Cloud account is kind of a pain and it requires a billing option. That was annoying but eventually fixed. It is required for geocoding addresses as OSM doesn’t do that anymore.

Tables, Pivots, Bars, and Mosaics

R Markdown There is detailed help for all that Markdown can do under Help in the RStudio. The key to it is knitting documents with the Knit button in the RStudio. If we use helpers like the R Commander, Radiant, or esquisse, we will need the R code implanted in the Markdown document in particular ways. I will use Markdown for everything. I even use a close relation of Markdown in my scholarly pursuits.

NFL ScrapR

Scraping NFL data with nflscrapr The nflscrapR package is designed to make data on NFL games more easily available. To install the package, we need to grab it from github. devtools::install_github(repo = "maksimhorowitz/nflscrapR") The github page for nflscrapR is quite informative. It has a lot of useful insight for working with the data; the set itself is quite large. Getting Some Data Following the guide to the package on GitHub, let me try their example.