Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Friendly friendly

View GitHub Profile
@friendly
friendly / migrate-svn-git.md
Last active Sep 18, 2017
Migration path for R packages from svn/R-Forge to git/github
View migrate-svn-git.md

Migrating SVN/R-Forge packages to git/github

Migration \Mi*gra"tion, n. [L. migratio: cf. F. migration]

1: The movement of persons or groups from one country or locality to another.

2: The passage of software developers from one platform, language or environment to another for the purpose of feeding, breeding or enhanced health of their offspring.

Context

@friendly
friendly / odds.R
Created Aug 10, 2015
calculate log odds
View odds.R
odds <- function(x, log=FALSE, ...)
lodds(x, log=log, ...)
lodds <- function(x, ...)
UseMethod("lodds")
lodds.formula <-
function(formula, data = NULL, ..., subset = NULL, na.action = NULL)
{
@friendly
friendly / boxM.R
Created Feb 10, 2016
Box's M-test for Homogeneity of Covariance Matrices
View boxM.R
# Box's M-test for Homogeneity of Covariance Matrices
boxM <-
function(mod, ...) UseMethod("boxM")
boxM.default <- function(Y, group)
{
dname <- deparse(substitute(Y))
if (!inherits(Y, c("data.frame", "matrix")))
@friendly
friendly / 3d-demo.R
Created Sep 30, 2016
3D demonstrations of linear transformations and matrix inverse
View 3d-demo.R
#' ---
#' title: "3D demonstrations of linear transformations and matrix inverse"
#' author: "Michael Friendly"
#' date: "30 Sep 2016"
#' ---
#' Start with a unit cube, representing the identity matrix. Show its transformation
#' by a matrix $A$ as the corresponding transformation of the cube.
#'
#' This also illustrates the determinant, det(A), as the volume of the transformed
@friendly
friendly / wavelength_to_rgb.R
Created Oct 24, 2016
Convert wavelength of color to RGB
View wavelength_to_rgb.R
#' Wavelength to RGB
#'
#' This function converts a given wavelength of light to an
#' approximate RGB color value.
#'
#' @param wavelength A wavelength value, in nanometers, in the human visual range from 380 nm through 750 nm.
#' These correspond to frequencies in the range from 789 THz through 400 THz.
#' @param gamma The \eqn{\gamma} correction for a given display device. The linear RGB values will require
#' gamma correction if the display device has nonlinear response.
#' @return a color string, corresponding to the result of \code{\link[grDevices]{rgb}} on the
View plot_r.R
# Taken from: http://janhove.github.io/teaching/2016/11/21/what-correlations-look-like
# source: http://janhove.github.io/RCode/plot_r.R
#
# plot_r
#
# Given a correlation coefficient and a sample size,
# this function draws 16 scatterplots
# whose shapes differ greatly
# but all of which are consistent with the correlation coefficient.
#
@friendly
friendly / minard-plot.R
Last active Aug 10, 2017
Reproduce Minard's March on Moscow Graphic using ggplot2
View minard-plot.R
#' # Reproduce Minard's March on Moscow Graphic using ggplot2
#' This gist extends the examples given in the HistData package. It explicitly
#' shows the construction of the plot as layers, and adds the plot of temperature
#' vs. longitude below the plot of troop strength.
#' ## Load data and required packages
data(Minard.troops, package="HistData")
data(Minard.cities, package="HistData")
data(Minard.temp, package="HistData")
@friendly
friendly / PartySupport-2019.R
Created Nov 1, 2019
Plots of Canadian 2019 election results
View PartySupport-2019.R
# Stacked Barplot of Support for Political Parites by Province in 2019 Canadian Federal Election
# written by Christopher D. Green
# 22 October 2019
# additions by MF 31 Oct 2019
provs<-c("BC","AB","SK","MB","ON","QC","NB","NS","PE","NF") # names of the provinces
pops<-c(5.0,4.3,1.2,1.4,14.4,8.4,0.8,1.0,0.2,0.5) # populations in millions
con<-c(34.1,69.2,64.3,45.4,33.2,16.0,32.8,25.7,27.4,28.0) # % support for Conservatives
lib<-c(26.1,13.7,11.6,26.3,41.5,34.2,37.6,41.3,43.6,44.7) # % support for Liberals
@friendly
friendly / phys-models.bib
Created Nov 28, 2020
Bibliography for physical analogs of statistical models
View phys-models.bib
@comment{Physical analogs for statistical models}
@article{GainesPalphrey:1932,
ISSN = {00368075, 10959203},
URL = {http://www.jstor.org/stable/1658643},
author = {W. L. Gaines and J. R. Palfrey},
journal = {Science},
number = {1977},
pages = {472--474},
publisher = {American Association for the Advancement of Science},