||
SSpower <- function(modelpop,modelana,n,alpha=.05,anadf=1){
require(lavaan)
dat <- simulateData(modelpop,sample.nobs=1000)
fit <- sem(modelpop,data=dat,meanstructure=T)
sigmahat <- fit@Fit@Sigma.hat[[1]]
muhat <- fit@Fit@Mu.hat[[1]]
colnames(sigmahat) <- fit@Data@ov.names[[1]]
rownames(sigmahat) <- fit@Data@ov.names[[1]]
rownames(muhat) <- fit@Data@ov.names[[1]]
fit1 <- sem(modelana,sample.nobs=1000,sample.cov=sigmahat,
sample.mean=muhat, meanstructure=T)
nowf <- fit1@Fit@fx*2
nowdf <- anadf
nowpower <- (1-pchisq(qchisq(1-alpha,nowdf),nowdf,ncp=(n-1)*nowf))
SSpower <- nowpower
return(SSpower)
}
model1pop <-'
F1=~.646*x1
F1=~.654*x2
F1=~.759*x3
F1=~.757*x4
F2=~.708*x5
F2=~.764*x6
F2=~.897*x7
F3=~.572*x8
F3=~.639*x9
F3=~.751*x10
F4=~.641*x11
F4=~.590*x12
F4=~.594*x13
F5=~.765*x14
F5=~.797*x15
F5=~.616*x16
F5=~.581*x17
F6=~.831*x18
F6=~.712*x19
F6=~.683*x20
F7=~.698*x21
F7=~.673*x22
F7=~.680*x23
F8=~.787*x24
F8=~.578*x25
F8=~.726*x26
x1~~.583*x1
x2~~.572*x2
x3~~.424*x3
x4~~.427*x4
x5~~.499*x5
x6~~.416*x6
x7~~.195*x7
x8~~.673*x8
x9~~.592*x9
x10~~.436*x10
x11~~.589*x11
x12~~.652*x12
x13~~.647*x13
x14~~.415*x14
x15~~.365*x15
x16~~.621*x16
x17~~.662*x17
x18~~.309*x18
x19~~.493*x19
x20~~.534*x20
x21~~.513*x21
x22~~.547*x22
x23~~.538*x23
x24~~.381*x24
x25~~.666*x25
x26~~.473*x26
F8~.74*F7
F7~.30*F1 +.12*F2 +.27*F3 +.45*F4 +.11*F5 +.19*F6
F1~~1*F1
F2~~1*F2
F3~~1*F3
F4~~1*F4
F5~~1*F5
F6~~1*F6
F7~~.568*F7
F8~~.453*F8
'
model1ana <-'
F1=~.646*x1
F1=~.654*x2
F1=~.759*x3
F1=~.757*x4
F2=~.708*x5
F2=~.764*x6
F2=~.897*x7
F3=~.572*x8
F3=~.639*x9
F3=~.751*x10
F4=~.641*x11
F4=~.590*x12
F4=~.594*x13
F5=~.765*x14
F5=~.797*x15
F5=~.616*x16
F5=~.581*x17
F6=~.831*x18
F6=~.712*x19
F6=~.683*x20
F7=~.698*x21
F7=~.673*x22
F7=~.680*x23
F8=~.787*x24
F8=~.578*x25
F8=~.726*x26
x1~~.583*x1
x2~~.572*x2
x3~~.424*x3
x4~~.427*x4
x5~~.499*x5
x6~~.416*x6
x7~~.195*x7
x8~~.673*x8
x9~~.592*x9
x10~~.436*x10
x11~~.589*x11
x12~~.652*x12
x13~~.647*x13
x14~~.415*x14
x15~~.365*x15
x16~~.621*x16
x17~~.662*x17
x18~~.309*x18
x19~~.493*x19
x20~~.534*x20
x21~~.513*x21
x22~~.547*x22
x23~~.538*x23
x24~~.381*x24
x25~~.666*x25
x26~~.473*x26
F8~F7
F7~0*F1 + F2 + F3 + F4 + F5 + F6
'
J= SSpower(model1pop,model1ana,n=376,alpha=.05,anadf=1)
print(J)
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-1 11:31
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社