View source: R/convenienceFunctions.R
semPower.powerARMA | R Documentation |
Convenience function for performing power analysis on effects in an ARMA model. This requires the lavaan package.
semPower.powerARMA(
type,
comparison = "restricted",
nWaves = NULL,
autoregEffects = NULL,
autoregLag1 = autoregEffects,
autoregLag2 = NULL,
autoregLag3 = NULL,
mvAvgLag1 = NULL,
mvAvgLag2 = NULL,
mvAvgLag3 = NULL,
means = NULL,
variances = NULL,
waveEqual = NULL,
groupEqual = NULL,
nullEffect = NULL,
nullWhich = NULL,
nullWhichGroups = NULL,
invariance = TRUE,
autocorResiduals = TRUE,
...
)
type |
type of power analysis, one of |
comparison |
comparison model, one of |
nWaves |
number of waves, must be >= 2. |
autoregEffects |
vector of the lag-1 autoregressive effects, e.g. |
autoregLag1 |
alternative name for autoregEffects. |
autoregLag2 |
vector of lag-2 effects, e.g. |
autoregLag3 |
vector of lag-3 effects, e.g. |
mvAvgLag1 |
vector of the lag-1 moving average parameters, e.g. |
mvAvgLag2 |
vector of the lag-2 moving average parameters, e.g. |
mvAvgLag3 |
vector of the lag-3 moving average parameters, e.g. |
means |
vector of means of |
variances |
vector of variances of the noise factors |
waveEqual |
parameters that are assumed to be equal across waves in both the H0 and the H1 model. Because ARMA models are likely not identified when no such constraints are imposed, this may not be empty. Valid are |
groupEqual |
parameters that are restricted across groups in both the H0 and the H1 model, when |
nullEffect |
defines the hypothesis of interest. Valid are the same arguments as in |
nullWhich |
used in conjunction with |
nullWhichGroups |
for hypothesis involving cross-groups comparisons, vector indicating the groups for which equality constrains should be applied, e.g. |
invariance |
whether metric invariance over waves is assumed ( |
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 models with autoregressive and moving average parameters (ARMA models), where one variable X
is repeatedly
assessed at different time points (nWaves
), and autoregressive (lag-1 effects; X1 -> X2 -> X3
, and optionally lag-2 and lag-3) effects,
and moving average parameters (N1 -> X2
, or equivalently for lag-2 and lag-3 effects) are assumed.
Relevant hypotheses in arising in an ARMA model are:
autoreg
: Tests the hypothesis that the autoregressive lag-1 effects are equal across waves (stationarity of autoregressive lag-1 effects).
autoregLag2
: Tests the hypothesis that the autoregressive lag-2 effects are equal across waves (stationarity of autoregressive lag-2 effects).
autoregLag3
: Tests the hypothesis that the autoregressive lag-3 effects are equal across waves (stationarity of autoregressive lag-3 effects).
mvAvg
: Tests the hypothesis that the moving average lag-1 parameters are equal across waves (stationarity of moving average lag-1 effects).
mvAvgLag2
: Tests the hypothesis that the moving average lag-2 parameters are equal across waves (stationarity of moving average lag-2 effects).
mvAvgLag3
: Tests the hypothesis that the moving average lag-3 parameters are equal across waves (stationarity of moving average lag-3 effects).
var
: Tests the hypothesis that the variances of the noise factors N (= the residual variances of X) are equal across waves 2 to nWaves (stationarity of variance).
mean
: Tests the hypothesis that the conditional means of X are equal across waves 2 to nWaves (stationarity of means).
autoreg = 0
, autoregLag2 = 0
, autoregLag3 = 0
: Tests the hypothesis that the autoregressive effects of the specified lag is zero.
mvAvg = 0
, mvAvgLag2 = 0
, mvAvgLag3 = 0
: Tests the hypothesis that the moving average parameter of the specified lag is zero.
autoregA = autoregB
: Tests the hypothesis that the autoregressive lag-1 effect is equal across groups.
mvAvgA = mvAvgB
: Tests the hypothesis that the moving average lag-1 parameter is equal across groups.
varA = varB
: Tests the hypothesis that the variance of the noise factors are equal across groups.
meanA = meanB
: Tests the hypothesis that latent means are equal across groups.
For hypotheses regarding a simple autoregression, see semPower.powerAutoreg()
. For hypotheses regarding a CLPM structure, see semPower.powerCLPM()
. For hypotheses regarding longitudinal measurement invariance, see semPower.powerLI()
.
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. Note that neither may contain the noise 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).
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 10-wave ARMA model
# to detect that the autoregressive effects differ across waves
# with a power of 80% on alpha = 5%, where
# X is measured by 3 indicators loading by .5 each (at each wave), and
# the autoregressive effects vary between .5 and .7, and
# the moving average parameters are .3 at each wave and
# are assumed to be constant across waves (in both the H0 and the H1 model) and
# there are no lagged effects, and
# metric invariance and autocorrelated residuals are assumed
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# show summary
summary(powerARMA)
# optionally use lavaan to verify the model was set-up as intended
lavaan::sem(powerARMA$modelH1, sample.cov = powerARMA$Sigma,
sample.nobs = powerARMA$requiredN,
sample.cov.rescale = FALSE)
lavaan::sem(powerARMA$modelH0, sample.cov = powerARMA$Sigma,
sample.nobs = powerARMA$requiredN,
sample.cov.rescale = FALSE)
# same as above, but determine power with N = 250 on alpha = .05
powerARMA <- semPower.powerARMA(
'post-hoc', alpha = .05, N = 250,
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but determine the critical chi-square with N = 250 so that alpha = beta
powerARMA <- semPower.powerARMA(
'compromise', abratio = 1, N = 250,
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but compare to the saturated model
# (rather than to the less restricted model)
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80, comparison = 'saturated',
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but assume only observed variables
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
Lambda = diag(1, 10),
invariance = TRUE,
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)
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = c(.5, .7, .6, .5, .7, .6, .6, .5, .6),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
loadings = list(
c(.5, .6, .4), # X1
c(.5, .6, .4), # X2
c(.5, .6, .4), # X3
c(.5, .6, .4), # X4
c(.5, .6, .4), # X5
c(.5, .6, .4), # X6
c(.5, .6, .4), # X7
c(.5, .6, .4), # X8
c(.5, .6, .4), # X9
c(.5, .6, .4) # X10
),
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but detect that the moving average parameters differ across waves
# with a power of 80% on alpha = 5%, where
# the moving average parameters vary between .05 and .4, and
# the autoregressive effects are .5 at each wave and
# are assumed to be constant across waves (in both the H0 and the H1 model)
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = rep(.5, 9),
mvAvgLag1 = c(.1, .05, .2, .1, .1, .3, .4, .4, .4),
variances = rep(1, 10),
waveEqual = c('autoreg'),
nullEffect = 'mvAvg',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but detect that the (noise) variances differ across waves
# with a power of 80% on alpha = 5%, where
# the variances vary between 0.5 and 2, and
# the autoregressive effects are .5 at each wave and
# the moving average parameters are .3 at each wave and
# bothj are assumed to be constant across waves (in both the H0 and the H1 model)
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = rep(.5, 9),
mvAvgLag1 = rep(.3, 9),
variances = c(1, .5, .7, .6, .7, .9, 1.2, 1.7, 2.0, 1.5),
waveEqual = c('autoreg', 'mvAvg'),
nullEffect = 'var',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# same as above, but include a meanstructure and
# detect that the means differ across waves
# with a power of 80% on alpha = 5%, where
# the means vary between 0 and .5, and
# the autoregressive effects are .5 at each wave and
# the moving average parameters are .3 at each wave and
# the variances are 1 at each wave and
# all are assumed to be constant across waves (in both the H0 and the H1 model) and
# metric and scalar invariance is assumed
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = rep(.5, 9),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
means = c(0, .1, .2, .3, .4, .5, .3, .4, .5, .5),
waveEqual = c('autoreg', 'mvAvg', 'var'),
nullEffect = 'mean',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# Determine required N in a 10-wave ARMA model
# to detect that the autoregressive lag-2 effects differ from zero
# with a power of 80% on alpha = 5%, where
# the lag-2 autoregressive effects are .2 at each wave and
# the lag-2 autoregressive effects are .1 at each wave and
# the autoregressive effects are .5 at each wave and
# the moving average parameters are .3 at each wave and
# the noise variances are equal to 1 in each wave,
# and all are assumed to be constant across waves (in both the H0 and the H1 model) and
# metric invariance and autocorrelated residuals are assumed, and
# the autoregressive lag2- and lag3-effects are estimated
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = rep(.5, 9),
autoregLag2 = rep(.2, 8),
autoregLag3 = rep(.1, 7),
mvAvgLag1 = rep(.3, 9),
variances = rep(1, 10),
waveEqual = c('mvAvg', 'autoreg', 'var', 'autoreglag2', 'autoreglag3'),
nullEffect = 'autoreglag2 = 0',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# similar as above, but get required N to detect that
# lag-2 moving average parameters are constant across waves
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80,
nWaves = 10,
autoregLag1 = rep(.5, 9),
autoregLag2 = rep(.2, 8),
mvAvgLag1 = rep(.3, 9),
mvAvgLag2 = c(.1, .2, .3, .1, .2, .3, .1, .1),
variances = rep(1, 10),
waveEqual = c('mvAvg', 'autoreg', 'var', 'autoreglag2'),
nullEffect = 'mvAvgLag2',
nIndicator = rep(3, 10), loadM = .5,
invariance = TRUE
)
# Determine required N in a 5-wave ARMA model
# to detect that the autoregressive effects in group 1
# differ from the ones in group 2, where
# both groups are equal-sized
# 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 autoregressive effects in group 1 are .5 (constant across waves) and
# the autoregressive effects in group 2 are .6 (constant across waves) and
# the moving average parameters are .25 at each wave and in both groups and
# the variances are 1 at each wave and in both groups and
# all are assumed to be constant across waves (in both the H0 and the H1 model)
# metric invariance (across both waves and groups) and
# autocorrelated residuals are assumed
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80, N = list(1, 1),
nWaves = 5,
autoregLag1 = list(
c(.5, .5, .5, .5), # group 1
c(.6, .6, .6, .6)), # group 2
mvAvgLag1 = rep(.25, 4),
variances = rep(1, 5),
waveEqual = c('autoreg', 'var', 'mvavg'),
nullEffect = 'autoregA = autoregB',
nIndicator = rep(3, 5), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# Determine required N in a 5-wave ARMA model
# to detect that the means in group 1
# differ from the means in group 2, where
# both groups are equal-sized
# 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 autoregressive effects are .5 at each wave and in both groups and
# the moving average parameters are .25 at each wave and in both groups and
# the variances are 1 at each wave and in both groups and
# all are assumed to be constant across waves (in both the H0 and the H1 model) and
# invariance of variances, autoregressive effects, and moving average parameters
# across groups as well as
# metric and scalar invariance (across both waves and groups) and
# autocorrelated residuals are assumed
powerARMA <- semPower.powerARMA(
'a-priori', alpha = .05, power = .80, N = list(1, 1),
nWaves = 5,
autoregLag1 = list(
c(.5, .5, .5, .5), # group 1
c(.5, .5, .5, .5)), # group 2
mvAvgLag1 = rep(.25, 4),
variances = rep(1, 5),
means = list(
c(0, .1, .1, .1, .1), # group 1
c(0, .4, .4, .4, .4) # group 2
),
waveEqual = c('autoreg', 'var', 'mvavg', 'mean'),
groupEqual = c('var', 'autoreg', 'mvavg'),
nullEffect = 'meanA = meanB',
nIndicator = rep(3, 5), loadM = .5,
invariance = TRUE,
autocorResiduals = TRUE
)
# perform a simulated post-hoc power analysis
# with 250 replications
set.seed(300121)
powerARMA <- semPower.powerARMA(
'post-hoc', alpha = .05, N = 500,
nWaves = 5,
autoregLag1 = c(.3, .7, .6, .3),
mvAvgLag1 = rep(.3, 4),
variances = rep(1, 5),
waveEqual = c('mvAvg'),
nullEffect = 'autoreg',
nIndicator = rep(3, 5), loadM = .5,
invariance = TRUE,
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.