View source: R/convenienceFunctions.R
semPower.powerPath | R Documentation |
Convenience function for performing power analyses for hypothesis arising in a generic path model. This requires the lavaan package.
semPower.powerPath(
type,
comparison = "restricted",
Beta,
Psi = NULL,
nullEffect = "beta = 0",
nullWhich = NULL,
nullWhichGroups = NULL,
standardized = TRUE,
...
)
type |
type of power analysis, one of |
comparison |
comparison model, one of |
Beta |
matrix of regression slopes between latent variables (all-Y notation). A list for multiple group models. Exogenous variables must occupy the first rows in |
Psi |
variance-covariance matrix of latent (residual) factors. If |
nullEffect |
defines the hypothesis of interest, must be one of |
nullWhich |
vector of size 2 indicating which slope in |
nullWhichGroups |
for |
standardized |
whether all parameters should be standardized ( |
... |
mandatory further parameters related to the specific type of power analysis requested, see |
This function performs a power analysis to reject a hypothesis arising in a generic structural equation model specifying regression relations between the factors via the Beta matrix:
nullEffect = 'beta = 0'
: Tests the hypothesis that a slope is zero.
nullEffect = 'betaX = betaZ'
: Tests the hypothesis that two or more slopes are equal to each other.
nullEffect = 'betaA = betaB'
: Tests the hypothesis that a slope is equal in two or more groups (always assuming metric invariance).
This function provides a generic way to perform power analyses (as compared to other functions covering special cases in a more accessible manner).
A specific hypothesis is defined by setting nullEffect
to define the hypothesis type,
nullWhich
to define the slope(s) that are targeted, and by providing
the Beta
(and optionally the Psi
) matrix to define the population structure.
To understand the structure of Beta
and Psi
, consider the general structural equation model,
\Sigma = \Lambda (I - B)^{-1} \Psi [(I - B)^{-1}]' \Lambda' + \Theta
where B
is the m \cdot m
matrix containing the regression slopes and \Psi
is the (residual) variance-covariance matrix of the m
factors.
As an example, suppose there are four factors (X1, X2, X3, X4), and Beta is defined as follows:
\begin{array}{lrrrr}
& X_1 & X_2 & X_3 & X_4\\
X_1 & 0.0 & 0.0 & 0.0 & 0.0 \\
X_2 & 0.0 & 0.0 & 0.0 & 0.0 \\
X_3 & 0.2 & 0.3 & 0.0 & 0.0 \\
X_4 & 0.3 & 0.5 & 0.0 & 0.0 \\
\end{array}
Each row specifies how a particular factor is predicted by the available factors, so the above implies the following regression relations:
X_1 = 0.0 \cdot X_1 + 0.0 \cdot X_2 + 0.0 \cdot X_3 + 0.0 \cdot X_4 \\
X_2 = 0.0 \cdot X_1 + 0.0 \cdot X_2 + 0.0 \cdot X_3 + 0.0 \cdot X_4 \\
X_3 = 0.2 \cdot X_1 + 0.3 \cdot X_2 + 0.0 \cdot X_3 + 0.0 \cdot X_4 \\
X_4 = 0.3 \cdot X_1 + 0.5 \cdot X_2 + 0.0 \cdot X_3 + 0.0 \cdot X_4
which simplifies to
X_3 = 0.2 \cdot X_1 + 0.3 \cdot X_2 \\
X_4 = 0.3 \cdot X_1 + 0.5 \cdot X_2
Further suppose that Psi is
\begin{array}{lrrrr}
& X_1 & X_2 & X_3 & X_4\\
X_1 & 1.0 & 0.3 & 0.0 & 0.0 \\
X_2 & 0.3 & 1.0 & 0.0 & 0.0 \\
X_3 & 0.0 & 0.0 & 1.0 & 0.2 \\
X_4 & 0.0 & 0.0 & 0.2 & 1.0 \\
\end{array}
which implies a correlation between X1 and X2 of .3 and a residual correlation between X3 and X4 of .2.
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
always need to be defined.
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.aPriori()
semPower.postHoc()
semPower.compromise()
## Not run:
# set up pathmodel in the form of
# f2 = .2*f1
# f3 = .3*f2
# f4 = .1*f1 + .4*f3
# obtain the required N to detect that the
# slope f1 -> f4 is >= .10
# with a power of 95% on alpha = 5%
# where f1 is measured by 3, f2 by 4, f3 by 5, and f4 by 6 indicators,
# and all loadings are .5
Beta <- matrix(c(
c(.00, .00, .00, .00), # f1
c(.20, .00, .00, .00), # f2
c(.00, .30, .00, .00), # f3
c(.10, .00, .40, .00) # f4
), byrow = TRUE, ncol = 4)
powerPath <- semPower.powerPath(type = 'a-priori',
Beta = Beta,
nullWhich = c(4, 1),
nIndicator = c(3, 4, 5, 6),
loadM = .5,
alpha = .05, beta = .05)
# show summary
summary(powerPath)
# optionally use lavaan to verify the model was set-up as intended
lavaan::sem(powerPath$modelH1, sample.cov = powerPath$Sigma,
sample.nobs = powerPath$requiredN, sample.cov.rescale = FALSE)
lavaan::sem(powerPath$modelH0, sample.cov = powerPath$Sigma,
sample.nobs = powerPath$requiredN, sample.cov.rescale = FALSE)
# same as above, but detect that the slope f3 -> f4 is >= .30
powerPath <- semPower.powerPath(type = 'a-priori',
Beta = Beta,
nullWhich = c(4, 3),
nIndicator = c(3, 4, 5, 6),
loadM = .5,
alpha = .05, beta = .05)
# same as above, but detect that
# the slope f1 -> f2 (of .20) differs from the slope f2 -> f3 (of .30)
powerPath <- semPower.powerPath(type = 'a-priori',
Beta = Beta,
nullEffect = 'betaX = betaZ',
nullWhich = list(c(2, 1), c(3, 2)),
nIndicator = c(3, 4, 5, 6),
loadM = .5,
alpha = .05, beta = .05)
# same as above, but consider a multiple group model with equally sized groups,
# and obtain the required N to detect that the slope
# in group 1 (of .20) differs from the one in group 2 (of .40)
Beta1 <- Beta2 <- matrix(c(
c(.00, .00, .00, .00), # f1
c(.20, .00, .00, .00), # f2
c(.00, .30, .00, .00), # f3
c(.10, .00, .40, .00) # f4
), byrow = TRUE, ncol = 4)
Beta2[2, 1] <- .40
Beta <- list(Beta1, Beta2)
powerPath <- semPower.powerPath(type = 'a-priori',
Beta = Beta,
nullEffect = 'betaA = betaB',
nullWhich = c(2, 1),
nIndicator = c(3, 4, 5, 6),
loadM = .5,
alpha = .05, beta = .05, N = list(1, 1))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.