loglike_compare {semlbci}R Documentation

Log Profile likelihood of a Parameter

Description

These functions compute the log profile likelihood of a parameter when it is fixed to a value or a range of values

Usage

loglike_compare(
  sem_out,
  semlbci_out = NULL,
  par_i,
  confidence = 0.95,
  n_points = 21,
  start = "default",
  try_k_more = 5,
  parallel = FALSE,
  ncpus = parallel::detectCores(logical = FALSE) - 1,
  use_pbapply = TRUE
)

loglike_range(
  sem_out,
  par_i,
  confidence = 0.95,
  n_points = 21,
  interval = NULL,
  verbose = FALSE,
  start = "default",
  try_k_more = 5,
  parallel = FALSE,
  ncpus = parallel::detectCores(logical = FALSE) - 1,
  use_pbapply = TRUE
)

loglike_point(
  theta0,
  sem_out,
  par_i,
  verbose = FALSE,
  start = "default",
  try_k_more = 5
)

loglike_quad_range(
  sem_out,
  par_i,
  confidence = 0.95,
  n_points = 21,
  interval = NULL,
  parallel = FALSE,
  ncpus = parallel::detectCores(logical = FALSE) - 1,
  use_pbapply = TRUE,
  try_k_more = 5,
  start = "default"
)

loglike_quad_point(theta0, sem_out, par_i)

Arguments

sem_out

The SEM output. Currently the outputs of lavaan::lavaan() or its wrappers, such as lavaan::sem() and lavaan::cfa() are supported.

semlbci_out

The output of semlbci(). If supplied, it will extract the likelihood-based confidence interval from the output. If not, it will call semlbci().

par_i

The row number of the parameter in the output of lavaan::parameterTable(). Can also be a lavaan::model.syntax specification for a parameter, e.g., "y ~ x" or ⁠ab := ⁠. It will be converted to the row number by syntax_to_i(). Refer to syntax_to_i() for details.

confidence

The level of confidence of the Wald-type confidence interval. If interval is NULL, this confidence is used to form the interval.

n_points

The number of points to be evaluated in the interval. Default is 21.

start

How the start values are set in lavaan::lavaan(). See lavaan::lavOptions() on this argument. Default is "default". If the plot is too irregular, try setting it to "simple".

try_k_more

How many more times to try finding the p-values, by randomizing the starting values. Default is 5. Try increasing this number if the plot is too irregular.

parallel

If TRUE, parallel processing will be used. A cluster will be created by parallel::makeCluster(), with the number of workers equal to ncpus. Parallel processing, though not enabled by default, is recommended because it can speed up the computation a lot.

ncpus

The number of workers if parallel is TRUE. Default is parallel::detectCores(logical = FALSE) - 1, the number of physical cores minus 1.

use_pbapply

If TRUE and pbapply::pbapply is installed, pbapply::pbapply will be used to display the progress in computing the log profile likelihood. Default is TRUE.

interval

A vector of numbers. If provided and has two elements, this will be used as the end points of the interval. If it has more than two elements, the elements will be used directly to form the values in the interval. Default is NULL.

verbose

Whether some diagnostic information will be printed. Default is FALSE.

theta0

The value at which the parameter is fixed to.

Details

It uses the methods presented in Pawitan (2013) to compute and visualize the log profile likelihood of a parameter in a structural equation model when this parameter is fixed to a value or a range of values. loglike_range() and loglike_point() compute the so-called "true" log profile likelihood, while loglike_quad_range() and loglike_quad_point() approximate the log profile likelihood by a quadratic function.

These functions are for creating illustrative examples and learning only, not for research use. Therefore, they are not as versatile as semlbci() in the types of models and parameters supported. They can be used for free parameters and user-defined parameters not involved in any constraints. Only a model fitted by maximum likelihood is supported.

They will not check whether the computation is appropriate for a model. It is the responsibility of the users to ensure that the computation is appropriate for the model and parameter.

Value

loglike_compare() calls loglike_range() and loglike_quad_range() and returns their results in a loglike_compare-class object, a list with these elements:

loglike_compare-class object has a plot method (plot.loglike_compare()) that can be used to plot the log profile likelihood.

loglike_point() returns a list with these elements:

loglike_quad_range() returns a data frame with these columns:

loglike_quad_point() returns a single number of the class lavaan.vector (because it is the output of lavaan::fitMeasures()). This number is the quadratic approximation of the log profile likelihood when the parameter is fixed to theta0.

loglike_range() returns a data frame with these columns:

Functions

References

Pawitan, Y. (2013). In all likelihood: Statistical modelling and inference using likelihood. Oxford University Press.

See Also

plot.loglike_compare()

Examples


## loglike_compare

library(lavaan)
data(simple_med)
dat <- simple_med
mod <-
"
m ~ a * x
y ~ b * m
ab := a * b
"
fit <- lavaan::sem(mod, simple_med, fixed.x = FALSE)

# 4 points are used just for illustration
# At least 21 points should be used for a smooth plot
# Remove try_k_more in real applications. It is set
# to zero such that this example does not take too long to run.
# use_pbapply can be removed or set to TRUE to show the progress.
ll_a <- loglike_compare(fit, par_i = "m ~ x", n_points = 4,
                        try_k_more = 0,
                        use_pbapply = FALSE)
plot(ll_a)

# See the vignette "loglike" for an example for the
# indirect effect.


## loglike_range

# Usually not to be used directly.
# Used by loglike_compare().
# 3 points are used just for illustration
ll_1 <- loglike_range(fit, par_i = "y ~ m", n_points = 2)
head(ll_1)


## loglike_point

# Usually not to be used directly.
# Used by loglike_compare().
llp_1 <- loglike_point(theta0 = 0.3, sem_out = fit, par_i = "y ~ m")
llp_1$loglike
llp_1$pvalue
llp_1$lrt



## loglike_quad_range

# Usually not to be used directly.
# Used by loglike_compare().
# 2 points are used just for illustration
lq_1 <- loglike_quad_range(fit, par_i = "y ~ m", n_points = 2)
head(lq_1)



## loglike_quad_point

# Usually not to be used directly.
# Used by loglike_compare().
lqp_1 <- loglike_quad_point(theta0 = 0.3, sem_out = fit, par_i = "y ~ m")
lqp_1



[Package semlbci version 0.11.2 Index]