Package 'lavacreg'

Title: Latent Variable Count Regression Models
Description: Estimation of a multi-group count regression models (i.e., Poisson, negative binomial) with latent covariates. This packages provides two extensions compared to ordinary count regression models based on a generalized linear model: First, measurement models for the predictors can be specified allowing to account for measurement error. Second, the count regression can be simultaneously estimated in multiple groups with stochastic group weights. The marginal maximum likelihood estimation is described in Kiefer & Mayer (2020) <doi:10.1080/00273171.2020.1751027>.
Authors: Christoph Kiefer [cre, aut]
Maintainer: Christoph Kiefer <[email protected]>
License: GPL (>= 2)
Version: 0.2-2
Built: 2024-11-10 03:44:38 UTC
Source: https://github.com/chkiefer/lavacreg

Help Index


Fitting Count Regression Models with Latent Covariates

Description

This function is the main function of the package and can be used to estimate latent variable count regression models in one or multiple group(s).

Usage

countreg(
  forml,
  data,
  lv = NULL,
  group = NULL,
  family = "poisson",
  silent = FALSE,
  se = TRUE,
  creg_options = NULL
)

Arguments

forml

An object of class formula (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under Details.

data

A data frame containing all variables specified in forml and/or indicators of the latent variables specified in lv (if applicable).

lv

A named list, where names of elements represent the names of the latent variables and each element consists of a character vector containing variable names of indicators for the respective latent variable, e.g., list(eta1 = c("z1", "z2", "z3")).

group

A group variable. If specified, the regression model specified in forml is estimated as multi-group model (i.e., within each group).

family

A character indicating the family of the generalized linear model to be estimated. At the moment, "poisson" (for Poisson regression; default) or "nbinom" (for negative binomial regression) are available.

silent

Logical. Should informations about the estimation process be suppressed? (Defaults to FALSE)

se

Logical. Should standard errors be computed? Defaults to TRUE. (Can take a while for complex models)

creg_options

optional list of additional options for the estimation procedure

Value

An object of type lavacreg. Use summary(object) to print results containing parameter estimates and their standard errors.

Examples

fit <- countreg(forml = "dv ~ z11", data = example01, family = "poisson")
summary(fit)

fit <- countreg(
  forml = "dv ~ eta1 + z11 + z21",
  lv = list(eta1 = c("z41", "z42", "z43")),
  group = "treat",
  data = example01,
  family = "poisson"
)
summary(fit)

A first example dataset to illustrate the use of lavacreg

Description

A dataset containing 9 variables: a dependent variable dv, a group variable treat and 7 indicators for 3 latent covariates.

Usage

example01

Format

A data frame with 871 rows and 9 variables:

dv

Count of correctly-answered items (dependent variable)

treat

Treatment group variable, where 0 is control and 2 is treatment

z11

First indicator of internal LoC

z12

Second indicator of internal LoC

z21

First indicator of external LoC

z22

Second indicator of external LoC

z41

First indicator of depression

z42

Second indicator of depression

z43

Third indicator of depression


Check for count variable

Description

Checks if the variable is a count variable

Usage

is_count(x, tol = .Machine$double.eps^0.5)

Arguments

x

vector to be checked

tol

Tolerance

Value

Function returns logical value indicating whether x can be considered a count variable or not.


Summary of a lavacreg object

Description

Exports the parameter table with parameter estimates and standard errors for an estimated latent variable count regression model.

Usage

## S4 method for signature 'lavacreg'
summary(object)

Arguments

object

lavacreg object

Value

Function prints the parameter table of an estimated model, which includes the parameter estimates and standard errors.