FAQ/singcase/multiW - CBU statistics Wiki
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 as linsum. For three conditions this equals c3 - c1.

The linear contrasts for more general numbers of repeated levels are available in the appendix polynomial of Howell DC (2002) Statistical Methods for Psychology Fifth Edition. Wadsworth:Pacific Grove, CA.

The SPSS program outputs the t values, df and 2-sided p-values of the test of the equality of the average linear change in the controls to that in the patient using the one and two-sample approaches described below. These are contained in the spreadsheet.

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

get file='C:\aggemp.sav' . 

if(sub eq 1) cbeta=avglin. 
if(sub eq 2) pbeta=avglin. 
if(sub eq 1) sdbeta=sdlin. 

compute const=1. 
exe. 

aggregate outfile=* 
/break=const 
/cb = first(cbeta) 
/pb= first(pbeta) 
/nb=first(nlin) 
/sdb=first(sdbeta). 

compute tout=(cb-pb)/(sdb/sqrt(nb)). 
compute df=nb-1. 
compute pv=2*(1-cdf.t(abs(tout),nb-1)).

compute toutc=(cb-pb)/(sdb/sqrt((nb+1)/nb)).
 compute pvc=2*(1-cdf.t(abs(toutc),nb-1)). 
exe. 

This can more elegantly be performed in R. R can generate the linear contrasts automatically so generalises more easily to more than three repeated measures. The output consists of two t-values, their df and 2-sided p-values testing the equality of average linear change between the controls and single case. The first is the one sample t and the second is a two sample t. ( Further details.)

One sample t

$$\frac{\mbox{control change - patient change}}{\mbox{s.d. of change amongst controls} \sqrt(1/n)}$$

Two sample t

$$\frac{\mbox{control change - patient change}}{\mbox{s.d. of change amongst controls} \sqrt(1 + 1/n)}$$

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 <- 2*pt(-abs(tout),nsub-1)
#print out t, df of t and its 2-sided p-value
print(tout)
print(df)
print(pval)
#Crawford approach
tout2 <- (trendc[2]-trendp)/sqrt(sec*sec*(nsub+1))
pval2 <- 2*pt(-abs(tout2),nsub-1)
print(tout2)
print(df)
print(pval2)

None: FAQ/singcase/multiW (last edited 2013-03-08 10:17:31 by localhost)