Package {ghcclm}


Type: Package
Title: Generalized Hybrid Contrast Coding in Linear Models
Version: 0.1.0
Description: Implements generalized hybrid contrast coding methods for K-level categorical predictors in linear models as established by Obulezi (2026)[cite: 3]. The package automates design matrix construction mixing dummy indicators and composite group contrasts, checks rank constraints via singular value decomposition, computes closed-form OLS parameter mappings, and estimates robust heteroscedastic covariance matrices[cite: 3].
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.0.0)
Imports: stats
Suggests: testthat (≥ 3.0.0)
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-08-03 16:38:47 UTC; Dr. O. J. Obulezi
Author: Okechukwu J. Obulezi [aut, cre]
Maintainer: Okechukwu J. Obulezi <oj.obulezi@unizik.edu.ng>
Repository: CRAN
Date/Publication: 2026-08-08 13:00:06 UTC

Generate Generalized Hybrid Design Matrix

Description

Constructs a non-orthogonal, full-rank hybrid design matrix for qualitative factors with K >= 3 levels, combining dummy indicator columns with composite simple contrast vectors.

Usage

build_ghc_matrix(K, n, tol = 1e-12)

Arguments

K

Positive integer. Total number of factor levels (K >= 3).

n

Integer vector of length K giving sub-sample sizes per group.

tol

Numeric tolerance threshold for SVD singular values to verify rank.

Value

A numeric design matrix of size N x K (where N = sum(n)) with class attribute "ghc_matrix" and matrix attribute "C_operator".

Examples

XH <- build_ghc_matrix(K = 3, n = c(10, 10, 10))
attr(XH, "condition_number")

Fit Linear Models via Generalized Hybrid Contrast Coding

Description

Computes linear regression parameters using analytical hybrid contrast mappings. Provides theoretical variance-covariance estimators under both homoscedasticity and heteroscedasticity.

Usage

ghc_lm(formula, data, robust = FALSE)

Arguments

formula

Object of class "formula" representing model structure.

data

Data frame containing continuous response and categorical predictor.

robust

Logical. If TRUE, computes Huber-White sandwich variance.

Value

An S3 object of class "ghc_lm" containing fitted metrics.

Examples

set.seed(123)
dat <- data.frame(
  group = factor(rep(1:3, each = 10)),
  y = rnorm(30, mean = 50, sd = 5)
)
mod <- ghc_lm(y ~ group, data = dat)
summary(mod)