FAQ/powspsinR - 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

location: FAQ / powspsinR

Running R code in SPSS for paired t (equal groups)

The R code below may be run in a syntax window in SPSS 16 after using the R integrator plug-in. You need to enter the inputs (Type I error, difference in means, sd and required power) in the BEGIN DATA sandwich. Sample size (in both groups) is outputted in the SPSS output window.

DATA LIST free
/alpha (f10.5) mdiff (f10.5) sd (f10.5) power (f10.5). 
BEGIN DATA. 
0.05 6.0 10.0 0.90
END DATA. 

begin program r.
casedata <- spssdata.GetDataFromSPSS()

beta <- casedata$alpha
mdiff <- casedata$mdiff
sd <- casedata$sd
pow <-casedata$power

fn <- function(n) {
(pow - (1 - pt(abs(qt(beta/2,(2*n)-2)),(2*n)-2,mdiff/sqrt(2*sd*sd/n))) )^2
 }

nout<- nlm(fn,2)
nout<- trunc(nout$estimate+1)
outp <- data.frame(A=c(nout,beta,mdiff,sd,pow),row.names=c("N","alpha","Mean Diff","sd","Power"))

spsspivottable.Display(outp,
                       title="Sample Size needed",                   rowdim=" ",                                                     format=formatSpec.Correlation)
end program.