Learn R Programming

slca (version 1.3.0)

compare: Compare Two Fitted slca Models

Description

Conducts a relative model fit test between two fitted SLCM models using the deviance statistic.

Usage

compare(
  model1,
  model2,
  test = c("none", "chisq", "boot"),
  nboot = 50,
  method = c("hybrid", "em", "nlm"),
  plot = FALSE,
  maxiter = 1000,
  tol = 1e-08,
  verbose = 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.

Arguments

model1

an object of class slcafit.

model2

another object of class slcafit to be compared with model1.

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 is FALSE.

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.

See Also

gof

Examples

Run this code
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)
gof(stat2, stat3, stat4, test = "chisq")
# \donttest{
gof(stat2, stat3, stat4, test = "boot")
# }

compare(stat3, stat4)
compare(stat3, stat4, test = "chisq")
# \donttest{
compare(stat3, stat4, test = "boot")
# }

Run the code above in your browser using DataLab