FAQ/singcase/multiW - CBU statistics Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
Type the odd letters out: ONlY twO thinGs aRE infiNite

Revision 2 as of 2007-02-20 17:20:12

location: FAQ / singcase / multiW

The programs below assume each person has three conditions, c1, c2 and c3 with the number of conditions entered as ncon and sub denoting control group (1) or case (2). They compare the average change over the three conditions to the change in the single case.

In SPSS you have to enter the contrast corresponding to a linear change over the three conditions. These are available in appendix polynomial of Howell DC (2002) Statistical Methods for Psychology Fifth Edition. Wadsworth:Pacific Grove, CA

compute linsum = -c1 + c3.
exe.
aggregate outfile='Y:\R_Work\aggemp.sav' 
  /break=sub
 /avglin = mean(linsum)
 /sdlin= sd(linsum)
 /nlin=n.

get file='Y:\R_Work\aggemp.sav' .
if(sub eq 1) cbeta=avglin.
if(sub eq 2) pbeta=avglin.
if(sub eq 1) secbeta=cbeta/sqrt(nlin).

compute const=1.
exe.
aggregate outfile=* 
 /break=const
 /cb = first(cbeta)
 /pb= first(pbeta)
 /nb=first(nlin)
 /seb=first(secbeta).

compute tout=(cb-pb)/seb.
compute df=nb-1.
compute pv2=2*(1-cdf.t(abs(tout),nb-1)).
exe.

This can more elegantly be performed in R.

c1 <- c(2,1,4,5,2,3,4,1,2,3,4)
c2 <- c(1,6,5,4,3,4,5,6,7,8,9)
c3 <- c(2,1,3,4,5,6,7,8,9,3,11)
sub <- c(1,1,1,1,1,1,1,1,1,1,2)
# input number of conditions
ncon <- 3

score <- c(c1,c2,c3)[sub == 1]
subj <- sub[sub == 1]
nsub <- length(subj)
ymat <- matrix(score, nrow=nsub, ncol=ncon)
ymat <- t(ymat)
id <- rep(1:length(subj), ncon)
cond <- gl(ncon,length(subj))
library(nlme)
longa <- groupedData(score ~ cond | id)
longa$cf <- factor(longa$cond, c(1:ncon))
longa$id <- factor(longa$id, c(1:length(subj)))
contrasts(longa$cf) <- contr.poly(ncon)
m <- contrasts(longa$cf)[,1]
yc <- m %*% ymat
yc <- cbind(yc[,1:length(subj)]) 
sec <- sd(c(yc[,1])) / sqrt(nsub)
# fit repeated measures model
model.cs <- gls(score ~ cf, data=longa, method=’ML’, corr=corCompSymm(form=~1  | id))
summary(model.cs)
trendc <- coefficients(model.cs)
#
#repeat for a single case
#
score <- c(c1,c2,c3)[sub == 2]
subj <- sub[sub == 2]
id <- rep(1:length(subj), ncon)
cond <- gl(ncon,length(subj))
longa <- groupedData(score ~ cond | id)
longa$cf <- factor(longa$cond, c(1,2,3))
contrasts(longa$cf) <- contr.poly(ncon)
m <- contrasts(longa$cf)[,1]
trendp <- m %*% score 
tout <- (trendc[2]-trendp)/sec
df <- nsub-1
pval <- dt(tout,nsub-1)
#print out t, df of t and its 2-sided p-value
print(tout)
print(df)
print(pval)