Skip to contents

Test all free parameters, including user-defined parameters, for a power4test object.

Usage

test_parameters(
  fit = fit,
  standardized = FALSE,
  pars = NULL,
  op = NULL,
  remove.nonfree = TRUE,
  check_post_check = TRUE,
  ...,
  omnibus = c("no", "all_sig", "at_least_one_sig", "at_least_k_sig"),
  at_least_k = 1,
  fit_name = "fit",
  get_map_names = FALSE,
  get_test_name = FALSE
)

find_par_names(object, fit_name = "fit")

Arguments

fit

The fit object, to be passed to lavaan::parameterEstimates(), lavaan::standardizedSolution(), or lmhelprs::lm_list_to_partable().

standardized

Logical. If TRUE, lavaan::standardizedSolution() will be used. Can be used only with models fitted by lavaan.

pars

Optional. If set to a character vector, only parameters with test_label equal to values in pars will be returned. See the help page on valid names.

op

Optional. If set to a character vector, only parameters with operators (e.g., "~", "=~") will be returned. If both pars and op are specified, only parameters meeting both requirements will be returned.

remove.nonfree

Logical. If TRUE, the default, only free parameters will be returned. Ignored if standardized is TRUE or if the model is not fitted by lavaan.

check_post_check

Logical. If TRUE, the default, and the model is fitted by lavaan, the test will be conducted only if the model passes the post.check conducted by lavaan::lavInspect() (with what = "post.check").

...

Additional arguments to be passed to lavaan::parameterEstimates(), lavaan::standardizedSolution(), or lmhelprs::lm_list_to_partable().

omnibus

If "no", the default, then the test results for all paths are stored. If "all_sig", then only one row of test is stored, and the test is declared significant if all paths are significant. If "at_least_one_sig", then only one row of test is stored, and the test is declared significant if at least one of the paths is significant. If "at_least_k_sig", then only one row of test is stored, and the test is declared significant if at least k of the paths is significant, k determined by the argument at_least_k.

at_least_k

The minimum number of paths required to be significant for the omnibus test to be considered significant. Used when omnibus is "at_least_k_sig".

fit_name

The name of the fit results for which the parameter names will be displayed. Default is "fit".

get_map_names

Logical. Used by power4test() to determine how to extract stored information and assign them to this function. Users should not use this argument.

get_test_name

Logical. Used by power4test() to get the default name of this test. Users should not use this argument.

object

A power4test object.

Value

In its normal usage, it returns the output returned by lavaan::parameterEstimates() or lmhelprs::lm_list_to_partable(), with the following modifications:

  • est: The parameter estimates, even if standardized estimates are requested (not est.std).

  • cilo and cihi: The lower and upper limits of the confidence interval (95% by default), respectively (not ci.lower and ci.upper).

  • sig: Whether a test by confidence interval is significant (1) or not significant (0).

  • test_label: A column of labels generated by lavaan::lav_partable_labels(), which are usually the labels used by coef() to label the parameters.

Details

This function is to be used in power4test() for testing all free and user-defined model parameters, by setting it to the test_fun argument.

For models fitted by lavaan, it uses lavaan::parameterEstimates() to do the test. If bootstrapping was requested (by setting se = "boot"), then it supports bootstrap confidence intervals returned by lavaan::parameterEstimates().

It has preliminary, though limited, supported for models fitted by stats::lm() (through lmhelprs::many_lm()). Tests are conducted by ordinary least squares confidence intervals based on the t statistic, reported by stats::confint() applied to the output of stats::lm().

Find the names of parameters

To use the argument pars, the names as appeared in the function coef() must be used. For the output of lavaan, this can usually be inferred from the parameter syntax (e.g., y~x, no space). If not sure, call coef() on the output of lavaan. If a parameter is labelled, then the label should be used in par.

If not sure, the function find_par_names() can be used to find valid names.

See also

Examples


# Specify the model

mod <-
"
m ~ x
y ~ m + x
"

# Specify the population values

mod_es <-
"
y ~ m: l
m ~ x: m
y ~ x: n
"

# Simulate the data

