This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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")) |