ChiBarSq.DiffTest: Chi-bar-square difference test

View source: R/Chi-bar-square_DiffTest.r

ChiBarSq.DiffTestR Documentation

Chi-bar-square difference test

Description

This function calculates the Chi-bar-square difference test of the RI-CLPM versus the CLPM or a general variance test. The first is discussed in Hamaker, Kuiper, and Grasman (2015) and the second in Stoel et al. (2006). There is also an interactive web application on my website: Chi-bar-square difference test (https://www.uu.nl/staff/RMKuiper/Websites%20%2F%20Shiny%20apps).

Usage

ChiBarSq.DiffTest(
  q,
  S,
  Chi2_clpm = NULL,
  Chi2_riclpm = NULL,
  df_clpm = NULL,
  df_riclpm = NULL,
  SB_clpm = NULL,
  SB_riclpm = NULL,
  alpha = 0.05,
  bootstrap = FALSE,
  seed = 123,
  iter = 1e+05,
  u = NULL,
  PrintPlot = TRUE,
  Min = 0,
  Max = 20,
  Step = 1
)

Arguments

q

The total number of variances (q = n + k), that is, the sum of the number of nuisance variances (n) and the number of constrained variances (k) whose values may be on the boundary of the parameter space under the null and the alternative hypotheses, that is, the number of random intercepts. When testing RI-CLPM vs CLPM (see Hamaker et al., 2015), q = k; in case of another test of variances (see Stoel et al., 2006), q >= k. Note: u = k*n + k*(k-1)/2 is the number of unconstrained variances and unconstrained covariances.

S

The k times k covariance matrix of the k constrained variances.

Chi2_clpm

The Chi-square value for the CLPM. In case of another test of variances, this refers to the Chi-square of the model with the k constrained variances (or, in general, the more constrained model). By default, Chi2_clpm = NULL; in that case, only the Chi-bar-square weights will be given and not the Chi-bar-square statistic with corresponding p-value.

Chi2_riclpm

The Chi-square value for the RI-CLPM. In case of another test of variances, this refers to the Chi-square of the model without the k constrained variances (or, in general, the less constrained model). By default, Chi2_riclpm = NULL; in that case, only the Chi-bar-square weights will be given and not the Chi-bar-square statistic with corresponding p-value.

df_clpm

The degrees of freedom of the Chi-square test in the CLPM (i.e., the model with the k constrained variances or the more constrained model). By default, df_clpm = NULL; in that case, only the Chi-bar-square weights will be given and not the Chi-bar-square statistic with corresponding p-value.

df_riclpm

The degrees of freedom of the Chi-square test in the RI-CLPM (i.e., the model without the k constrained variances or the less constrained model). By default, df_riclpm = NULL; in that case, only the Chi-bar-square weights will be given and not the Chi-bar-square statistic with corresponding p-value.

SB_clpm

Optional. The Satorra-Bentler scaled Chi-square value for the CLPM (i.e., the model with the k constrained variances or the more constrained model). By default, SB_clpm = NULL; in that case, the difference test will be solely based on the unadjusted/regular Chi-square value.

SB_riclpm

Optional. The Satorra-Bentler scaled Chi-square value for the RI-CLPM (i.e., the model without the k constrained variances or the less constrained model). By default, SB_riclpm = NULL; in that case, the difference test will be solely based on the unadjusted/regular Chi-square value.

alpha

The alpha level in determining the significance of the Chi-bar-square difference test. By default, alpha = 0.05.

bootstrap

Indicator (TRUE/FALSE or 1/0) whether the Chi-bar-square weights are determined using bootstrap (TRUE or 1) or using the package ic.infer (FALSE or 0; default). By default, bootstrap = FALSE (and thus ic.infer is used).

seed

The seed number, used in case bootstrap = TRUE. By changing this number, the sensitivity of the results can be inspected. By default, seed = 123.

iter

The number of iterations, used in case bootstrap = TRUE. By changing this number, the sensitivity/precision of the results can be inspected. By default, iter = 100000.

u

The number of unconstrained parameters of interest. In case of a more general test than a variance test, 'u' can easily be specified and there is no 'q'. For more details, see Stoel et al. (2006). By default, a variance test is assumed and thus the argument u = NULL implying that u = k*n + k*(k-1)/2 is used in the calculation. If 'u' is specified, then 'q' is discarded and can be set to NULL.

PrintPlot

Optional. Indicator (TRUE/FALSE or 1/0) whether Chi-bar-square distribution plot should be printed (TRUE or 1) or not (FALSE or 0); together with the critical value. By default, PrintPlot = TRUE (and thus a plot is rendered).

Min

Optional. Minimum value used in the Chi-bar-square distribution plot. By default, Min = 0.

Max

Optional. Maximum time used in the Chi-bar-square distribution plot. By default, Max = 20. If Max is lower than critical value c2, then it is changed to c2+1.

Step

Optional. The step-size taken in the Chi-bar-square distribution plot. By default, Step = 1.

Value

The output comprises, among other things, the Chi-bar-square weights and critical value for the Chi-bar-square statistic (if asked for) the Chi-bar-square statistic and corresponding p-value.

Examples


# library(ChiBarSq.DiffTest)

# Compare fit CLPM vs RI-CLPM
# For an elaborate example, see https://ellenhamaker.github.io/RI-CLPM/lavaan.html#(bar{chi}^{2})-test.

# Specification of input needed in the examples below:
# There are 2 random intercepts in the RI-CLPM (omega and kappa): q = k = 2
q <- 2
# The full covariance matrix of the random intercepts is:
S <- matrix(c(1.232, -0.118, -0.118, 0.539), byrow = T, ncol = q)
# Chi-square values
Chi2_clpm <- 20.6779  #The Chi-square value of CLPM is 20.6779
Chi2_riclpm <- 3.2127 #The Chi-square value of RI-CLPM is 3.2127
#Degrees of freedom (df)
df_clpm <- 4   #The df in CLPM is 4
df_riclpm <- 1 #The df in RI-CLPM is 1

# Run function to obtain Chi-bar-square weights and critical value for the Chi-bar-square statistic
ChiBarSq.DiffTest(q, S)

# Run function to obtain Chi-bar-square weights based on bootstrap
ChiBarSq.DiffTest(q, S, bootstrap = T, seed = 123, iter = 100000)

# Run function to do Chi-bar-square test (and also obtain Chi-bar-square weights and critical value)
ChiBarSq.DiffTest(q, S, Chi2_clpm, Chi2_riclpm, df_clpm, df_riclpm)

# Different types of output options are possible:
ChiBar2 <- ChiBarSq.DiffTest(q, S, Chi2_clpm, Chi2_riclpm, df_clpm, df_riclpm)
ChiBar2 # same as print(ChiBar2)
summary(ChiBar2)
print(ChiBar2, digits = 4)
summary(ChiBar2, digits = 4)
# In Rstudio, use 'ChiBar2$' to see what output there is:
# ChiBar2$message; ChiBar2$k; ChiBar2$u; ChiBar2$S; ChiBar2$ChiBar2_weights; ChiBar2$critical_value; ChiBar2$DiffChi2; ChiBar2$CritValSmallerDiffChi2; ChiBar2$p_value; ChiBar2$pSmallerAlpha
# and possibly: ChiBar2$ChiBar2_plot


# Run function based on using 'u' as input to do Chi-bar-square test (and also obtain Chi-bar-square weights and critical value)
# For simplicity, we use the same example as above and calculate u based on input above - normally you would know u (and not q).
q <- 2
k <- 2
n <- q-k
u <- k*n + k*(k-1)/2 # This expression holds in case of k constrained variances and thus also in case of k random intercepts.
#
ChiBarSq.DiffTest(q, S, Chi2_clpm, Chi2_riclpm, df_clpm, df_riclpm, u = u)
# Or
ChiBarSq.DiffTest(NULL, S, Chi2_clpm, Chi2_riclpm, df_clpm, df_riclpm, u = u)
# But do NOT leave the q-argument out like this:
#ChiBarSq.DiffTest(S, Chi2_clpm, Chi2_riclpm, df_clpm, df_riclpm, u = u) # Note: This does not work (properly) and gives an error.
# It is possible to use: ChiBarSq.DiffTest(S = S, Chi2_clpm = Chi2_clpm, Chi2_riclpm = Chi2_riclpm, df_clpm = df_clpm, df_riclpm = df_riclpm, u = u)
#
# Note: This is now again based on testing the CLPM versus the RI-CLPM, but this code is most helpful in case of a more general test than a 'k constrained variance test'. For more details, see Stoel et al. (2006).


rebeccakuiper/ChiBarSq.DiffTest documentation built on March 21, 2023, 9:46 p.m.