difContinuous: Detection of DIF for continuous items via linear regression

View source: R/difContinuous.R

difContinuousR Documentation

Detection of DIF for continuous items via linear regression

Description

Detects differential item functioning (DIF) for items with continuous responses using nested linear regression models. The function provides optional item purification and p-value adjustment, and returns results in a "Continuous" object.

Usage

difContinuous(
    Data, group, focal.name,
    anchor = NULL,
    member.type = "group",
    match = "score",
    type = "both",
    criterion = "F",
    alpha = 0.05, all.cov = FALSE,
    purify = FALSE, nrIter = 10,
    p.adjust.method = NULL, puriadjType = "simple",
    save.output = FALSE, output = c("out", "default")
)

Arguments

Data

A numeric matrix or data frame of item responses with N rows (persons) and M columns (items). All columns must be numeric (continuous items).

group

The grouping/membership variable. It can be:

  • a vector of length N,

  • or a character string naming a column in Data.

When member.type = "group", group should define two groups (e.g., factor with two levels or 0/1 coding). When member.type = "cont", group is treated as continuous.

focal.name

Character string specifying the focal group (reference group is the other level) when member.type = "group". Ignored when member.type = "cont".

anchor

Integer vector (or NULL) specifying anchor items used to build the matching variable. Anchor items are not tested for DIF. If NULL, all non-flagged items are potential anchors, but all are tested for DIF. If anchor set is provided, purification is not performed.

member.type

Type of membership variable: "group" (categorical, two groups) or "cont" (continuous covariate).

match

Matching variable specification passed to the internal matching builder. Common options include "score" (total score on anchor items and the tested item), "zscore" (standardized "score"), or "restscore" (total anchor score without the tested item). Matching can also be a numeric a vector of length N or a numeric matrix/data.frame with the same dimensions as Data (N \times M; each column is item-specific matching criterion).

type

DIF effect tested:

"udif"

uniform DIF (group main effect).

"nudif"

non-uniform DIF (interaction effect).

"both"

joint test of uniform and non-uniform DIF.

criterion

Test used for nested-model comparison:

"F"

nested F test.

"Wald"

Wald chi-square test based on dropped terms.

alpha

Significance level for DIF detection and purification. Must be in (0, 1).

all.cov

Logical; if TRUE, returns variance–covariance matrices for parameters for both full and reduced models for each tested item.

purify

Logical; if TRUE, performs iterative item purification by updating anchor items across iterations. Purification is allowed only when match is "score" or "zscore", and anchor = NULL.

nrIter

Maximum number of purification iterations. Non-negative integer.

p.adjust.method

Optional character string specifying a p-value adjustment method as in p.adjust (e.g., "holm", "bonferroni", "BH"). If NULL, no adjustment is performed.

puriadjType

When purify = TRUE, specifies how p-value adjustment is handled:

"simple"

adjusts p-values within each purification step.

"combined"

adjusts p-values across the full purification process.

save.output

Logical; if TRUE, the printed result is saved to a text file.

output

Character vector controlling the output file when save.output = TRUE. The first element is the base file name (without extension). The second element is either "default" (current working directory) or a custom path.

Details

The function internally calls Continuous to fit, for each tested item, a full linear model (M1) and a reduced model (M0) depending on type. Test statistics are computed using criterion.

If purify = FALSE, DIF testing is performed once using the specified anchors. If purify = TRUE and allowed by the matching option, purification proceeds as follows:

  1. Run DIF once with all items as anchors.

  2. Flag items with adjusted p-values below alpha as DIF.

  3. Recompute matching scores using only non-DIF items as anchors.

  4. Repeat until convergence or nrIter is reached.

During purification, a difPur matrix is stored, indicating DIF status by step.

For items finally flagged as DIF, parameter estimates and standard errors returned in lmPar and lmSe correspond to the reduced model (M0), as in the behavior of other difR-style regression DIF functions.

Value

An object of class "Continuous" with components:

Stat

Numeric vector of test statistics per item (non-tested items are NA).

p.value

Numeric vector of raw p-values per item.

