Conducts a relative model fit test between two fitted SLCM models using the deviance statistic.
Arguments
- model1
an object of class
slcafit
.- model2
another object of class
slcafit
to be compared withmodel1
.- test
a character string specifying the type of test to be conducted. If
"chisq"
, a chi-squared test is conducted. If"boot"
, a bootstrap test is conducted.- nboot
an integer specifying the number of bootstrap iterations to perform (used only when
test = "boot"
). The default is 100.- method
a character string specifying the estimation method for bootstrapping.
- plot
a logical value indicating whether to display a histogram of G-squared statistics for the bootstrap samples (applicable only for
test = "boot"
). The default isFALSE
.- maxiter
an integer specifying the maximum number of iterations allowed during each bootstrap estimation round. The default is 100.
- tol
numeric value setting the convergence tolerance for each bootstrap iteration. The default is
1e-6
.- verbose
a logical value indicating whether to print progress updates on completed bootstrap iterations. The default is
FALSE
.
Value
A data.frame
containing the number of parameters (Df), loglikelihood, AIC, BIC, G-squared statistics, and the residual degree of freedom for each object.
If a statistical test is conducted (via test
), the resulting p-value for the comparison is also included.
Examples
library(magrittr)
data <- gss7677[gss7677$COHORT == "YOUNG", ]
stat2 <- slca(status(2) ~ PAPRES + PADEG + MADEG) %>%
estimate(data = data, control = list(verbose = FALSE))
stat3 <- slca(status(3) ~ PAPRES + PADEG + MADEG) %>%
estimate(data = data, control = list(verbose = FALSE))
stat4 <- slca(status(4) ~ PAPRES + PADEG + MADEG) %>%
estimate(data = data, control = list(verbose = FALSE))
gof(stat2, stat3, stat4)
#> Analysis of Goodness of Fit Table
#>
#> Df logLik AIC BIC Gsq Res. Df
#> stat2 21 -1179.2 2400.4 2489.5 115.979 53
#> stat3 32 -1139.3 2342.6 2478.5 36.204 42
#> stat4 43 -1135.4 2356.8 2539.4 28.423 31
gof(stat2, stat3, stat4, test = "chisq")
#> Analysis of Goodness of Fit Table
#>
#> Df logLik AIC BIC Gsq Res. Df Pr(>Chi)
#> stat2 21 -1179.2 2400.4 2489.5 115.979 53 1.34e-06 ***
#> stat3 32 -1139.3 2342.6 2478.5 36.204 42 0.7226
#> stat4 43 -1135.4 2356.8 2539.4 28.423 31 0.5993
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# \donttest{
gof(stat2, stat3, stat4, test = "boot")
#> Error in stats::nlm(llf, logit[-c(fix0, fix1, arg$ref_idx)], fix0, fix1, arg$ref_idx, arg$id, y = attr(mf, "y"), nobs = arg$nobs, nvar = arg$nvar, nlev = unlist(arg$nlev), nlv = arg$nlv, nrl = arg$nrl, nlf = arg$nlf, npi = arg$npi, ntau = arg$ntau, nrho = arg$nrho, ul = arg$ul, vl = arg$vl, lf = arg$lf, tr = arg$tr, rt = arg$rt, eqrl = arg$eqrl, eqlf = arg$eqlf, nc = arg$nc, nk = arg$nk, nl = arg$nl, ncl = arg$ncl, nc_pi = arg$nc_pi, nk_tau = arg$nk_tau, nl_tau = arg$nl_tau, nc_rho = arg$nc_rho, nr_rho = arg$nr_rho, iterlim = 1, hessian = TRUE): missing value in parameter
# }
compare(stat3, stat4)
#> Analysis of Relative Model Fit
#>
#> Model H0: stat3
#> Model H1: stat4
#> Df logLik AIC BIC Gsq Res. Df
#> stat3 32 -1139.3 2342.6 2478.5
#> stat4 43 -1135.4 2356.8 2539.4 7.7805 11
compare(stat3, stat4, test = "chisq")
#> Analysis of Relative Model Fit
#>
#> Model H0: stat3
#> Model H1: stat4
#> Df logLik AIC BIC Gsq Res. Df Pr(>Chi)
#> stat3 32 -1139.3 2342.6 2478.5
#> stat4 43 -1135.4 2356.8 2539.4 7.7805 11 0.7328
# \donttest{
compare(stat3, stat4, test = "boot")
#> Analysis of Relative Model Fit
#>
#> Model H0: stat3
#> Model H1: stat4
#> Df logLik AIC BIC Gsq Res. Df Pr(Boot)
#> stat3 32 -1139.3 2342.6 2478.5
#> stat4 43 -1135.4 2356.8 2539.4 7.7805 11 0.08 .
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# }