sim_only <- power4test(nrep = 2,
                       model = mod,
                       pop_es = mod_es,
                       n = 100,
                       do_the_test = FALSE,
                       iseed = 1234)
#> Simulate the data:
#> Fit the model(s):

# Do the tests in each replication

test_out <- power4test(object = sim_only,
                       test_fun = test_parameters)
#> Do the test: test_parameters: CIs  

print(test_out,
      test_long = TRUE)
#> 
#> ====================== Model Information ======================
#> 
#> == Model on Factors/Variables ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> == Model on Variables/Indicators ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> ====== Population Values ======
#> 
#> Regressions:
#>                    Population
#>   m ~                        
#>     x                 0.300  
#>   y ~                        
#>     m                 0.500  
#>     x                 0.000  
#> 
#> Variances:
#>                    Population
#>    .m                 0.910  
#>    .y                 0.750  
#>     x                 1.000  
#> 
#> (Computing indirect effects for 2 paths ...)
#> 
#> == Population Conditional/Indirect Effect(s) ==
#> 
#> == Indirect Effect(s) ==
#> 
#>               ind
#> x -> m -> y 0.150
#> x -> y      0.000
#> 
#>  - The 'ind' column shows the indirect effect(s).
#>  
#> ======================= Data Information =======================
#> 
#> Number of Replications:  2 
#> Sample Sizes:  100 
#> 
#> Call print with 'data_long = TRUE' for further information.
#> 
#> ==================== Extra Element(s) Found ====================
#> 
#> - fit
#> 
#> === Element(s) of the First Dataset ===
#> 
#> ============ <fit> ============
#> 
#> lavaan 0.6-19 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         5
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 0.000
#>   Degrees of freedom                                 0
#> 
#> =============== <test_parameters: CIs > ===============
#> 
#> Mean(s) across replication:
#>   test_label lhs op rhs    est    se      z pvalue   cilo  cihi   sig
#> 1        m~x   m  ~   x  0.382 0.103  3.698  0.000  0.179 0.585 1.000
#> 2        y~m   y  ~   m  0.443 0.094  4.715  0.000  0.259 0.627 1.000
#> 3        y~x   y  ~   x -0.029 0.104 -0.226  0.236 -0.232 0.174 0.000
#> 4       m~~m   m ~~   m  0.945 0.134  7.071  0.000  0.683 1.207 1.000
#> 5       y~~y   y ~~   y  0.836 0.118  7.071  0.000  0.604 1.068 1.000
#> 
#> - The column 'sig' shows the rejection rates.
#> - If the null hypothesis is false, the rate is the power.
#> - Number of valid replications for rejection rate(s): 2 
#> - Proportion of valid replications for rejection rate(s): 1.000 

# Do the tests in each replication: Standardized solution
# Delta method SEs will be used to do the tests

test_out <- power4test(object = sim_only,
                       test_fun = test_parameters,
                       test_args = list(standardized = TRUE))
#> Do the test: test_parameters: CIs (standardized)  

print(test_out,
      test_long = TRUE)