lmPar

M \times 4 matrix of parameter estimates shown for each item (M1 for non-DIF, M0 for DIF).

lmSe

M \times 4 matrix of standard errors corresponding to lmPar.

parM0, seM0

M \times 4 matrices of estimates and SEs for reduced models.

covM0, covM1

Lists of covariance matrices for M0 and M1 (only if all.cov = TRUE).

deltaR2

Numeric vector of \Delta R^2 per item.

alpha

Significance level used.

thr

Critical value of the chosen test at level alpha.

DIFitems

Either a character string "No DIF item detected" or an integer vector of flagged items.

member.type, match, type, criterion

Echoed specifications used in the analysis.

p.adjust.method

Adjustment method requested (possibly NULL).

adjusted.p

Adjusted p-values if p.adjust.method is not NULL; otherwise NULL.

purification

Logical indicating whether purification was performed.

nrPur

Number of purification iterations effectively run (if applicable).

puriadjType

Purification adjustment type (if applicable).

difPur

Matrix tracking DIF status by purification step (if applicable).

convergence

Logical indicating whether purification converged.

names

Item names (column names of Data).

anchor.names

Anchor specification as provided (or NULL under purification).

save.output, output

Echoed saving options.

Data, group

Final processed data matrix and grouping variable used.

Author(s)

Adela Hladka (nee Drabinova)
Institute of Computer Science of the Czech Academy of Sciences
hladka@cs.cas.cz
Sebastien Beland
Faculte des sciences de l'education
Universite de Montreal (Canada)
sebastien.beland@umontreal.ca

See Also

Continuous, difLogistic.

Examples

 set.seed(123)
  n <- 300                            # sample size
  group <- rep(c(0, 1), each = n / 2) # binary group membership variable
  theta <- rnorm(n)                   # latent trait

  # generating 5 continuous items with noise
  Data <- data.frame(
    Item1 = 0.5 * theta + rnorm(n),                        # No DIF
    Item2 = 0.4 * theta + 0.3 * group + rnorm(n),          # Uniform DIF
    Item3 = 0.6 * theta + 0.6 * theta * group + rnorm(n),  # Non-uniform DIF
    Item4 = 0.4 * theta + rnorm(n),                        # No DIF
    Item5 = 0.4 * theta - 0.4 * group + rnorm(n)           # Uniform DIF
  )

  # various matching criteria
  difContinuous(Data, group, focal.name = 1)
  difContinuous(Data, group, focal.name = 1, match = rowSums(Data))
  difContinuous(Data, group, focal.name = 1, match = as.data.frame(replicate(5, rowSums(Data))))
  difContinuous(Data, group, focal.name = 1, match = "zscore")
  difContinuous(Data, group, focal.name = 1, match = "restscore")
  difContinuous(Data, group, focal.name = 1, match = theta)

  # DIF detection with linear model, anchor items
  difContinuous(Data, group, focal.name = 1, anchor = c(1, 4))
  difContinuous(Data, group, focal.name = 1, anchor = paste0("Item", c(1, 4)))

  # DIF detection with linear model, different type of DIF
  difContinuous(Data, group, focal.name = 1, type = "both")
  difContinuous(Data, group, focal.name = 1, type = "udif")
  difContinuous(Data, group, focal.name = 1, type = "nudif")

  # DIF detection with linear model, different test criterion
  difContinuous(Data, group, focal.name = 1, criterion = "F")
  difContinuous(Data, group, focal.name = 1, criterion = "Wald")

  # DIF detection with linear model, item purification and multiple comparison corrections
  difContinuous(Data, group, focal.name = 1, purify = TRUE)
  difContinuous(Data, group, focal.name = 1, p.adjust.method = "BH")
  difContinuous(Data, group, focal.name = 1, purify = TRUE,
              p.adjust.method = "holm", puriadjType = "simple")

  difContinuous(Data, group, focal.name = 1, purify = TRUE,
              p.adjust.method = "holm", puriadjType = "combined")


difR documentation built on Nov. 29, 2025, 9:06 a.m.