Skip to content

Instantly share code, notes, and snippets.

View gjkerns's full-sized avatar

G. Jay Kerns gjkerns

View GitHub Profile
@gjkerns
gjkerns / wer_all.R
Last active June 25, 2023 01:28 — forked from glamp/wer_all.R
library(plyr)
library(qcc)
data("pistonrings")
attach(pistonrings)
x <- qcc.groups(diameter, sample)
detach(pistonrings)
find_zones <- function(x) {
@gjkerns
gjkerns / misleadingGraph.R
Created October 8, 2015 17:03
Misleading Graph
# source: http://www.aul.org/2015/06/aul-releases-the-new-leviathan-the-mega-centers-report-how-planned-parenthood-has-become-abortion-inc/
plot(x = c(74, 74, 774, 774),
y = c(-541, -213, -305, -572),
main = "PLANNED PARENTHOOD FEDERATION OF AMERICA:",
xlab = "", ylab = "", asp = 1, axes = FALSE,
xlim = c(74, 774), ylim = c(-679, -150),
type = "n")
mtext("ABORTIONS UP - LIFE SAVING PROCEDURES DOWN", side = 3)
arrows(x0 = 74, y0 = -541, x1 = 774, y1 = -305,
lwd = 3, col = "red")
@gjkerns
gjkerns / WeakLawLargeNumbers.R
Created February 15, 2014 23:39
Weak Law of Large Numbers
####################################################################
# WLLN
samp.size <- 5
mu <- 10
sigma <- 3
histN <- 1000
@gjkerns
gjkerns / StrongLawLargeNumbers.R
Created February 15, 2014 23:38
Strong Law of Large Numbers
SLLN <- function( iter = 10,
p = 0.5){
require(TeachingDemos)
x <- rbinom( iter, size=1, prob = p)
plot( cumsum(x)/1:length(x),
type="l",
#lwd = 2,
ylab = "Relative Frequency",
xlab = "Cumulative Trials",
@gjkerns
gjkerns / LawIteratedLogarithm.R
Last active August 29, 2015 13:56
Law of the Iterated Logarithm
limsup <- function(x){
z = rep(0,length(x))
for(i in 1:length(x)){
z[i] = max(x[i:length(x)])
}
return(z)
}
set.seed(2)
# Condorcet
Votes <- read.csv("Votes.csv")
candidates <- names(Votes)
nvoters <- dim(Votes)[1]
ncand <- dim(Votes)[2]
allpairs <- combn(1:ncand, 2)
@gjkerns
gjkerns / equationoftime.R
Created February 15, 2012 18:17
Make a sundial
# The Equation of Time
# based on trigonometric approximation on Wikipedia
equoftime <- function(M){
-7.657*sin(M) + 9.862*sin(2*M + 3.599)
}
x <- equoftime((1:365)*2*pi/365.242)
y <- ts(x, start = 4, frequency = 365)
# set up the plot
@gjkerns
gjkerns / powerSampleSize.R
Created January 13, 2012 19:30
Simulation for determining sample size in Repeated Measures ANOVA
# Simulation study for sample size between/within
# got Treat + Sham between subjects
# got Time within subjects
nPerGroup <- 30
nTime <- 4
muTreat <- c(37, 32, 20, 15)
muSham <- c(37, 32, 25, 22)
stdevs <- c(12, 10, 8, 6)
stdiff <- 9
@gjkerns
gjkerns / flowchart.R
Created January 1, 2012 21:27
Flowchart for reporting R bugs
library(diagram)
openplotmat(main="Flowchart for R Bug Reporting")
curvedarrow(from = c(0.5,0.85), to = c(0.8,0.725), curve = -0.2, arr.pos = 0.6)
curvedarrow(from = c(0.8,0.725), to = c(0.85,0.5), curve = -0.2, arr.pos = 0.5)
curvedarrow(from = c(0.85,0.5), to = c(0.8,0.26), curve = -0.2, arr.pos = 0.5)
curvedarrow(from = c(0.8,0.26), to = c(0.5,0.15), curve = -0.2, arr.pos = 0.53)
curvedarrow(from = c(0.5,0.15), to = c(0.2,0.3), curve = -0.2, arr.pos = 0.4)
curvedarrow(from = c(0.2,0.3), to = c(0.15,0.5), curve = -0.2, arr.pos = 0.5)