#> 
#> ====================== Model Information ======================
#> 
#> == Model on Factors/Variables ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> == Model on Variables/Indicators ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> ====== Population Values ======
#> 
#> Regressions:
#>                    Population
#>   m ~                        
#>     x                 0.300  
#>   y ~                        
#>     m                 0.500  
#>     x                 0.000  
#> 
#> Variances:
#>                    Population
#>    .m                 0.910  
#>    .y                 0.750  
#>     x                 1.000  
#> 
#> (Computing indirect effects for 2 paths ...)
#> 
#> == Population Conditional/Indirect Effect(s) ==
#> 
#> == Indirect Effect(s) ==
#> 
#>               ind
#> x -> m -> y 0.150
#> x -> y      0.000
#> 
#>  - The 'ind' column shows the indirect effect(s).
#>  
#> ======================= Data Information =======================
#> 
#> Number of Replications:  2 
#> Sample Sizes:  100 
#> 
#> Call print with 'data_long = TRUE' for further information.
#> 
#> ==================== Extra Element(s) Found ====================
#> 
#> - fit
#> 
#> === Element(s) of the First Dataset ===
#> 
#> ============ <fit> ============
#> 
#> lavaan 0.6-19 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         5
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 0.000
#>   Degrees of freedom                                 0
#> 
#> ======== <test_parameters: CIs (standardized) > ========
#> 
#> Mean(s) across replication:
#>   test_label lhs op rhs    est    se      z pvalue   cilo  cihi   sig
#> 1        m~x   m  ~   x  0.347 0.085  4.069  0.000  0.180 0.514 1.000
#> 2        y~m   y  ~   m  0.446 0.086  5.190  0.000  0.277 0.615 1.000
#> 3        y~x   y  ~   x -0.024 0.094 -0.233  0.232 -0.209 0.160 0.000
#> 4       m~~m   m ~~   m  0.880 0.059 14.888  0.000  0.764 0.995 1.000
#> 5       y~~y   y ~~   y  0.791 0.071 11.181  0.000  0.652 0.931 1.000
#> 6       x~~x   x ~~   x  1.000 0.000    NaN    NaN  1.000 1.000 1.000
#> 
#> - The column 'sig' shows the rejection rates.
#> - If the null hypothesis is false, the rate is the power.
#> - Number of valid replications for rejection rate(s): 2 
#> - Proportion of valid replications for rejection rate(s): 1.000 

# Do the tests in each replication: Parameters with the selected operator

test_out <- power4test(object = sim_only,
                       test_fun = test_parameters,
                       test_args = list(op = "~"))
#> Do the test: test_parameters: CIs (op: ~) 

print(test_out,
      test_long = TRUE)
#> 
#> ====================== Model Information ======================
#> 
#> == Model on Factors/Variables ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> == Model on Variables/Indicators ==
#> 
#> m ~ x
#> y ~ m + x
#> 
#> ====== Population Values ======
#> 
#> Regressions:
#>                    Population
#>   m ~                        
#>     x                 0.300  
#>   y ~                        
#>     m                 0.500  
#>     x                 0.000  
#> 
#> Variances:
#>                    Population
#>    .m                 0.910  
#>    .y                 0.750  
#>     x                 1.000  
#> 
#> (Computing indirect effects for 2 paths ...)
#> 
#> == Population Conditional/Indirect Effect(s) ==
#> 
#> == Indirect Effect(s) ==
#> 
#>               ind
#> x -> m -> y 0.150
#> x -> y      0.000
#> 
#>  - The 'ind' column shows the indirect effect(s).
#>  
#> ======================= Data Information =======================
#> 
#> Number of Replications:  2 
#> Sample Sizes:  100 
#> 
#> Call print with 'data_long = TRUE' for further information.
#> 
#> ==================== Extra Element(s) Found ====================
#> 
#> - fit
#> 
#> === Element(s) of the First Dataset ===
#> 
#> ============ <fit> ============
#> 
#> lavaan 0.6-19 ended normally after 1 iteration
#> 
#>   Estimator                                         ML
#>   Optimization method                           NLMINB
#>   Number of model parameters                         5
#> 
#>   Number of observations                           100
#> 
#> Model Test User Model:
#>                                                       
#>   Test statistic                                 0.000
#>   Degrees of freedom                                 0
#> 
#> ============ <test_parameters: CIs (op: ~)> ============
#> 
#> Mean(s) across replication:
#>   test_label lhs op rhs    est    se      z pvalue   cilo  cihi   sig
#> 1        m~x   m  ~   x  0.382 0.103  3.698  0.000  0.179 0.585 1.000
#> 2        y~m   y  ~   m  0.443 0.094  4.715  0.000  0.259 0.627 1.000
#> 3        y~x   y  ~   x -0.029 0.104 -0.226  0.236 -0.232 0.174 0.000
#> 
#> - The column 'sig' shows the rejection rates.
#> - If the null hypothesis is false, the rate is the power.
#> - Number of valid replications for rejection rate(s): 2 
#> - Proportion of valid replications for rejection rate(s): 1.000 


# Finding valid parameter names

find_par_names(sim_only)
#> [1] "m~x"  "y~m"  "y~x"  "m~~m" "y~~y"