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 missing letters from: He's no ded, he's jus resing hs eys

Revision 1 as of 2009-01-19 12:20:52

location: FAQ / powspsinR

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

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.