View source: R/convenienceFunctions.R
semPower.powerLGCM | R Documentation |
Convenience function for performing power analysis on effects in a latent growth curve model (LGCM). This requires the lavaan package.
semPower.powerLGCM(
type,
comparison = "restricted",
nWaves = NULL,
means = NULL,
variances = NULL,
covariances = NULL,
quadratic = FALSE,
timeCodes = NULL,
ticExogSlopes = NULL,
ticEndogSlopes = NULL,
groupEqual = NULL,
nullEffect = NULL,
nullWhichGroups = NULL,
autocorResiduals = TRUE,
...
)
type |
type of power analysis, one of |
comparison |
comparison model, one of |
nWaves |
number of waves, must be >= 3 for linear and > 3 for quadratic trends. |
means |
vector providing the means of the intercept and the linear slope factor (and the quadratic slope factor, if |
variances |
vector providing the variances of the intercept and the linear slope factor (and the quadratic slope factor, if |
covariances |
either the variance-covariance matrix between the intercept and the slope (and the quadratic slope factor, if |
quadratic |
whether to include a quadratic slope factor in addition to a linear slope factor. Defaults to |
timeCodes |
vector of length |
ticExogSlopes |
vector defining the slopes for an exogenous time-invariant covariate in the prediction of the intercept and slope factors (and the quadratic slope factor, if |
ticEndogSlopes |
vector defining the slopes for the intercept and slope factors (and the quadratic slope factor, if |
groupEqual |
parameters that are restricted across groups in both the H0 and the H1 model, when |
nullEffect |
defines the hypothesis of interest. See details for valid arguments. |
nullWhichGroups |
for hypothesis involving cross-groups comparisons, vector indicating the groups for which equality constrains should be applied, e.g. |
autocorResiduals |
whether the residuals of the indicators of latent variables are autocorrelated over waves ( |
... |
mandatory further parameters related to the specific type of power analysis requested, see |
This function performs a power analysis to reject various hypotheses arising
in latent growth curve models (LGCM), where one variable X
is repeatedly
assessed at different time points (nWaves
), and a latent intercept and a
linear (and optionally a quadratic) latent slope factor is assumed.
Relevant hypotheses in arising in a LCGM are:
iMean = 0
, sMean = 0
, s2Mean = 0
: Tests the hypothesis that the mean of the intercept, linear slope, and quadratic slope factors, respectively, is zero.
iVar = 0
, sVar = 0
, s2Var = 0
: Tests the hypothesis that the variance of the intercept, linear slope, and quadratic slope factors, respectively, is zero.
isCov = 0
: Tests the hypothesis that covariance between the intercept and linear slope factor is zero.
is2Cov = 0
: Tests the hypothesis that covariance between the intercept and quadratic slope factor is zero.
ss2Cov = 0
: Tests the hypothesis that covariance between the linear and the quadratic slope factor is zero.
betaIT = 0
, betaST = 0
, betaS2T = 0
: Tests the hypothesis that the slope for an exogenous time-invariant covariate in the prediction of the intercept, the linear slope, and the quadratic slope factor, respectively, is zero (TIC -> I, S, S2
).
betaTI = 0
, betaTS = 0
, betaTS2 = 0
: Tests the hypothesis that the slope the intercept, the linear slope, and the quadratic slope factor, respectively, in the prediction of an endogenous time-invariant covariate is zero (I, S, S2 -> TIC
).
iMeanA = iMeanB
, sMeanA = sMeanB
, s2MeanA = s2MeanB
: Tests the hypothesis that the means of the intercept, linear slope, and quadratic slope factors, respectively, are equal across groups.
iVarA = iVarB
, sVarA = sVarB
, s2VarA = s2VarB
: Tests the hypothesis that the variances of the intercept, linear slope, and quadratic slope factors, respectively, are equal across groups.
isCovA = isCovA
: Tests the hypothesis that covariance between the intercept and linear slope factor is equal across groups.
is2CovA = is2CovA
: Tests the hypothesis that the covariance between the intercept and quadratic slope factor is equal across groups.
ss2CovA = ss2CovA
: Tests the hypothesis that the covariance between the linear and quadratic slope factor is equal across groups.
betaITA = betaITB
, betaSTA = betaSTB
, betaS2TA = betaS2TB
: Tests the hypothesis that the slopes for the time-invariant covariate in the prediction of the intercept, the linear slope, and the quadratic slope factor, respectively, are equal across groups (TIC -> I, S, S2
).
betaTIA = betaTIB
, betaTSA = betaTSB
, betaTS2A = betaTS2B
: Tests the hypothesis that the slope the intercept, the linear slope, and the quadratic slope factor, respectively, in the prediction of the time-invariant covariate are equal across groups (I, S, S2 -> TIC
).
For hypotheses regarding longitudinal invariance, see semPower.powerLI()
. For hypotheses regarding a simple autoregression, see semPower.powerAutoreg()
. For hypotheses in an ARMA model, see semPower.powerARMA()
.
Beyond the arguments explicitly contained in the function call, additional arguments are required specifying the factor model and the requested type of power analysis.
Additional arguments related to the definition of the factor model:
Lambda
: The factor loading matrix (with the number of columns equaling the number of factors).
loadings
: Can be used instead of Lambda
: Defines the primary loadings for each factor in a list structure, e. g. loadings = list(c(.5, .4, .6), c(.8, .6, .6, .4))
defines a two factor model with three indicators loading on the first factor by .5, , 4., and .6, and four indicators loading on the second factor by .8, .6, .6, and .4.
nIndicator
: Can be used instead of Lambda
: Used in conjunction with loadM
. Defines the number of indicators by factor, e. g., nIndicator = c(3, 4)
defines a two factor model with three and four indicators for the first and second factor, respectively. nIndicator
can also be a single number to define the same number of indicators for each factor.
loadM
: Can be used instead of Lambda
: Used in conjunction with nIndicator
. Defines the loading either for all indicators (if a single number is provided) or separately for each factor (if a vector is provided), e. g. loadM = c(.5, .6)
defines the loadings of the first factor to equal .5 and those of the second factor do equal .6.
So either Lambda
, or loadings
, or nIndicator
and loadM
need to be defined. Neither may contain entries referring to the intercept and slope factors.
If the model contains observed variables only, use Lambda = diag(x)
where x
is the number of variables.
The order of the factors is (X1, X2, ..., X_nWaves, ticExogenous, ticEndogenous). If ticExogenous is undefined, ticEndogenous takes its place.
Additional arguments related to the requested type of power analysis:
alpha
: The alpha error probability. Required for type = 'a-priori'
and type = 'post-hoc'
.
Either beta
or power
: The beta error probability and the statistical power (1 - beta), respectively. Only for type = 'a-priori'
.
N
: The sample size. Always required for type = 'post-hoc'
and type = 'compromise'
. For type = 'a-priori'
and multiple group analysis, N
is a list of group weights.
abratio
: The ratio of alpha to beta. Only for type = 'compromise'
.
If a simulated power analysis (simulatedPower = TRUE
) is requested, optional arguments can be provided as a list to simOptions
:
nReplications
: The targeted number of simulation runs. Defaults to 250, but larger numbers greatly improve accuracy at the expense of increased computation time.
minConvergenceRate
: The minimum convergence rate required, defaults to .5. The maximum actual simulation runs are increased by a factor of 1/minConvergenceRate.
type
: specifies whether the data should be generated from a population assuming multivariate normality ('normal'
; the default), or based on an approach generating non-normal data ('IG'
, 'mnonr'
, 'RC'
, or 'VM'
).
The approaches generating non-normal data require additional arguments detailed below.
missingVars
: vector specifying the variables containing missing data (defaults to NULL).
missingVarProp
: can be used instead of missingVars
: The proportion of variables containing missing data (defaults to zero).
missingProp
: The proportion of missingness for variables containing missing data (defaults to zero), either a single value or a vector giving the probabilities for each variable.
missingMechanism
: The missing data mechanism, one of MCAR
(the default), MAR
, or NMAR
.
nCores
: The number of cores to use for parallel processing. Defaults to 1 (= no parallel processing). This requires the doSNOW
package.
type = 'IG'
implements the independent generator approach (IG, Foldnes & Olsson, 2016) approach
specifying third and fourth moments of the marginals, and thus requires that skewness (skewness
) and excess kurtosis (kurtosis
) for each variable are provided as vectors. This requires the covsim
package.
type = 'mnonr'
implements the approach suggested by Qu, Liu, & Zhang (2020) and requires provision of Mardia's multivariate skewness (skewness
) and kurtosis (kurtosis
), where
skewness must be non-negative and kurtosis must be at least 1.641 skewness + p (p + 0.774), where p is the number of variables. This requires the mnonr
package.
type = 'RK'
implements the approach suggested by Ruscio & Kaczetow (2008) and requires provision of the population distributions
of each variable (distributions
). distributions
must be a list (if all variables shall be based on the same population distribution) or a list of lists.
Each component must specify the population distribution (e.g. rchisq
) and additional arguments (list(df = 2)
).
type = 'VM'
implements the third-order polynomial method (Vale & Maurelli, 1983)
specifying third and fourth moments of the marginals, and thus requires that skewness (skewness
) and excess kurtosis (kurtosis
) for each variable are provided as vectors. This requires the semTools
package.
a list. Use the summary
method to obtain formatted results. Beyond the results of the power analysis and a number of effect size measures, the list contains the following components:
Sigma |
the population covariance matrix. A list for multiple group models. |
mu |
the population mean vector or |
SigmaHat |
the H0 model implied covariance matrix. A list for multiple group models. |
muHat |
the H0 model implied mean vector or |
modelH0 |
|
modelH1 |
|
simRes |
detailed simulation results when a simulated power analysis ( |
semPower.genSigma()
semPower.aPriori()
semPower.postHoc()
semPower.compromise()
## Not run:
# Determine required N in a 3-wave LGCM model
# to detect that the mean of the slope factor differs from zero
# with a power of 80% on alpha = 5%, where
# X is measured by 3 indicators loading by .5 each (at each wave), and
# the mean of the intercept factor is .5 and
# the mean of the slope factor is .2 and
# the variance of the intercept factor is 1 and
# the variance of the slope factor is .5 and
# the intercept-slope covariance is .25 and
# autocorrelated residuals are assumed
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 3,
means = c(.5, .2), # i, s
variances = c(1, .5), # i, s
covariances = .25,
nullEffect = 'sMean = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# show summary
summary(powerLGCM)
# optionally use lavaan to verify the model was set-up as intended
lavaan::sem(powerLGCM$modelH1, sample.cov = powerLGCM$Sigma,
sample.mean = powerLGCM$mu,
sample.nobs = powerLGCM$requiredN,
sample.cov.rescale = FALSE)
lavaan::sem(powerLGCM$modelH0, sample.cov = powerLGCM$Sigma,
sample.mean = powerLGCM$mu,
sample.nobs = powerLGCM$requiredN,
sample.cov.rescale = FALSE)
# same as above, but determine power with N = 250 on alpha = .05
powerLGCM <- semPower.powerLGCM(
'post-hoc', alpha = .05, N = 250,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMean = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# same as above, but determine the critical chi-square with N = 250 so that alpha = beta
powerLGCM <- semPower.powerLGCM(
'compromise', abratio = 1, N = 250,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMean = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# same as above, but compare to the saturated model
# (rather than to the less restricted model)
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80, comparison = 'saturated',
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMean = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# same as above, but assume only observed variables
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80, comparison = 'saturated',
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMean = 0',
Lambda = diag(3),
autocorResiduals = TRUE
)
# same as above, but provide reduced loadings matrix to define that
# X is measured by 3 indicators each loading by .5, .6, .4 (at each wave)
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80, comparison = 'saturated',
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMean = 0',
loadings = list(
c(.5, .6, .4), # X1
c(.5, .6, .4), # X2
c(.5, .6, .4) # X3
),
autocorResiduals = TRUE
)
# same as above, but get required N to detect that
# the variance of the intercept factor differs from zero
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'iVar = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# same as above, but get required N to detect that
# the intercept-slope covariance differs from zero
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
nullEffect = 'iscov = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# include a quadratic slope factor
# and get required N to detect that
# its variance differs from zero.
# provide the variance-covariance matrix
# between intercept, slope, and quadratic slope factors
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 4,
quadratic = TRUE,
means = c(.5, .2, .1),
covariances = matrix(c(
# i s s2
c(1, .3, .2),
c(.3, .5, .01),
c(.2, .01, .1)
), ncol = 3, byrow = TRUE),
nullEffect = 's2var = 0',
nIndicator = rep(3, 4), loadM = .5,
autocorResiduals = TRUE
)
# Determine required N in a 3-wave LGCM model
# to detect that the slope of an time-invariant covariate (TIC)
# on the slope factor differs from zero.
# The TIC is measured by 4 indicators loading
# by .7, .7, .5, and .8. The slope of the TIC in the prediction of
# the intercept factor is .5, and in the prediction of the slope factor is .4.
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
ticExogSlopes = c(.5, .4), # i s
nullEffect = 'betaST = 0',
loadings = list(
c(.5, .6, .4), # X1
c(.5, .6, .4), # X2
c(.5, .6, .4), # X3
c(.7, .7, .5, .8) # TIC
),
autocorResiduals = TRUE
)
# Determine required N in a 3-wave LGCM model
# to detect that the slope of the slope factor in
# the prediction of a time-invariant covariate (TIC) differs from zero.
# The TIC is measured by 4 indicators loading
# by .7, .7, .5, and .8. The slopes of the intercept and the slope factors in
# the prediction of the TIC are .1 and .3, respectively.
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80,
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = .25,
ticEndogSlopes = c(.1, .3), # i s
nullEffect = 'betaTS = 0',
loadings = list(
c(.5, .6, .4), # X1
c(.5, .6, .4), # X2
c(.5, .6, .4), # X3
c(.7, .7, .5, .8) # TIC
),
autocorResiduals = TRUE
)
# Determine required N in a 3-wave LGCM model
# to detect that the mean of the slope factor in group 1
# differs from the mean of the slope factor in group 2
# with a power of 80% on alpha = 5%, where
# X is measured by 3 indicators loading by .5 each (at each wave and in each group), and
# the means of the intercept factor in group 1 and 2 are .5 and .25
# the means of the slope factor in group 1 and 2 are .25 and .4
# the variance of the intercept factor is 1 in both groups and
# the variance of the slope factor is .5in both groups and
# the intercept-slope covariance is .25 in both groups and
# autocorrelated residuals are assumed and
# the groups are equal-sized
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80, N = list(1, 1),
nWaves = 3,
means = list(
# i, s
c(.5, .2), # group 1
c(.25, .4)), # group 2
variances = c(1, .5),
covariances = .25,
nullEffect = 'sMeanA = sMeanB',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# similar as above, but get required N to detect that
# the intercept-slope covariance differs across groups,
# assuming that intercept and slope variances are equal across groups.
powerLGCM <- semPower.powerLGCM(
'a-priori', alpha = .05, power = .80, N = list(1, 1),
nWaves = 3,
means = c(.5, .2),
variances = c(1, .5),
covariances = list(
c(.25), # group 1
c(.1)), # group 2
nullEffect = 'isCovA = isCovB',
groupEqual = c('ivar', 'svar'),
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE
)
# perform a simulated post-hoc power analysis
# with 250 replications
set.seed(300121)
powerLGCM <- semPower.powerLGCM(
'post-hoc', alpha = .05, N = 500,
nWaves = 3,
means = c(.5, .2), # i, s
variances = c(1, .5), # i, s
covariances = .25,
nullEffect = 'sMean = 0',
nIndicator = rep(3, 3), loadM = .5,
autocorResiduals = TRUE,
simulatedPower = TRUE,
simOptions = list(nReplications = 250)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.