Skip to content

Instantly share code, notes, and snippets.

@friendly
friendly / odds.R
Created August 10, 2015 20:18
calculate log odds
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)
{
# 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 / migrate-svn-git.md
Last active September 18, 2017 21:00
Migration path for R packages from svn/R-Forge to git/github

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 / boxM.R
Created February 10, 2016 15:12
Box's M-test for Homogeneity of Covariance Matrices
# 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 / PartySupport-2019.R
Created November 1, 2019 19:43
Plots of Canadian 2019 election results
# 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 November 28, 2020 17:49
Bibliography for physical analogs of statistical models
@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},
@friendly
friendly / clark-lord-paradox.R
Created February 7, 2022 19:08
Demonstrate Lord's Paradox example, following Michael Clarke
# Demonstrate Lord's Paradox example, following Michael Clarke
# https://m-clark.github.io/docs/lord/index.html
library(ggplot2)
library(dplyr)
#' ## Data example: Initial and final weight for boys & girls
#'
#' Make a plot showing the distribution of gain scores perpendicular to the line of slope = 1
#'
@friendly
friendly / minard-plot.R
Last active April 7, 2022 11:30
Reproduce Minard's March on Moscow Graphic using ggplot2
#' # 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 / 3d-demo.R
Created September 30, 2016 14:58
3D demonstrations of linear transformations and matrix inverse
#' ---
#' 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 / test-newcommand.html
Created August 15, 2022 18:23
Quarto: Test LaTeX newcommands in HTML doc
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.0.37">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Quarto: Test LaTeX newcommands in HTML doc</title>