Skip to contents

Provides AIC, BIC and deviance statistic (G-squared) for goodness of fit test for the fitted model. Absolute model fit can be tested with deviance statistics, if test argument is specified.

Usage

gof(object, ...)

# S3 method for class 'slca'
gof(
   object, ..., test = c("none", "chisq", "boot"),
   nboot = 100, plot = FALSE,
   maxiter = 100, tol = 1e-6, verbose = FALSE
)

Arguments

object

an object of class slca and estimated.

...

additional objects of class slca and estimated.

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 rounds to be performed.

plot

a logical value indicating whether to print histogram of G-squared statistics for boostrap samples, only for test = "boot".

maxiter

an integer specifying maximum number of iterations allowed for the estimation process of each bootstrapping round.

tol

a numeric value setting tolerance for the convergence of each bootstrapping round.

verbose

a logical value indicating whether to print progress updates on the number of bootstrapping rounds completed.

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. Depending on the test argument, the p-value for the corresponding statistical test may also be included.

See also

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.7225    
#> stat4 43 -1135.4 2356.8 2539.4  28.423      31   0.5992    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# \donttest{
gof(stat2, stat3, stat4, test = "boot")
#> Analysis of Goodness of Fit Table
#> 
#>       Df  logLik    AIC    BIC     Gsq Res. Df Pr(Boot)    
#> stat2 21 -1179.2 2400.4 2489.5 115.979      53   <2e-16 ***
#> stat3 32 -1139.3 2342.6 2478.5  36.204      42     0.18    
#> stat4 43 -1135.4 2356.8 2539.4  28.423      31     0.20    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# }

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.7804      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.7804      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.7804      11     0.16
# }