Skip to content

Instantly share code, notes, and snippets.

View even4void's full-sized avatar

chl even4void

View GitHub Profile
cronbach.alpha <- function(data, na.action="omit", signif.level=.05) {
# computes Cronbach's Alpha
# * Input *
# data : a n*k matrix, where each column hold one item responses'
# vector
# na.action : if "omit", then handle missing value in cov/var
# calculation [default]
# signif.level : type I error
# * Output *
# a list with statistic and confidence interval
@even4void
even4void / sdt1a.asy
Created October 16, 2010 10:16
distribution of miss/hit according to SDT
import graph;
import patterns;
size(300,200,IgnoreAspect);
real xmin=-4,xmax=4;
real ymin=0,ymax=1;
real PI=3.141593;
real sd=.6;
int a=-1, b=1;
@even4void
even4void / sdt1b.asy
Created October 16, 2010 10:18
distribution of CR/FA according to SDT
import graph;
import patterns;
size(300,200,IgnoreAspect);
real xmin=-4,xmax=4;
real ymin=0,ymax=1;
real PI=3.141593;
real sd=.6;
int a=-1, b=1;
@even4void
even4void / neyman.asy
Created October 16, 2010 10:19
classical decision theory framework
import graph;
import patterns;
size(300,200,IgnoreAspect);
real xmin=-4,xmax=4;
real ymin=0,ymax=1;
real PI=3.141593;
real sd=.6;
real a=1, b=-.5;
@even4void
even4void / reliability.R
Created October 17, 2010 19:36
Some illustrations of reliability analysis.
# Some illustrations of reliability analysis.
# Time-stamp: <2010-10-17 21:35:51 chl>
x <- c(12,8,22,10,10,6,8,4,14,6,2,22,12,7,24,14,8,4,5,6,14,5,5,16)
GHQ <- data.frame(subject=gl(12,1,24), time=gl(2,12), score=x)
# ----------------------------------------------------
# Computing reliability (Rx) by hand from ANOVA tables
# ----------------------------------------------------
# one-way ANOVA (assuming no time trends)
summary(aov(score ~ subject, data=GHQ))
itan <- function(x, keys=NULL, digits=3, no.resp=4) {
# x is an n subjects by k items matrix
# keys is a vector with the correct keys (A, B, C, D)
stopifnot(ncol(x)>1)
if (is.null(keys)) keys <- rep("A", ncol(x))
require(ltm)
raw.resp <- matrix(nr=ncol(x), nc=no.resp)
colnames(raw.resp) <- LETTERS[1:no.resp]
for (i in 1:ncol(x)) {
tmp <- table(x[,i])
# Some examples of graphical displays for Likert items
#
# Time-stamp: <2010-10-24 20:04:59 chl>
data(Environment, package="ltm")
Environment[sample(1:nrow(Environment), 10),1] <- NA
na.count <- apply(Environment, 2, function(x) sum(is.na(x)))
tab <- apply(Environment, 2, table)/apply(apply(Environment, 2, table), 2, sum)*100
# Cleveland dot plot
dotchart(tab, xlim=c(0,100), xlab="Frequency (%)", sub=paste("N", nrow(Environment), sep="="), pch=19)
# Time-stamp: <2010-12-10 14:28:19 chl>
#
# A toy example to illustrate SS idea in the Linear Model.
#
do.it <- function(x, g) {
stopifnot(is.factor(g))
stripchart(x ~ g, method="jitter", pch=19, col="darkgrey",
vertical=TRUE, ylab="")
@even4void
even4void / 23_designAB.mp
Created December 10, 2010 13:51
Illustration of two factors interaction
prologues := 2;
input geometriesyr16;
figure(-u,-u,6.5u,6u);
pair A,B,C,D,E,F,G,H,I,J,K,L,M,N;
picture depart;
numeric i,j,r,v;
r:=.5;
@even4void
even4void / venn_sql.r
Created January 7, 2011 11:58
Toy illustration of SQL joins with Venn diagrams in R
# Time-stamp: <2011-01-07 12:41:47 chl>
#
# Some illustrations of SQL joins with R.
# Inspiration: Jeff Atwood, http://bit.ly/eMhJEp
#
tableA <- data.frame(id=1:4, name=c("Pirate","Monkey","Ninja","Spaghetti"))
tableB <- data.frame(id=1:4, name=c("Rutabaga","Pirate","Darth Vader","Ninja"))