FAQ/singcase/multiW - CBU statistics Wiki

Revision 8 as of 2007-03-09 10:07:31

Clear message
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 value, df and 2-sided p-value of the test of the equality of the average linear change in the controls to that in the patient. 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) 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. R can generate the linear contrasts automatically. R also generalises to more than three repeated meeasures. 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. (see http://www.abdn.ac.uk/~psy086/dept/SingleCaseMethodology.htm)

'One sample t'

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

'Two sample t'

$$\frac{\mbox{control change - patient change}}{controls' slope s.d. \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 <- dt(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 <- dt(tout,nsub-1)
print(tout)
print(df)
print(pval)